Changeset 9142 for trunk/tests/phpunit/testcases/apis/suggestions.php
- Timestamp:
- 11/14/2014 02:01:30 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/apis/suggestions.php
r8958 r9142 7 7 */ 8 8 class BP_Tests_Suggestions_Authenticated extends BP_UnitTestCase { 9 protected $current_user = null; 10 protected $group_ids = array(); 11 protected $group_slugs = array(); 12 protected $old_user_id = 0; 13 protected $user_ids = array(); 14 15 public function setUp() { 16 parent::setUp(); 17 18 $this->old_user_id = get_current_user_id(); 19 $this->current_user = $this->create_user( array( 9 protected static $current_user = null; 10 protected static $group_ids = array(); 11 protected static $group_slugs = array(); 12 protected static $old_user_id = 0; 13 protected static $user_ids = array(); 14 15 public static function setUpBeforeClass() { 16 parent::setUpBeforeClass(); 17 18 $factory = new BP_UnitTest_Factory(); 19 20 self::$old_user_id = get_current_user_id(); 21 self::$current_user = $factory->user->create( array( 20 22 'display_name' => 'Katie Parker', 21 23 'user_login' => 'katie', 22 ) ); 23 24 $this->set_current_user( $this->current_user ); 24 'user_email' => 'test-katie@example.com', 25 ) ); 25 26 26 27 $users = array( … … 40 41 41 42 // Create some dummy users. 42 foreach ( $users as $user ) {43 $ this->user_ids[ $user[0] ] = $this->create_user( array(43 foreach ( $users as $user_index => $user ) { 44 $new_user = $factory->user->create( array( 44 45 'display_name' => $user[1], 45 46 'user_login' => $user[0], 47 'user_email' => "test-$user_index@example.com", 46 48 ) ); 49 50 self::$user_ids[ $user[0] ] = $new_user; 47 51 } 48 52 49 // Create some dummy friendships. 50 friends_add_friend( $this->current_user, $this->user_ids['aardvark'], true ); 51 friends_add_friend( $this->current_user, $this->user_ids['cat'], true ); 52 friends_add_friend( $this->current_user, $this->user_ids['caterpillar'], true ); 53 friends_add_friend( $this->current_user, $this->user_ids['pig'], true ); 54 55 $this->group_slugs['hidden'] = 'the-maw'; 56 $this->group_slugs['public'] = 'the-great-journey'; 57 $this->group_slugs['private'] = 'tsavo-highway'; 53 // Create some dummy friendships (but not the corresponding activity items). 54 remove_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 ); 55 friends_add_friend( self::$current_user, self::$user_ids['aardvark'], true ); 56 friends_add_friend( self::$current_user, self::$user_ids['cat'], true ); 57 friends_add_friend( self::$current_user, self::$user_ids['caterpillar'], true ); 58 friends_add_friend( self::$current_user, self::$user_ids['pig'], true ); 59 add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 ); 60 61 self::$group_slugs['hidden'] = 'the-maw'; 62 self::$group_slugs['public'] = 'the-great-journey'; 63 self::$group_slugs['private'] = 'tsavo-highway'; 58 64 59 65 // Create dummy groups. 60 $this->group_ids['hidden'] = $this->factory->group->create( array(61 'creator_id' => $this->user_ids['xylo'],62 'slug' => $this->group_slugs['hidden'],66 self::$group_ids['hidden'] = $factory->group->create( array( 67 'creator_id' => self::$user_ids['xylo'], 68 'slug' => self::$group_slugs['hidden'], 63 69 'status' => 'hidden', 64 70 ) ); 65 $this->group_ids['public'] = $this->factory->group->create( array(66 'creator_id' => $this->user_ids['xylo'],67 'slug' => $this->group_slugs['public'],71 self::$group_ids['public'] = $factory->group->create( array( 72 'creator_id' => self::$user_ids['xylo'], 73 'slug' => self::$group_slugs['public'], 68 74 'status' => 'public', 69 75 ) ); 70 $this->group_ids['private'] = $this->factory->group->create( array(71 'creator_id' => $this->user_ids['xylo'],72 'slug' => $this->group_slugs['private'],76 self::$group_ids['private'] = $factory->group->create( array( 77 'creator_id' => self::$user_ids['xylo'], 78 'slug' => self::$group_slugs['private'], 73 79 'status' => 'private', 74 80 ) ); 75 81 76 82 // Add dummy users to dummy hidden groups. 77 groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] );78 groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] );83 groups_join_group( self::$group_ids['hidden'], self::$user_ids['pig'] ); 84 groups_join_group( self::$group_ids['hidden'], self::$user_ids['alpaca red'] ); 79 85 80 86 // Add dummy users to dummy public groups. 81 groups_join_group( $this->group_ids['public'], $this->current_user );82 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] );83 groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] );84 groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] );85 groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] );87 groups_join_group( self::$group_ids['public'], self::$current_user ); 88 groups_join_group( self::$group_ids['public'], self::$user_ids['aardvark'] ); 89 groups_join_group( self::$group_ids['public'], self::$user_ids['alpaca red'] ); 90 groups_join_group( self::$group_ids['public'], self::$user_ids['cat'] ); 91 groups_join_group( self::$group_ids['public'], self::$user_ids['smith'] ); 86 92 87 93 // Add dummy users to dummy private groups. 88 groups_join_group( $this->group_ids['private'], $this->user_ids['cat'] ); 89 groups_join_group( $this->group_ids['private'], $this->user_ids['caterpillar'] ); 94 groups_join_group( self::$group_ids['private'], self::$user_ids['cat'] ); 95 groups_join_group( self::$group_ids['private'], self::$user_ids['caterpillar'] ); 96 97 self::commit_transaction(); 98 } 99 100 public static function tearDownAfterClass() { 101 foreach ( self::$group_ids as $group_id ) { 102 groups_delete_group( $group_id ); 103 } 104 105 foreach ( array_merge( self::$user_ids, array( self::$current_user ) ) as $user_id ) { 106 if ( is_multisite() ) { 107 wpmu_delete_user( $user_id ); 108 } else { 109 wp_delete_user( $user_id ); 110 } 111 } 112 113 self::commit_transaction(); 114 } 115 116 public function setUp() { 117 parent::setUp(); 118 $this->set_current_user( self::$current_user ); 90 119 } 91 120 92 121 public function tearDown() { 93 122 parent::tearDown(); 94 $this->set_current_user( $this->old_user_id ); 95 } 96 123 $this->set_current_user( self::$old_user_id ); 124 } 97 125 98 126 public function test_suggestions_with_type_members() { … … 169 197 public function test_suggestions_with_type_groupmembers_public() { 170 198 $suggestions = bp_core_get_suggestions( array( 171 'group_id' => $this->group_ids['public'],199 'group_id' => self::$group_ids['public'], 172 200 'type' => 'members', 173 201 'term' => 'smith', … … 181 209 $suggestions = bp_core_get_suggestions( array( 182 210 'limit' => 1, 183 'group_id' => $this->group_ids['public'],211 'group_id' => self::$group_ids['public'], 184 212 'type' => 'members', 185 213 'term' => 'smith', … … 192 220 public function test_suggestions_with_type_groupmembers_public_and_only_friends() { 193 221 $suggestions = bp_core_get_suggestions( array( 194 'group_id' => $this->group_ids['public'],222 'group_id' => self::$group_ids['public'], 195 223 'only_friends' => true, 196 224 'type' => 'members', … … 204 232 public function test_suggestions_with_type_groupmembers_public_and_term_as_displayname() { 205 233 $suggestions = bp_core_get_suggestions( array( 206 'group_id' => $this->group_ids['public'],234 'group_id' => self::$group_ids['public'], 207 235 'type' => 'members', 208 236 'term' => 'aardvark', … … 215 243 public function test_suggestions_with_type_groupmembers_public_and_term_as_usernicename() { 216 244 $suggestions = bp_core_get_suggestions( array( 217 'group_id' => $this->group_ids['public'],245 'group_id' => self::$group_ids['public'], 218 246 'type' => 'members', 219 247 'term' => 'robert', … … 226 254 public function test_suggestions_with_type_groupmembers_public_as_id() { 227 255 $suggestions = bp_core_get_suggestions( array( 228 'group_id' => $this->group_ids['public'],256 'group_id' => self::$group_ids['public'], 229 257 'type' => 'members', 230 258 'term' => 'smith', … … 238 266 // current_user isn't a member of the hidden group 239 267 $suggestions = bp_core_get_suggestions( array( 240 'group_id' => $this->group_ids['hidden'],268 'group_id' => self::$group_ids['hidden'], 241 269 'type' => 'members', 242 270 'term' => 'pig', … … 245 273 246 274 // "alpaca red" is in the hidden group 247 $this->set_current_user( $this->user_ids['alpaca red'] );248 $suggestions = bp_core_get_suggestions( array( 249 'group_id' => $this->group_ids['hidden'],275 $this->set_current_user( self::$user_ids['alpaca red'] ); 276 $suggestions = bp_core_get_suggestions( array( 277 'group_id' => self::$group_ids['hidden'], 250 278 'type' => 'members', 251 279 'term' => 'pig', … … 258 286 // current_user isn't a member of the private group. 259 287 $suggestions = bp_core_get_suggestions( array( 260 'group_id' => $this->group_ids['private'],288 'group_id' => self::$group_ids['private'], 261 289 'type' => 'members', 262 290 'term' => 'cat', … … 265 293 266 294 // "caterpillar" is in the private group 267 $this->set_current_user( $this->user_ids['caterpillar'] );268 $suggestions = bp_core_get_suggestions( array( 269 'group_id' => $this->group_ids['private'],295 $this->set_current_user( self::$user_ids['caterpillar'] ); 296 $suggestions = bp_core_get_suggestions( array( 297 'group_id' => self::$group_ids['private'], 270 298 'type' => 'members', 271 299 'term' => 'cat', … … 278 306 public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() { 279 307 $suggestions = bp_core_get_suggestions( array( 280 'group_id' => $this->group_ids['public'],308 'group_id' => self::$group_ids['public'], 281 309 'type' => 'members', 282 310 'term' => 'smith', … … 286 314 287 315 $suggestions = bp_core_get_suggestions( array( 288 'group_id' => - $this->group_ids['public'],316 'group_id' => -self::$group_ids['public'], 289 317 'type' => 'members', 290 318 'term' => 'smith', … … 297 325 // current_user isn't a member of the private group. 298 326 $suggestions = bp_core_get_suggestions( array( 299 'group_id' => - $this->group_ids['private'],327 'group_id' => -self::$group_ids['private'], 300 328 'type' => 'members', 301 329 'term' => 'cat', … … 304 332 305 333 306 $this->set_current_user( $this->user_ids['caterpillar'] );334 $this->set_current_user( self::$user_ids['caterpillar'] ); 307 335 308 336 // "cat" is in the private group, so won't show up here. 309 337 $suggestions = bp_core_get_suggestions( array( 310 'group_id' => - $this->group_ids['private'],338 'group_id' => -self::$group_ids['private'], 311 339 'type' => 'members', 312 340 'term' => 'cat', … … 317 345 // "zoo" is not the private group, so will show up here. 318 346 $suggestions = bp_core_get_suggestions( array( 319 'group_id' => - $this->group_ids['private'],347 'group_id' => -self::$group_ids['private'], 320 348 'type' => 'members', 321 349 'term' => 'zoo', … … 328 356 // current_user isn't a member of the hidden group. 329 357 $suggestions = bp_core_get_suggestions( array( 330 'group_id' => $this->group_ids['hidden'],358 'group_id' => self::$group_ids['hidden'], 331 359 'type' => 'members', 332 360 'term' => 'pig', … … 335 363 336 364 337 $this->set_current_user( $this->user_ids['alpaca red'] );365 $this->set_current_user( self::$user_ids['alpaca red'] ); 338 366 339 367 // "alpaca red" is in the hidden group, so won't show up here. 340 368 $suggestions = bp_core_get_suggestions( array( 341 'group_id' => - $this->group_ids['hidden'],369 'group_id' => -self::$group_ids['hidden'], 342 370 'type' => 'members', 343 371 'term' => 'alpaca red', … … 348 376 // "zoo" is not the hidden group, so will show up here. 349 377 $suggestions = bp_core_get_suggestions( array( 350 'group_id' => - $this->group_ids['hidden'],378 'group_id' => -self::$group_ids['hidden'], 351 379 'type' => 'members', 352 380 'term' => 'zoo',
Note: See TracChangeset
for help on using the changeset viewer.