Ticket #7436: 7436.purge-incremented-cache.patch
File 7436.purge-incremented-cache.patch, 2.8 KB (added by , 7 years ago) |
---|
-
src/bp-friends/bp-friends-cache.php
51 51 52 52 // Clear the friendship object cache. 53 53 wp_cache_delete( $friendship_id, 'bp_friends_friendships' ); 54 55 // Clear incremented cache. 56 $friendship = new stdClass; 57 $friendship->initiator_user_id = $initiator_user_id; 58 $friendship->friend_user_id = $friend_user_id; 59 bp_friends_delete_cached_friendships_on_friendship_save( $friendship ); 54 60 } 55 61 add_action( 'friends_friendship_requested', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 ); 56 62 add_action( 'friends_friendship_accepted', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 ); … … 71 77 72 78 // Clear the friendship object cache. 73 79 wp_cache_delete( $friendship_id, 'bp_friends_friendships' ); 80 81 // Clear incremented cache. 82 bp_friends_delete_cached_friendships_on_friendship_save( $friendship ); 74 83 } 75 84 add_action( 'friends_friendship_withdrawn', 'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 ); 76 85 add_action( 'friends_friendship_rejected', 'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 ); -
tests/phpunit/testcases/friends/functions.php
279 279 return $value; 280 280 } 281 281 282 /** 283 * @group friends_remove_friend 284 */ 285 public function test_friends_check_is_friend_after_remove() { 286 $now = time(); 287 $old_user = get_current_user_id(); 288 $u1 = $this->factory->user->create( array( 289 'last_activity' => date( 'Y-m-d H:i:s', $now ), 290 ) ); 291 $u2 = $this->factory->user->create( array( 292 'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ), 293 ) ); 294 295 /* 296 * Pretend user 1 is on the Members Directory page. 297 * 298 * Also primes the friendship cache in the process. 299 * @see bp_friends_filter_user_query_populate_extras() 300 */ 301 $this->set_current_user( $u1 ); 302 ob_start(); 303 bp_get_template_part( 'members/members-loop' ); 304 ob_end_clean(); 305 306 // User 1 initiates friendship. 307 friends_add_friend( $u1, $u2 ); 308 309 /* 310 * Pretend user 2 is logged in and accepts friendship. 311 * 312 * User 2 needs to be logged in for friends_accept_friendship() to work 313 * properly. 314 */ 315 $this->set_current_user( $u2 ); 316 friends_accept_friendship( friends_get_friendship_id( $u1, $u2 ) ); 317 318 // Afterwards, user 1 decides to cancel friendship. 319 $this->set_current_user( $u1 ); 320 friends_remove_friend( $u1, $u2 ); 321 322 // Assert that users are no longer friends. 323 $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) ); 324 325 $this->set_current_user( $old_user ); 326 } 327 282 328 /** 283 329 * @group friendship_caching 284 330 */