[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @group groups
   5   * @group template
   6   */
   7  class BP_Tests_Groups_Template_Status_Message extends BP_UnitTestCase {
   8      private $current_user;
   9      private $groups_template = null;
  10  
  11  	public function setUp() {
  12          parent::setUp();
  13          $this->current_user = bp_loggedin_user_id();
  14          $this->set_current_user( 0 );
  15  
  16          if ( isset( $GLOBALS['groups_template'] ) ) {
  17              $this->groups_template = $GLOBALS['groups_template'];
  18          }
  19      }
  20  
  21  	public function tearDown() {
  22          $this->set_current_user( $this->current_user );
  23          if ( $this->groups_template ) {
  24              $GLOBALS['groups_template'] = $this->groups_template;
  25          }
  26  
  27          parent::tearDown();
  28      }
  29  
  30      /**
  31       * @group BP6319
  32       */
  33      public function test_private_group_where_logged_in_user_has_not_requested_membership_but_has_been_invited() {
  34          $users = self::factory()->user->create_many( 2 );
  35          $g = self::factory()->group->create( array( 'status' => 'private' ) );
  36  
  37          $this->set_current_user( $users[0] );
  38  
  39          groups_invite_user( array(
  40              'user_id' => $users[0],
  41              'group_id' => $g,
  42              'inviter_id' => $users[1],
  43          ) );
  44  
  45          if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
  46              while ( bp_groups() ) {
  47                  bp_the_group();
  48                  $found = get_echo( 'bp_group_status_message' );
  49              }
  50          }
  51  
  52          $expected = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
  53          $this->assertSame( $expected, $found );
  54      }
  55  
  56      /**
  57       * @group BP6319
  58       */
  59      public function test_private_group_where_logged_in_user_has_not_requested_membership_and_has_not_been_invited() {
  60          $u = self::factory()->user->create();
  61          $g = self::factory()->group->create( array( 'status' => 'private' ) );
  62  
  63          $this->set_current_user( $u );
  64  
  65          if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
  66              while ( bp_groups() ) {
  67                  bp_the_group();
  68                  $found = get_echo( 'bp_group_status_message' );
  69              }
  70          }
  71  
  72          $expected = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
  73          $this->assertSame( $expected, $found );
  74      }
  75  
  76      /**
  77       * @group BP6319
  78       */
  79      public function test_private_group_visited_by_a_non_logged_in_user() {
  80          $g = self::factory()->group->create( array( 'status' => 'private' ) );
  81  
  82          if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
  83              while ( bp_groups() ) {
  84                  bp_the_group();
  85                  $found = get_echo( 'bp_group_status_message' );
  86              }
  87          }
  88  
  89          $expected = __( 'This is a private group. To join you must be a registered site member and request group membership.', 'buddypress' );
  90          $this->assertSame( $expected, $found );
  91      }
  92  
  93      /**
  94       * @group BP6319
  95       */
  96      public function test_private_group_where_loggedin_user_has_requested_membership() {
  97          $u = self::factory()->user->create();
  98          $g = self::factory()->group->create( array( 'status' => 'private' ) );
  99  
 100          $this->set_current_user( $u );
 101  
 102          groups_send_membership_request( array(
 103              'user_id'  => $u,
 104              'group_id' => $g
 105          ) );
 106  
 107          if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
 108              while ( bp_groups() ) {
 109                  bp_the_group();
 110                  $found = get_echo( 'bp_group_status_message' );
 111              }
 112          }
 113  
 114          $expected = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
 115          $this->assertSame( $expected, $found );
 116      }
 117  
 118      /**
 119       * @group BP6319
 120       */
 121  	public function test_hidden_group() {
 122          $u = self::factory()->user->create();
 123          $g = self::factory()->group->create( array( 'status' => 'hidden' ) );
 124  
 125          $this->set_current_user( $u );
 126  
 127          $group = groups_get_group( $g );
 128  
 129          $found = get_echo( 'bp_group_status_message', array( $group ) );
 130  
 131          $expected = __( 'This is a hidden group and only invited members can join.', 'buddypress' );
 132          $this->assertSame( $expected, $found );
 133      }
 134  
 135      /**
 136       * @group BP6319
 137       */
 138  	public function test_group_parameter_should_be_obeyed() {
 139          $u = self::factory()->user->create();
 140          $groups = self::factory()->group->create_many( 2, array( 'status' => 'private' ) );
 141  
 142          $this->set_current_user( $u );
 143  
 144          // Fake the current group.
 145          $GLOBALS['groups_template'] = new stdClass;
 146          $GLOBALS['groups_template']->group = groups_get_group( $groups[0] );
 147  
 148          groups_send_membership_request( array(
 149              'user_id' => $u,
 150              'group_id' => $groups[1]
 151          ) );
 152  
 153          $group1 = groups_get_group( array(
 154              'group_id' => $groups[1],
 155              'populate_extras' => true,
 156          ) );
 157  
 158          $found = get_echo( 'bp_group_status_message', array( $group1 ) );
 159  
 160          $expected = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
 161          $this->assertSame( $expected, $found );
 162      }
 163  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1