| | 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 | |