[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/groups/template/ -> group-is-visible.php (source)

   1  <?php
   2  
   3  /**
   4   * @group groups
   5   * @group template
   6   */
   7  class BP_Tests_Groups_Template_Is_Visible 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  	public function test_bp_group_is_visible_no_member() {
  26          $g = $this->factory->group->create( array( 'status' => 'private' ) );
  27  
  28          $this->assertFalse( bp_group_is_visible( $g ) );
  29      }
  30  
  31  	public function test_bp_group_is_visible_regular_member() {
  32          $g = $this->factory->group->create( array( 'status' => 'private' ) );
  33          $u = $this->factory->user->create();
  34  
  35          $this->set_current_user( $u );
  36  
  37          $this->assertFalse( bp_group_is_visible( $g ) );
  38      }
  39  
  40      public function test_bp_group_is_visible_regular_member_from_group() {
  41          $g = $this->factory->group->create( array( 'status' => 'private' ) );
  42          $u = $this->factory->user->create();
  43  
  44          $this->set_current_user( $u );
  45  
  46          $this->add_user_to_group( $u, $g );
  47  
  48          $this->assertTrue( bp_group_is_visible( $g ) );
  49      }
  50  
  51  	public function test_bp_group_is_visible_invalid_group() {
  52          $u = $this->factory->user->create();
  53  
  54          // Empty the current group.
  55          $GLOBALS['groups_template'] = new stdClass;
  56          $GLOBALS['groups_template']->group = null;
  57  
  58          $this->set_current_user( $u );
  59  
  60          $this->assertFalse( bp_group_is_visible() );
  61      }
  62  
  63  	public function test_bp_group_is_visible_admin() {
  64          $g = $this->factory->group->create( array( 'status' => 'private' ) );
  65          $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
  66  
  67          $this->set_current_user( $u );
  68  
  69          $this->assertTrue( bp_group_is_visible( $g ) );
  70      }
  71  
  72  	public function test_bp_group_is_visible_using_user_id() {
  73          $g = $this->factory->group->create( array( 'status' => 'hidden' ) );
  74          $u = $this->factory->user->create();
  75  
  76          $this->add_user_to_group( $u, $g );
  77  
  78          $this->assertTrue( bp_group_is_visible( $g, $u ) );
  79      }
  80  
  81  	public function test_bp_group_is_not_visible_using_user_id() {
  82          $g = $this->factory->group->create( array( 'status' => 'private' ) );
  83          $u = $this->factory->user->create();
  84  
  85          $this->assertFalse( bp_group_is_visible( $g, $u ) );
  86      }
  87  
  88  	public function test_bp_group_is_visible_with_group_slug() {
  89          $slug = 'test-group';
  90  
  91          $this->factory->group->create(
  92              array(
  93                  'status' => 'private',
  94                  'slug'   => $slug,
  95              )
  96          );
  97  
  98          $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
  99  
 100          $this->set_current_user( $u );
 101  
 102          $this->assertTrue( bp_group_is_visible( $slug ) );
 103      }
 104  
 105  	public function test_bp_group_is_visible_from_current_group() {
 106          $g = $this->factory->group->create( array( 'status' => 'private' ) );
 107          $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
 108  
 109          // Fake the current group.
 110          $GLOBALS['groups_template'] = new stdClass;
 111          $GLOBALS['groups_template']->group = groups_get_group( $g );
 112  
 113          $this->set_current_user( $u );
 114  
 115          $this->assertTrue( bp_group_is_visible() );
 116      }
 117  }


Generated: Sat Apr 20 01:00:58 2024 Cross-referenced by PHPXref 0.7.1