Ticket #8540: 8540.1.patch
File 8540.1.patch, 22.1 KB (added by , 2 years ago) |
---|
-
src/bp-members/bp-members-cache.php
diff --git src/bp-members/bp-members-cache.php src/bp-members/bp-members-cache.php index 54185a454..296582726 100644
function bp_members_reset_activity_cache_incrementor() { 73 73 return bp_core_reset_incrementor( 'bp_activity_with_last_activity' ); 74 74 } 75 75 add_action( 'bp_core_user_updated_last_activity', 'bp_members_reset_activity_cache_incrementor' ); 76 77 /** 78 * Bust signup caches when editing or deleting. 79 * 80 * @since 10.0.0 81 * 82 * @param int $signup_id The ID of the signup affected. 83 */ 84 function bp_members_delete_signup_cache( $signup_id = 0 ) { 85 wp_cache_delete( $signup_id, 'bp_signups' ); 86 } 87 add_action( 'bp_core_signups_after_add', 'bp_members_delete_signup_cache' ); 88 add_action( 'bp_core_signups_after_update_meta', 'bp_members_delete_signup_cache' ); 89 90 /** 91 * Bust signup caches for arrays of signup IDs. 92 * 93 * @since 10.0.0 94 * 95 * @param array $signup_ids The IDs of the signups affected. 96 */ 97 function bp_members_delete_signup_cache_multiples( $signup_ids = array() ) { 98 // Ensure that the incoming item is an array. 99 $signup_ids = wp_parse_id_list( $signup_ids ); 100 foreach ( $signup_ids as $signup_id ) { 101 bp_members_delete_signup_cache( $signup_id ); 102 } 103 } 104 add_action( 'bp_core_signup_after_resend', 'bp_members_delete_signup_cache_multiples' ); 105 add_action( 'bp_core_signup_after_activate', 'bp_members_delete_signup_cache_multiples' ); 106 add_action( 'bp_core_signup_after_delete', 'bp_members_delete_signup_cache_multiples' ); 107 108 /** 109 * Reset cache incrementor for BP_Signups. 110 * 111 * This function invalidates all cached results of BP_Signup queries, 112 * whenever one of the following events takes place: 113 * - A record is created or updated. 114 * - A record is deleted. 115 * 116 * @since 10.0.0 117 * 118 * @return bool True on success, false on failure. 119 */ 120 function bp_members_reset_signup_cache_incrementor() { 121 return bp_core_reset_incrementor( 'bp_signups' ); 122 } 123 add_filter( 'bp_core_signups_after_add', 'bp_members_reset_signup_cache_incrementor' ); 124 add_action( 'bp_core_activated_user', 'bp_members_reset_signup_cache_incrementor' ); 125 add_action( 'bp_core_signup_after_activate', 'bp_members_reset_signup_cache_incrementor' ); 126 add_action( 'bp_core_signups_after_update_meta', 'bp_members_reset_signup_cache_incrementor' ); 127 add_action( 'bp_core_signup_after_delete', 'bp_members_reset_signup_cache_incrementor' ); 128 -
src/bp-members/classes/class-bp-signup.php
diff --git src/bp-members/classes/class-bp-signup.php src/bp-members/classes/class-bp-signup.php index f1eece597..b0f1d6673 100644
class BP_Signup { 89 89 * @param integer $signup_id The ID for the signup being queried. 90 90 */ 91 91 public function __construct( $signup_id = 0 ) { 92 if ( ! empty( $signup_id ) ) {92 if ( ! empty( $signup_id ) ) { 93 93 $this->id = $signup_id; 94 94 $this->populate(); 95 95 } … … class BP_Signup { 103 103 public function populate() { 104 104 global $wpdb; 105 105 106 $signups_table = buddypress()->members->table_name_signups;107 $ signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE signup_id = %d AND active = 0", $this->id ));106 // Get BuddyPress. 107 $bp = buddypress(); 108 108 109 $this->avatar = get_avatar( $signup->user_email, 32 ); 109 // Check cache for signup data. 110 $signup = wp_cache_get( $this->id, 'bp_signups' ); 111 112 // Cache missed, so query the DB. 113 if ( false === $signup ) { 114 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->members->table_name_signups} WHERE signup_id = %d AND active = 0", $this->id ) ); 115 116 wp_cache_set( $this->id, $signup, 'bp_signups' ); 117 } 118 119 // No signup found so set the ID and bail. 120 if ( empty( $signup ) || is_wp_error( $signup ) ) { 121 $this->id = 0; 122 return; 123 } 124 125 /* 126 * Add every db column to the object. 127 */ 128 $this->signup_id = $this->id; 129 $this->domain = $signup->domain; 130 $this->path = $signup->path; 131 $this->title = $signup->title; 110 132 $this->user_login = $signup->user_login; 111 133 $this->user_email = $signup->user_email; 112 $this->meta = maybe_unserialize( $signup->meta );113 $this->user_name = ! empty( $this->meta['field_1'] ) ? wp_unslash( $this->meta['field_1'] ) : '';114 134 $this->registered = $signup->registered; 135 $this->activated = $signup->activated; 136 $this->active = $signup->active; 115 137 $this->activation_key = $signup->activation_key; 138 $this->meta = maybe_unserialize( $signup->meta ); 139 140 // Add richness. 141 $this->avatar = get_avatar( $signup->user_email, 32 ); 142 $this->user_name = ! empty( $this->meta['field_1'] ) ? wp_unslash( $this->meta['field_1'] ) : ''; 143 144 // When was the activation email sent? 145 if ( isset( $this->meta['sent_date'] ) ) { 146 $this->date_sent = $this->meta['sent_date']; 147 } else { 148 $this->date_sent = '0000-00-00 00:00:00'; 149 } 150 151 /** 152 * Calculate a diff between now & last time 153 * an activation link has been resent. 154 */ 155 $sent_at = mysql2date('U', $this->date_sent ); 156 $now = current_time( 'timestamp', true ); 157 $diff = $now - $sent_at; 158 159 /** 160 * Set a boolean to track whether an activation link 161 * was sent in the last day. 162 */ 163 $this->recently_sent = ( $diff < 1 * DAY_IN_SECONDS ); 164 165 // How many times has the activation email been sent? 166 if ( isset( $this->meta['count_sent'] ) ) { 167 $this->count_sent = absint( $this->meta['count_sent'] ); 168 } else { 169 $this->count_sent = 0; 170 } 116 171 } 117 172 118 173 /** Static Methods *******************************************************/ … … class BP_Signup { 126 181 * @param array $args { 127 182 * The argument to retrieve desired signups. 128 183 * @type int $offset Offset amount. Default 0. 129 * @type int $number How many to fetch. Default 1.184 * @type int $number How many to fetch. Pass -1 to fetch all. Default 1. 130 185 * @type bool|string $usersearch Whether or not to search for a username. Default false. 131 186 * @type string $orderby Order By parameter. Possible values are `signup_id`, `login`, `email`, 132 187 * `registered`, `activated`. Default `signup_id`. … … class BP_Signup { 145 200 public static function get( $args = array() ) { 146 201 global $wpdb; 147 202 148 $r = bp_parse_args( $args, 203 $bp = buddypress(); 204 $r = bp_parse_args( $args, 149 205 array( 150 206 'offset' => 0, 151 207 'number' => 1, … … class BP_Signup { 154 210 'order' => 'DESC', 155 211 'include' => false, 156 212 'activation_key' => '', 213 'user_email' => '', 157 214 'user_login' => '', 158 215 'fields' => 'all', 159 216 ), … … class BP_Signup { 171 228 172 229 $r['orderby'] = sanitize_title( $r['orderby'] ); 173 230 174 $sql = array(); 175 $signups_table = buddypress()->members->table_name_signups; 176 $sql['select'] = "SELECT * FROM {$signups_table}"; 177 $sql['where'] = array(); 178 $sql['where'][] = "active = 0"; 231 $sql = array( 232 'select' => "SELECT DISTINCT signup_id", 233 'from' => "{$bp->members->table_name_signups}", 234 'where' => array( 235 'active = 0', 236 ), 237 'orderby' => '', 238 'limit' => '', 239 ); 179 240 180 241 if ( empty( $r['include'] ) ) { 181 242 … … class BP_Signup { 190 251 $sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] ); 191 252 } 192 253 254 // User email. 255 if ( ! empty( $r['user_email'] ) ) { 256 $sql['where'][] = $wpdb->prepare( "user_email = %s", $r['user_email'] ); 257 } 258 193 259 // User login. 194 260 if ( ! empty( $r['user_login'] ) ) { 195 261 $sql['where'][] = $wpdb->prepare( "user_login = %s", $r['user_login'] ); 196 262 } 197 263 198 $sql['orderby'] = "ORDER BY {$r['orderby']}"; 199 $sql['order'] = bp_esc_sql_order( $r['order'] ); 200 $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", $r['offset'], $r['number'] ); 264 $order = bp_esc_sql_order( $r['order'] ); 265 $sql['orderby'] = "ORDER BY {$r['orderby']} {$order}"; 266 267 $number = intval( $r['number'] ); 268 if ( -1 !== $number ) { 269 $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", absint( $r['offset'] ), $number ); 270 } 201 271 } else { 202 $in = implode( ',', wp_parse_id_list( $r['include'] ) );203 $sql[' in'] = "ANDsignup_id IN ({$in})";272 $in = implode( ',', wp_parse_id_list( $r['include'] ) ); 273 $sql['where'][] = "signup_id IN ({$in})"; 204 274 } 205 275 206 276 // Implode WHERE clauses. 207 277 $sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] ); 208 278 279 $paged_signups_sql = "{$sql['select']} FROM {$sql['from']} {$sql['where']} {$sql['orderby']} {$sql['limit']}"; 280 209 281 /** 210 282 * Filters the Signups paged query. 211 283 * … … class BP_Signup { 216 288 * @param array $args Array of original arguments for get() method. 217 289 * @param array $r Array of parsed arguments for get() method. 218 290 */ 219 $paged_signups = $wpdb->get_results( apply_filters( 'bp_members_signups_paged_query', join( ' ', $sql ), $sql, $args, $r ));291 $paged_signups_sql = apply_filters( 'bp_members_signups_paged_query', $paged_signups_sql, $sql, $args, $r ); 220 292 221 if ( empty( $paged_signups ) ) { 222 return array( 'signups' => false, 'total' => false ); 293 $cached = bp_core_get_incremented_cache( $paged_signups_sql, 'bp_signups' ); 294 if ( false === $cached ) { 295 $paged_signup_ids = $wpdb->get_col( $paged_signups_sql ); 296 bp_core_set_incremented_cache( $paged_signups_sql, 'bp_signups', $paged_signup_ids ); 297 } else { 298 $paged_signup_ids = $cached; 223 299 } 224 300 225 301 // We only want the IDs. 226 302 if ( 'ids' === $r['fields'] ) { 227 $paged_signups = wp_list_pluck( $paged_signups, 'signup_id' );228 } else {229 230 // Used to calculate a diff between now & last231 // time an activation link has been resent.232 $now = current_time( 'timestamp', true );233 234 foreach ( (array) $paged_signups as $key => $signup ) {235 303 236 $signup->id = intval( $signup->signup_id);304 $paged_signups = array_map( 'intval', $paged_signup_ids ); 237 305 238 $signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false; 239 240 $signup->user_name = ''; 241 if ( ! empty( $signup->meta['field_1'] ) ) { 242 $signup->user_name = wp_unslash( $signup->meta['field_1'] ); 243 } 244 245 // Sent date defaults to date of registration. 246 if ( ! empty( $signup->meta['sent_date'] ) ) { 247 $signup->date_sent = $signup->meta['sent_date']; 248 } else { 249 $signup->date_sent = $signup->registered; 250 } 251 252 $sent_at = mysql2date('U', $signup->date_sent ); 253 $diff = $now - $sent_at; 254 255 /** 256 * Add a boolean in case the last time an activation link 257 * has been sent happened less than a day ago. 258 */ 259 if ( $diff < 1 * DAY_IN_SECONDS ) { 260 $signup->recently_sent = true; 261 } 306 } else { 262 307 263 if ( ! empty( $signup->meta['count_sent'] ) ) { 264 $signup->count_sent = absint( $signup->meta['count_sent'] ); 265 } else { 266 $signup->count_sent = 1; 308 $uncached_signup_ids = bp_get_non_cached_ids( $paged_signup_ids, 'bp_signups' ); 309 if ( $uncached_signup_ids ) { 310 $signup_ids_sql = implode( ',', array_map( 'intval', $uncached_signup_ids ) ); 311 $signup_data_objects = $wpdb->get_results( "SELECT * FROM {$bp->members->table_name_signups} WHERE signup_id IN ({$signup_ids_sql})" ); 312 foreach ( $signup_data_objects as $signup_data_object ) { 313 wp_cache_set( $signup_data_object->signup_id, $signup_data_object, 'bp_signups' ); 267 314 } 315 } 268 316 269 $paged_signups[ $key ] = $signup; 317 $paged_signups = array(); 318 foreach ( $paged_signup_ids as $paged_signup_id ) { 319 $paged_signups[] = new BP_Signup( $paged_signup_id ); 270 320 } 321 271 322 } 272 323 273 unset( $sql['limit'] );274 $ sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] );324 // Find the total number of signups in the results set. 325 $total_signups_sql = "SELECT COUNT(DISTINCT signup_id) FROM {$sql['from']} {$sql['where']}"; 275 326 276 327 /** 277 328 * Filters the Signups count query. … … class BP_Signup { 283 334 * @param array $args Array of original arguments for get() method. 284 335 * @param array $r Array of parsed arguments for get() method. 285 336 */ 286 $total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) ); 337 $total_signups_sql = apply_filters( 'bp_members_signups_count_query', $total_signups_sql, $sql, $args, $r ); 338 339 $cached = bp_core_get_incremented_cache( $total_signups_sql, 'bp_signups' ); 340 if ( false === $cached ) { 341 $total_signups = (int) $wpdb->get_var( $total_signups_sql ); 342 bp_core_set_incremented_cache( $total_signups_sql, 'bp_signups', $total_signups ); 343 } else { 344 $total_signups = (int) $cached; 345 } 287 346 288 347 return array( 'signups' => $paged_signups, 'total' => $total_signups ); 289 348 } … … class BP_Signup { 318 377 'user_email' => '', 319 378 'registered' => current_time( 'mysql', true ), 320 379 'activation_key' => '', 321 'meta' => '',380 'meta' => array(), 322 381 ), 323 382 'bp_core_signups_add_args' 324 383 ); 325 384 385 // Ensure that sent_date and count_sent are set in meta. 386 if ( ! isset( $r['meta']['sent_date'] ) ) { 387 $r['meta']['sent_date'] = '0000-00-00 00:00:00'; 388 } 389 if ( ! isset( $r['meta']['count_sent'] ) ) { 390 $r['meta']['count_sent'] = 0; 391 } 392 326 393 $r['meta'] = maybe_serialize( $r['meta'] ); 327 394 328 395 $inserted = $wpdb->insert( … … class BP_Signup { 337 404 $retval = false; 338 405 } 339 406 407 /** 408 * Fires after adding a new BP_Signup. 409 * 410 * @since 10.0.0 411 * 412 * @param int|bool $retval ID of the BP_Signup just added. 413 * @param array $r Array of parsed arguments for add() method. 414 * @param array $args Array of original arguments for add() method. 415 */ 416 do_action( 'bp_core_signups_after_add', $retval, $r, $args ); 417 340 418 /** 341 419 * Filters the result of a signup addition. 342 420 * 343 421 * @since 2.0.0 344 422 * 345 * @param int|bool $retval Newly added userID on success, false on failure.423 * @param int|bool $retval Newly added signup ID on success, false on failure. 346 424 */ 347 425 return apply_filters( 'bp_core_signups_add', $retval ); 348 426 } … … class BP_Signup { 420 498 } 421 499 } 422 500 501 /** 502 * Fires after adding a new WP User (backcompat). 503 * 504 * @since 10.0.0 505 * 506 * @param int $user_id ID of the WP_User just added. 507 */ 508 do_action( 'bp_core_signups_after_add_backcompat', $user_id ); 509 423 510 /** 424 511 * Filters the user ID for the backcompat functionality. 425 512 * … … class BP_Signup { 445 532 return false; 446 533 } 447 534 448 $user_status = $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id ) ); 535 $user = get_user_by( 'id', $user_id ); 536 $user_status = $user->user_status; 449 537 450 538 /** 451 539 * Filters the user status of a provided user ID. … … class BP_Signup { 511 599 * @return int The number of signups. 512 600 */ 513 601 public static function count_signups() { 514 global $wpdb; 515 516 $signups_table = buddypress()->members->table_name_signups; 517 $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) ); 602 $all_signups = self::get( 603 array( 604 'fields' => 'ids', 605 ) 606 ); 607 $count_signups = $all_signups['total']; 518 608 519 609 /** 520 610 * Filters the total inactive signups. … … class BP_Signup { 556 646 return false; 557 647 } 558 648 649 $signup_id = absint( $r['signup_id'] ); 650 651 // Figure out which meta keys should be updated. 652 $signup = new BP_Signup( $signup_id ); 653 $blended_meta = wp_parse_args( $r['meta'], $signup->meta ); 654 559 655 $wpdb->update( 560 656 // Signups table. 561 657 buddypress()->members->table_name_signups, 562 658 // Data to update. 563 659 array( 564 'meta' => serialize( $ r['meta']),660 'meta' => serialize( $blended_meta ), 565 661 ), 566 662 // WHERE. 567 663 array( 568 'signup_id' => $ r['signup_id'],664 'signup_id' => $signup_id, 569 665 ), 570 666 // Data sanitization format. 571 667 array( … … class BP_Signup { 577 673 ) 578 674 ); 579 675 676 /** 677 * Fires after updating the meta of a new BP_Signup. 678 * 679 * @since 10.0.0 680 * 681 * @param int|bool $signup_id ID of the BP_Signup updated. 682 * @param array $r Array of parsed arguments to update() method. 683 * @param array $args Array of original arguments to update() method. 684 * @param array $blended_meta The complete set of meta to save. 685 */ 686 do_action( 'bp_core_signups_after_update_meta', $signup_id, $r, $args, $blended_meta ); 687 580 688 /** 581 689 * Filters the signup ID which received a meta update. 582 690 * … … class BP_Signup { 621 729 622 730 foreach ( $signups as $signup ) { 623 731 624 $meta = $signup->meta; 625 $meta['sent_date'] = current_time( 'mysql', true ); 626 $meta['count_sent'] = $signup->count_sent + 1; 732 $meta = array( 733 'sent_date' => current_time( 'mysql', true ), 734 'count_sent' => $signup->count_sent + 1 735 ); 627 736 628 737 // Send activation email. 629 738 if ( is_multisite() ) { -
tests/phpunit/testcases/members/class-bp-signup.php
diff --git tests/phpunit/testcases/members/class-bp-signup.php tests/phpunit/testcases/members/class-bp-signup.php index 4a420d414..cee9cbe47 100644
class BP_Tests_BP_Signup extends BP_UnitTestCase { 356 356 357 357 $this->assertEquals( array( $s3, $s2, $s1 ), $ss['signups'] ); 358 358 } 359 360 /** 361 * @group cache 362 */ 363 public function test_get_queries_should_be_cached() { 364 global $wpdb; 365 366 $s = self::factory()->signup->create(); 367 368 $found1 = BP_Signup::get( 369 array( 370 'fields' => 'ids', 371 ) 372 ); 373 374 $num_queries = $wpdb->num_queries; 375 376 $found2 = BP_Signup::get( 377 array( 378 'fields' => 'ids', 379 ) 380 ); 381 382 $this->assertEqualSets( $found1, $found2 ); 383 $this->assertSame( $num_queries, $wpdb->num_queries ); 384 } 385 386 /** 387 * @group cache 388 */ 389 public function test_get_query_caches_should_be_busted_by_add() { 390 $s1 = self::factory()->signup->create(); 391 392 $found1 = BP_Signup::get( 393 array( 394 'fields' => 'ids', 395 ) 396 ); 397 $this->assertEqualSets( array( $s1 ), $found1['signups'] ); 398 399 $s2 = self::factory()->signup->create(); 400 $found2 = BP_Signup::get( 401 array( 402 'fields' => 'ids', 403 ) 404 ); 405 $this->assertEqualSets( array( $s2 ), $found2['signups'] ); 406 } 407 408 /** 409 * @group cache 410 */ 411 public function test_get_query_caches_should_be_busted_by_meta_update() { 412 $time = bp_core_current_time(); 413 414 $args = array( 415 'domain' => 'foo', 416 'path' => 'bar', 417 'title' => 'Foo bar', 418 'user_login' => 'user1', 419 'user_email' => 'user1@example.com', 420 'registered' => $time, 421 'activation_key' => '12345', 422 'meta' => array( 423 'field_1' => 'Fozzie', 424 'meta1' => 'meta2', 425 ), 426 ); 427 $s1 = BP_Signup::add( $args ); 428 429 $args['meta']['field_1'] = 'Fozz'; 430 $s2 = BP_Signup::add( $args ); 431 432 // Should find both. 433 $found1 = BP_Signup::get( array( 434 'fields' => 'ids', 435 'number' => -1, 436 'usersearch' => 'Fozz', 437 ) ); 438 $this->assertEqualSets( array( $s1, $s2 ), $found1['signups'] ); 439 440 BP_Signup::update( array( 441 'signup_id' => $s1, 442 'meta' => array( 443 'field_1' => 'Fonzie' 444 ), 445 ) ); 446 447 $found2 = BP_Signup::get( array( 448 'fields' => 'ids', 449 'number' => -1, 450 'usersearch' => 'Fozz', 451 ) ); 452 453 $this->assertEqualSets( array( $s2 ), $found2['signups'] ); 454 } 455 456 /** 457 * @group cache 458 */ 459 public function test_get_query_caches_should_be_busted_by_delete() { 460 global $wpdb; 461 $time = bp_core_current_time(); 462 463 $args = array( 464 'domain' => 'foo', 465 'path' => 'bar', 466 'title' => 'Foo bar', 467 'user_login' => 'user1', 468 'user_email' => 'user1@example.com', 469 'registered' => $time, 470 'activation_key' => '12345', 471 'meta' => array( 472 'field_1' => 'Fozzie', 473 'meta1' => 'meta2', 474 ), 475 ); 476 $s1 = BP_Signup::add( $args ); 477 478 $args['meta']['field_1'] = 'Fozz'; 479 $s2 = BP_Signup::add( $args ); 480 481 // Should find both. 482 $found1 = BP_Signup::get( array( 483 'fields' => 'ids', 484 'number' => -1, 485 'usersearch' => 'Fozz', 486 ) ); 487 $this->assertEqualSets( array( $s1, $s2 ), $found1['signups'] ); 488 489 BP_Signup::delete( array( $s1 ) ); 490 491 $found2 = BP_Signup::get( array( 492 'fields' => 'ids', 493 'number' => -1, 494 'usersearch' => 'Fozz', 495 ) ); 496 497 $this->assertEqualSets( array( $s2 ), $found2['signups'] ); 498 } 499 500 /** 501 * @group cache 502 */ 503 public function test_get_query_caches_should_be_busted_by_activation() { 504 $s1 = self::factory()->signup->create( array( 505 'user_login' => 'accountone', 506 'user_email' => 'accountone@example.com', 507 'activation_key' => 'activationkeyone', 508 ) ); 509 510 $s2 = self::factory()->signup->create( array( 511 'user_login' => 'accounttwo', 512 'user_email' => 'accounttwo@example.com', 513 'activation_key' => 'activationkeytwo', 514 ) ); 515 $found1 = BP_Signup::get( 516 array( 517 'number' => -1, 518 'fields' => 'ids', 519 ) 520 ); 521 $this->assertEqualSets( array( $s1, $s2 ), $found1['signups'] ); 522 523 $activate = BP_Signup::activate( (array) $s2 ); 524 525 $found2 = BP_Signup::get( 526 array( 527 'number' => -1, 528 'fields' => 'ids', 529 ) 530 ); 531 $this->assertEqualSets( array( $s1 ), $found2['signups'] ); 532 } 533 534 /** 535 * @group cache 536 */ 537 public function test_objects_should_be_cached() { 538 $s1 = self::factory()->signup->create( array( 539 'user_login' => 'accountone', 540 'user_email' => 'accountone@example.com', 541 'activation_key' => 'activationkeyone', 542 ) ); 543 544 $found1 = new BP_Signup( $s1 ); 545 $this->assertEquals( $s1, $found1->id ); 546 547 $activate = BP_Signup::activate( (array) $s1 ); 548 549 $found2 = new BP_Signup( $s1 ); 550 $this->assertEquals( 0, $found2->id ); 551 } 552 553 /** 554 * @group cache 555 */ 556 public function object_caches_should_be_busted_by_activation() { 557 global $wpdb; 558 559 $s1 = self::factory()->signup->create( array( 560 'user_login' => 'accountone', 561 'user_email' => 'accountone@example.com', 562 'activation_key' => 'activationkeyone', 563 ) ); 564 565 $found1 = new BP_Signup( $s1 ); 566 567 $num_queries = $wpdb->num_queries; 568 569 // Object should be rebuilt from cache. 570 $found2 = new BP_Signup( $s1 ); 571 572 // @TODO: This fails because "get_avatar()" in populate() results in db queries. 573 $this->assertEquals( $found1, $found2 ); 574 $this->assertEquals( $num_queries, $wpdb->num_queries ); 575 } 359 576 }