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


Generated: Wed Jul 17 01:01:40 2019 Cross-referenced by PHPXref 0.7.1