Changeset 9142
- Timestamp:
- 11/14/2014 02:01:30 PM (10 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r9141 r9142 431 431 return $args; 432 432 } 433 434 /** 435 * Commit a MySQL transaction. 436 */ 437 public static function commit_transaction() { 438 global $wpdb; 439 $wpdb->query( 'COMMIT;' ); 440 } 433 441 } -
trunk/tests/phpunit/testcases/apis/suggestions-nonauth.php
r8958 r9142 7 7 */ 8 8 class BP_Tests_Suggestions_Non_Authenticated extends BP_UnitTestCase { 9 protected $group_ids = array();10 protected $group_slugs = array();11 protected $user_ids = array();9 protected static $group_ids = array(); 10 protected static $group_slugs = array(); 11 protected static $user_ids = array(); 12 12 13 public function setUp() {14 parent::setUp ();13 public static function setUpBeforeClass() { 14 parent::setUpBeforeClass(); 15 15 16 16 $users = array( … … 29 29 ); 30 30 31 $factory = new BP_UnitTest_Factory(); 32 31 33 // Create some dummy users. 32 foreach( $users as $user ) {33 $ this->user_ids[ $user[0] ] = $this->create_user( array(34 foreach( $users as $user_index => $user ) { 35 $new_user = $factory->user->create( array( 34 36 'display_name' => $user[1], 35 37 'user_login' => $user[0], 38 'user_email' => "test-$user_index@example.com", 36 39 ) ); 40 41 self::$user_ids[ $user[0] ] = $new_user; 37 42 } 38 43 39 $this->group_slugs['hidden'] = 'the-maw';40 $this->group_slugs['public'] = 'the-great-journey';41 $this->group_slugs['private'] = 'tsavo-highway';44 self::$group_slugs['hidden'] = 'the-maw'; 45 self::$group_slugs['public'] = 'the-great-journey'; 46 self::$group_slugs['private'] = 'tsavo-highway'; 42 47 43 48 // Create dummy groups. 44 $this->group_ids['hidden'] = $this->factory->group->create( array(45 'creator_id' => $this->user_ids['xylo'],46 'slug' => $this->group_slugs['hidden'],49 self::$group_ids['hidden'] = $factory->group->create( array( 50 'creator_id' => self::$user_ids['xylo'], 51 'slug' => self::$group_slugs['hidden'], 47 52 'status' => 'hidden', 48 53 ) ); 49 $this->group_ids['public'] = $this->factory->group->create( array(50 'creator_id' => $this->user_ids['xylo'],51 'slug' => $this->group_slugs['public'],54 self::$group_ids['public'] = $factory->group->create( array( 55 'creator_id' => self::$user_ids['xylo'], 56 'slug' => self::$group_slugs['public'], 52 57 'status' => 'public', 53 58 ) ); 54 $this->group_ids['private'] = $this->factory->group->create( array(55 'creator_id' => $this->user_ids['xylo'],56 'slug' => $this->group_slugs['private'],59 self::$group_ids['private'] = $factory->group->create( array( 60 'creator_id' => self::$user_ids['xylo'], 61 'slug' => self::$group_slugs['private'], 57 62 'status' => 'private', 58 63 ) ); 59 64 60 65 // Add dummy users to dummy hidden groups. 61 groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] );62 groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] );66 groups_join_group( self::$group_ids['hidden'], self::$user_ids['pig'] ); 67 groups_join_group( self::$group_ids['hidden'], self::$user_ids['alpaca red'] ); 63 68 64 69 // Add dummy users to dummy public groups. 65 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] );66 groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] );67 groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] );68 groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] );70 groups_join_group( self::$group_ids['public'], self::$user_ids['aardvark'] ); 71 groups_join_group( self::$group_ids['public'], self::$user_ids['alpaca red'] ); 72 groups_join_group( self::$group_ids['public'], self::$user_ids['cat'] ); 73 groups_join_group( self::$group_ids['public'], self::$user_ids['smith'] ); 69 74 70 75 // Add dummy users to dummy private groups. 71 groups_join_group( $this->group_ids['private'], $this->user_ids['cat'] ); 72 groups_join_group( $this->group_ids['private'], $this->user_ids['caterpillar'] ); 76 groups_join_group( self::$group_ids['private'], self::$user_ids['cat'] ); 77 groups_join_group( self::$group_ids['private'], self::$user_ids['caterpillar'] ); 78 79 self::commit_transaction(); 73 80 } 74 81 82 public static function tearDownAfterClass() { 83 foreach ( self::$group_ids as $group_id ) { 84 groups_delete_group( $group_id ); 85 } 86 87 foreach ( self::$user_ids as $user_id ) { 88 if ( is_multisite() ) { 89 wpmu_delete_user( $user_id ); 90 } else { 91 wp_delete_user( $user_id ); 92 } 93 } 94 95 self::commit_transaction(); 96 } 75 97 76 98 /** … … 92 114 // only_friends requires authenticated requests 93 115 $suggestions = bp_core_get_suggestions( array( 94 'group_id' => $this->group_ids['public'],116 'group_id' => self::$group_ids['public'], 95 117 'only_friends' => true, 96 118 'type' => 'members', … … 103 125 public function test_suggestions_with_type_groupmembers_hidden() { 104 126 $suggestions = bp_core_get_suggestions( array( 105 'group_id' => $this->group_ids['hidden'],127 'group_id' => self::$group_ids['hidden'], 106 128 'type' => 'members', 107 129 'term' => 'pig', … … 113 135 public function test_suggestions_with_type_groupmembers_private() { 114 136 $suggestions = bp_core_get_suggestions( array( 115 'group_id' => $this->group_ids['private'],137 'group_id' => self::$group_ids['private'], 116 138 'type' => 'members', 117 139 'term' => 'cat', … … 123 145 public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() { 124 146 $suggestions = bp_core_get_suggestions( array( 125 'group_id' => $this->group_ids['public'],147 'group_id' => self::$group_ids['public'], 126 148 'type' => 'members', 127 149 'term' => 'smith', … … 131 153 132 154 $suggestions = bp_core_get_suggestions( array( 133 'group_id' => - $this->group_ids['public'],155 'group_id' => -self::$group_ids['public'], 134 156 'type' => 'members', 135 157 'term' => 'smith', … … 141 163 public function test_suggestions_with_type_groupmembers_private_and_exclude_group_from_results() { 142 164 $suggestions = bp_core_get_suggestions( array( 143 'group_id' => - $this->group_ids['private'],165 'group_id' => -self::$group_ids['private'], 144 166 'type' => 'members', 145 167 'term' => 'cat', … … 150 172 public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group_from_results() { 151 173 $suggestions = bp_core_get_suggestions( array( 152 'group_id' => $this->group_ids['hidden'],174 'group_id' => self::$group_ids['hidden'], 153 175 'type' => 'members', 154 176 'term' => 'pig', -
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.