[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/groups/functions/ -> get-group.php (source)

   1  <?php
   2  
   3  /**
   4   * @group groups
   5   * @group functions
   6   */
   7  class BP_Tests_Get_Groups_Param extends BP_UnitTestCase {
   8  
   9  	public function setUp() {
  10          parent::setUp();
  11  
  12          if ( isset( $GLOBALS['groups_template'] ) ) {
  13              $this->groups_template = $GLOBALS['groups_template'];
  14          }
  15      }
  16  
  17  	public function tearDown() {
  18          if ( $this->groups_template ) {
  19              $GLOBALS['groups_template'] = $this->groups_template;
  20          }
  21  
  22          parent::tearDown();
  23      }
  24  
  25      /**
  26       * @group bp_get_group
  27       */
  28  	public function test_bp_get_group_with_no_group() {
  29          $this->assertFalse( bp_get_group() );
  30          $this->assertFalse( bp_get_group_by( 'id', 0 ) );
  31      }
  32  
  33      /**
  34       * @group bp_get_group
  35       */
  36  	public function test_bp_get_group_with_id() {
  37          $g = $this->factory->group->create();
  38  
  39          $this->assertSame( $g, bp_get_group( $g )->id );
  40          $this->assertSame( $g, bp_get_group_by( 'id', $g )->id );
  41          $this->assertSame( $g, bp_get_group_by( 'ID', $g )->id );
  42      }
  43  
  44      /**
  45       * @group bp_get_group
  46       */
  47  	public function test_bp_get_group_with_slug() {
  48          $slug = 'test-group';
  49          $g    = $this->factory->group->create( array( 'slug' => $slug ) );
  50          $g1   = bp_get_group( $slug );
  51  
  52          $this->assertSame( $g, $g1->id );
  53          $this->assertSame( $slug, $g1->slug );
  54  
  55          $g2 = bp_get_group_by( 'slug', $slug );
  56  
  57          $this->assertSame( $g, $g2->id );
  58          $this->assertSame( $slug, $g2->slug );
  59      }
  60  
  61      /**
  62       * @group bp_get_group
  63       */
  64  	public function test_bp_get_group_with_object() {
  65          $g = $this->factory->group->create_and_get();
  66  
  67          $this->assertSame( $g->id, bp_get_group( $g )->id );
  68      }
  69  
  70      /**
  71       * @group bp_get_group
  72       */
  73  	public function test_bp_get_group_from_groups_template() {
  74          $g = $this->factory->group->create( array( 'status' => 'private' ) );
  75  
  76          if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
  77              while ( bp_groups() ) {
  78                  bp_the_group();
  79                  $group = bp_get_group();
  80              }
  81          }
  82  
  83          $this->assertSame( $g, $group->id );
  84      }
  85  
  86      /**
  87       * @group bp_get_group
  88       */
  89  	public function test_bp_get_group_from_current_group() {
  90          $bp = buddypress();
  91          $g  = $this->factory->group->create_and_get( array( 'name' => 'foo' ) );
  92  
  93          // Set the current group.
  94          $bp->groups->current_group = $g;
  95  
  96          // Change the name to check the current group was used.
  97          $bp->groups->current_group->name = 'bar';
  98  
  99          // Override the name
 100          do_action( 'bp_groups_set_current_group' );
 101  
 102          $this->assertSame( 'bar', bp_get_group( $g->id )->name );
 103      }
 104  }


Generated: Thu Oct 28 01:00:59 2021 Cross-referenced by PHPXref 0.7.1