1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-24 21:16:56 +08:00
buddypress/tests/phpunit/testcases/routing/groups.php
Mathieu Viet 89a6666dc6 Fully enjoy Yoast’s PHPUnit polyfills
Using these polyfills let us use PHPUnit v9.x for our tests and add PHP 8.1 to our testing matrix. Some additional edits to our PHP unit tests suite were needed:

- Stop using PHPunit deprecated functions.
- Rename some `BP_UnitTestCase` methods to use Yoast's polyfills.
- Edit the PHP Unit test GH action and also run this action on pull requests.
- Update some composer dependencies, remove the one about `phpunit/phpunit:^7.5` and add a new composer script to use PHPUnit v9.x. 

Props renatonascalves, rafiahmedd

Closes https://github.com/buddypress/buddypress/pull/13
Fixes #8649


git-svn-id: https://buddypress.svn.wordpress.org/trunk@13314 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2022-08-13 08:58:51 +00:00

127 lines
3.7 KiB
PHP

<?php
/**
* @group groups
* @group routing
*/
class BP_Tests_Routing_Groups extends BP_UnitTestCase {
protected $old_current_user = 0;
public function set_up() {
parent::set_up();
buddypress()->members->types = array();
$this->old_current_user = get_current_user_id();
$this->set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
}
public function tear_down() {
parent::tear_down();
$this->set_current_user( $this->old_current_user );
}
function test_member_groups() {
$this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() );
$this->assertTrue( bp_is_user_groups() );
}
function test_member_groups_invitations() {
$this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() . '/invites' );
$this->assertTrue( bp_is_user_groups() && bp_is_current_action( 'invites' ) );
}
/**
* @group group_types
*/
public function test_group_directory_with_type() {
bp_groups_register_group_type( 'foo' );
$this->go_to( bp_get_groups_directory_permalink() . 'type/foo/' );
$this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foo', 0 ) );
}
/**
* @group group_types
*/
public function test_group_directory_with_type_that_has_custom_directory_slug() {
bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) );
$this->go_to( bp_get_groups_directory_permalink() . 'type/foos/' );
$this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foos', 0 ) );
}
/**
* @group group_types
*/
public function test_group_directory_should_404_for_group_types_that_have_no_directory() {
bp_register_member_type( 'foo', array( 'has_directory' => false ) );
$this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
$this->assertTrue( is_404() );
}
/**
* @group group_types
*/
public function test_group_directory_should_404_for_invalid_group_types() {
$this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
$this->assertTrue( is_404() );
}
/**
* @group group_previous_slug
*/
public function test_group_previous_slug_current_slug_should_resolve() {
$g1 = self::factory()->group->create( array(
'slug' => 'george',
) );
groups_edit_base_group_details( array(
'group_id' => $g1,
'slug' => 'ralph',
) );
$this->go_to( bp_get_groups_directory_permalink() . 'ralph' );
$this->assertEquals( $g1, bp_get_current_group_id() );
}
/**
* @group group_previous_slug
*/
public function test_group_previous_slug_should_resolve() {
$g1 = self::factory()->group->create( array(
'slug' => 'george',
) );
groups_edit_base_group_details( array(
'group_id' => $g1,
'slug' => 'sam!',
'notify_members' => false,
) );
$this->go_to( bp_get_groups_directory_permalink() . 'george' );
$this->assertEquals( $g1, bp_get_current_group_id() );
}
/**
* @group group_previous_slug
*/
public function test_group_previous_slug_most_recent_takes_precedence() {
$g1 = self::factory()->group->create( array(
'slug' => 'george',
) );
groups_edit_base_group_details( array(
'group_id' => $g1,
'slug' => 'ralph',
'notify_members' => false,
) );
$g2 = self::factory()->group->create( array(
'slug' => 'george',
) );
groups_edit_base_group_details( array(
'group_id' => $g2,
'slug' => 'sam',
'notify_members' => false,
) );
$this->go_to( bp_get_groups_directory_permalink() . 'george' );
$this->assertEquals( $g2, bp_get_current_group_id() );
}
}