[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> suggestions-nonauth.php (source)

   1  <?php
   2  /**
   3   * Suggestions API tests specifically for non-authenticated (anonymous) users.
   4   *
   5   * @group api
   6   * @group suggestions
   7   */
   8  class BP_Tests_Suggestions_Non_Authenticated extends BP_UnitTestCase {
   9      protected static $group_ids    = array();
  10      protected static $group_slugs  = array();
  11      protected static $user_ids     = array();
  12  
  13  	public static function wpSetUpBeforeClass( $factory ) {
  14          $users = array(
  15              // user_login, display_name
  16              array( 'aardvark',    'Bob Smith' ),
  17              array( 'alpaca red',  'William Quinn' ),
  18              array( 'cat',         'Lauren Curtis' ),
  19              array( 'caterpillar', 'Eldon Burrows' ),
  20              array( 'dog green',   'Reece Thornton' ),
  21              array( 'pig',         'Joshua Barton' ),
  22              array( 'rabbit blue', 'Amber Hooper' ),
  23              array( 'smith',       'Robert Bar' ),
  24              array( 'snake',       'Eleanor Moore' ),
  25              array( 'xylo',        'Silver McFadden' ),
  26              array( 'zoom',        'Lisa Smithy' ),
  27          );
  28  
  29          // Create some dummy users.
  30          foreach( $users as $user_index => $user ) {
  31              $new_user = $factory->user->create( array(
  32                  'display_name' => $user[1],
  33                  'user_login'   => $user[0],
  34                  'user_email'   => "test-$user_index@example.com",
  35              ) );
  36  
  37              self::$user_ids[ $user[0] ] = $new_user;
  38          }
  39  
  40          self::$group_slugs['hidden']  = 'the-maw';
  41          self::$group_slugs['public']  = 'the-great-journey';
  42          self::$group_slugs['private'] = 'tsavo-highway';
  43  
  44          // Create dummy groups.
  45          self::$group_ids['hidden'] = $factory->group->create( array(
  46              'creator_id' => self::$user_ids['xylo'],
  47              'slug'       => self::$group_slugs['hidden'],
  48              'status'     => 'hidden',
  49          ) );
  50          self::$group_ids['public'] = $factory->group->create( array(
  51              'creator_id' => self::$user_ids['xylo'],
  52              'slug'       => self::$group_slugs['public'],
  53              'status'     => 'public',
  54          ) );
  55          self::$group_ids['private'] = $factory->group->create( array(
  56              'creator_id' => self::$user_ids['xylo'],
  57              'slug'       => self::$group_slugs['private'],
  58              'status'     => 'private',
  59          ) );
  60  
  61          // Add dummy users to dummy hidden groups.
  62          groups_join_group( self::$group_ids['hidden'], self::$user_ids['pig'] );
  63          groups_join_group( self::$group_ids['hidden'], self::$user_ids['alpaca red'] );
  64  
  65          // Add dummy users to dummy public groups.
  66          groups_join_group( self::$group_ids['public'], self::$user_ids['aardvark'] );
  67          groups_join_group( self::$group_ids['public'], self::$user_ids['alpaca red'] );
  68          groups_join_group( self::$group_ids['public'], self::$user_ids['cat'] );
  69          groups_join_group( self::$group_ids['public'], self::$user_ids['smith'] );
  70  
  71          // Add dummy users to dummy private groups.
  72          groups_join_group( self::$group_ids['private'], self::$user_ids['cat'] );
  73          groups_join_group( self::$group_ids['private'], self::$user_ids['caterpillar'] );
  74  
  75          self::commit_transaction();
  76      }
  77  
  78  	public static function tearDownAfterClass() {
  79          foreach ( self::$group_ids as $group_id ) {
  80              groups_delete_group( $group_id );
  81          }
  82  
  83          foreach ( self::$user_ids as $user_id ) {
  84              if ( is_multisite() ) {
  85                  wpmu_delete_user( $user_id );
  86              } else {
  87                  wp_delete_user( $user_id );
  88              }
  89          }
  90  
  91          self::commit_transaction();
  92      }
  93  
  94      /**
  95       * Tests below this point are expected to fail.
  96       */
  97  
  98      public function test_suggestions_with_type_members_and_only_friends() {
  99          // only_friends requires authenticated requests
 100          $suggestions = bp_core_get_suggestions( array(
 101              'only_friends' => true,
 102              'type'         => 'members',
 103              'term'         => 'smith',
 104          ) );
 105  
 106          $this->assertTrue( is_wp_error( $suggestions ) );
 107      }
 108  
 109      public function test_suggestions_with_type_groupmembers_and_only_friends() {
 110          // only_friends requires authenticated requests
 111          $suggestions = bp_core_get_suggestions( array(
 112              'group_id'     => self::$group_ids['public'],
 113              'only_friends' => true,
 114              'type'         => 'members',
 115              'term'         => 'smith',
 116          ) );
 117  
 118          $this->assertTrue( is_wp_error( $suggestions ) );
 119      }
 120  
 121      public function test_suggestions_with_type_groupmembers_hidden() {
 122          $suggestions = bp_core_get_suggestions( array(
 123              'group_id' => self::$group_ids['hidden'],
 124              'type'     => 'members',
 125              'term'     => 'pig',
 126          ) );
 127  
 128          $this->assertTrue( is_wp_error( $suggestions ) );
 129      }
 130  
 131      public function test_suggestions_with_type_groupmembers_private() {
 132          $suggestions = bp_core_get_suggestions( array(
 133              'group_id' => self::$group_ids['private'],
 134              'type'     => 'members',
 135              'term'     => 'cat',
 136          ) );
 137  
 138          $this->assertTrue( is_wp_error( $suggestions ) );
 139      }
 140  
 141      public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() {
 142          $suggestions = bp_core_get_suggestions( array(
 143              'group_id' => self::$group_ids['public'],
 144              'type'     => 'members',
 145              'term'     => 'smith',
 146          ) );
 147          $this->assertFalse( is_wp_error( $suggestions ) );
 148          $this->assertEquals( 2, count( $suggestions ) );  // aardvark, smith.
 149  
 150          $suggestions = bp_core_get_suggestions( array(
 151              'group_id' => -self::$group_ids['public'],
 152              'type'     => 'members',
 153              'term'     => 'smith',
 154          ) );
 155          $this->assertFalse( is_wp_error( $suggestions ) );
 156          $this->assertEquals( 1, count( $suggestions ) );  // zoom
 157      }
 158  
 159      public function test_suggestions_with_type_groupmembers_private_and_exclude_group_from_results() {
 160          $suggestions = bp_core_get_suggestions( array(
 161              'group_id' => -self::$group_ids['private'],
 162              'type'     => 'members',
 163              'term'     => 'cat',
 164          ) );
 165          $this->assertTrue( is_wp_error( $suggestions ) );  // no access to group.
 166      }
 167  
 168      public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group_from_results() {
 169          $suggestions = bp_core_get_suggestions( array(
 170              'group_id' => self::$group_ids['hidden'],
 171              'type'     => 'members',
 172              'term'     => 'pig',
 173          ) );
 174          $this->assertTrue( is_wp_error( $suggestions ) );  // no access to group.
 175      }
 176  }


Generated: Sun Nov 17 01:01:36 2019 Cross-referenced by PHPXref 0.7.1