[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/routing/ -> groups.php (source)

   1  <?php
   2  /**
   3   * @group groups
   4   * @group routing
   5   */
   6  class BP_Tests_Routing_Groups extends BP_UnitTestCase {
   7      protected $old_current_user = 0;
   8  
   9  	public function setUp() {
  10          parent::setUp();
  11  
  12          buddypress()->members->types = array();
  13          $this->old_current_user = get_current_user_id();
  14          $this->set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
  15      }
  16  
  17  	public function tearDown() {
  18          parent::tearDown();
  19          $this->set_current_user( $this->old_current_user );
  20      }
  21  
  22  	function test_member_groups() {
  23          $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() );
  24          $this->assertTrue( bp_is_user_groups() );
  25      }
  26  
  27  	function test_member_groups_invitations() {
  28          $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() . '/invites' );
  29          $this->assertTrue( bp_is_user_groups() && bp_is_current_action( 'invites' ) );
  30      }
  31  
  32      /**
  33       * @group group_types
  34       */
  35  	public function test_group_directory_with_type() {
  36          bp_groups_register_group_type( 'foo' );
  37          $this->go_to( bp_get_groups_directory_permalink() . 'type/foo/' );
  38          $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 ) );
  39      }
  40  
  41      /**
  42       * @group group_types
  43       */
  44      public function test_group_directory_with_type_that_has_custom_directory_slug() {
  45          bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) );
  46          $this->go_to( bp_get_groups_directory_permalink() . 'type/foos/' );
  47          $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 ) );
  48      }
  49  
  50      /**
  51       * @group group_types
  52       */
  53      public function test_group_directory_should_404_for_group_types_that_have_no_directory() {
  54          bp_register_member_type( 'foo', array( 'has_directory' => false ) );
  55          $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
  56          $this->assertTrue( is_404() );
  57      }
  58  
  59      /**
  60       * @group group_types
  61       */
  62      public function test_group_directory_should_404_for_invalid_group_types() {
  63          $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
  64          $this->assertTrue( is_404() );
  65      }
  66  
  67      /**
  68       * @group group_previous_slug
  69       */
  70      public function test_group_previous_slug_current_slug_should_resolve() {
  71          $g1 = self::factory()->group->create( array(
  72              'slug' => 'george',
  73          ) );
  74          groups_edit_base_group_details( array(
  75              'group_id' => $g1,
  76              'slug'     => 'ralph',
  77          ) );
  78  
  79          $this->go_to( bp_get_groups_directory_permalink() . 'ralph' );
  80  
  81          $this->assertEquals( $g1, bp_get_current_group_id() );
  82      }
  83  
  84      /**
  85       * @group group_previous_slug
  86       */
  87  	public function test_group_previous_slug_should_resolve() {
  88          $g1 = self::factory()->group->create( array(
  89              'slug' => 'george',
  90          ) );
  91  
  92          groups_edit_base_group_details( array(
  93              'group_id'       => $g1,
  94              'slug'           => 'sam!',
  95              'notify_members' => false,
  96          ) );
  97          $this->go_to( bp_get_groups_directory_permalink() . 'george' );
  98  
  99          $this->assertEquals( $g1, bp_get_current_group_id() );
 100      }
 101  
 102      /**
 103       * @group group_previous_slug
 104       */
 105      public function test_group_previous_slug_most_recent_takes_precedence() {
 106          $g1 = self::factory()->group->create( array(
 107              'slug' => 'george',
 108          ) );
 109          groups_edit_base_group_details( array(
 110              'group_id'       => $g1,
 111              'slug'           => 'ralph',
 112              'notify_members' => false,
 113          ) );
 114          $g2 = self::factory()->group->create( array(
 115              'slug' => 'george',
 116          ) );
 117          groups_edit_base_group_details( array(
 118              'group_id'       => $g2,
 119              'slug'           => 'sam',
 120              'notify_members' => false,
 121          ) );
 122  
 123          $this->go_to( bp_get_groups_directory_permalink() . 'george' );
 124          $this->assertEquals( $g2, bp_get_current_group_id() );
 125      }
 126  
 127  }


Generated: Fri Jul 19 01:01:43 2019 Cross-referenced by PHPXref 0.7.1