| 335 | |
| 336 | public function test_friends_get_recently_active() { |
| 337 | $u1 = $this->factory->user->create(); |
| 338 | $u2 = $this->factory->user->create(); |
| 339 | $u3 = $this->factory->user->create(); |
| 340 | $u4 = $this->factory->user->create(); |
| 341 | |
| 342 | // request friendship |
| 343 | friends_add_friend( $u1, $u2, true ); |
| 344 | friends_add_friend( $u1, $u3, true ); |
| 345 | friends_add_friend( $u1, $u4, true ); |
| 346 | |
| 347 | bp_update_user_last_activity( $u2, date( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) ) ); |
| 348 | bp_update_user_last_activity( $u3, date( 'Y-m-d H:i:s', time() - ( 5 * DAY_IN_SECONDS ) ) ); |
| 349 | bp_update_user_last_activity( $u4, date( 'Y-m-d H:i:s', time() - ( 3 * DAY_IN_SECONDS ) ) ); |
| 350 | |
| 351 | $recent = friends_get_recently_active( $u1 ); |
| 352 | |
| 353 | $this->assertEquals( $recent['users'][0]->ID, $u2 ); |
| 354 | $this->assertEquals( $recent['users'][1]->ID, $u4 ); |
| 355 | $this->assertEquals( $recent['users'][2]->ID, $u3 ); |
| 356 | } |
| 357 | |
| 358 | public function test_friends_get_alphabetically() { |
| 359 | $u1 = $this->factory->user->create(); |
| 360 | $u2 = $this->factory->user->create(); |
| 361 | $u3 = $this->factory->user->create(); |
| 362 | |
| 363 | // request friendship |
| 364 | friends_add_friend( $u1, $u2, true ); |
| 365 | friends_add_friend( $u1, $u3, true ); |
| 366 | |
| 367 | wp_update_user( array( 'ID' => $u2, 'display_name' => 'Dave Lister' ) ); |
| 368 | wp_update_user( array( 'ID' => $u3, 'display_name' => 'Arnold Rimmer' ) ); |
| 369 | |
| 370 | $alpha = friends_get_alphabetically( $u1 ); |
| 371 | $this->assertEquals( $alpha['users'][0]->ID, $u3 ); |
| 372 | $this->assertEquals( $alpha['users'][1]->ID, $u2 ); |
| 373 | } |
| 374 | |
| 375 | public function test_friends_get_newest() { |
| 376 | $u1 = $this->factory->user->create(); |
| 377 | $u2 = $this->factory->user->create(); |
| 378 | $u3 = $this->factory->user->create(); |
| 379 | $u4 = $this->factory->user->create(); |
| 380 | |
| 381 | // request friendship |
| 382 | friends_add_friend( $u1, $u2, true ); |
| 383 | friends_add_friend( $u1, $u3, true ); |
| 384 | friends_add_friend( $u1, $u4, true ); |
| 385 | |
| 386 | bp_update_user_last_activity( $u2, date( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) ) ); |
| 387 | bp_update_user_last_activity( $u3, date( 'Y-m-d H:i:s', time() - ( 5 * DAY_IN_SECONDS ) ) ); |
| 388 | bp_update_user_last_activity( $u4, date( 'Y-m-d H:i:s', time() - ( 3 * DAY_IN_SECONDS ) ) ); |
| 389 | |
| 390 | $newest = friends_get_newest( $u1 ); |
| 391 | |
| 392 | $this->assertEquals( $newest['users'][0]->ID, $u4 ); |
| 393 | $this->assertEquals( $newest['users'][1]->ID, $u3 ); |
| 394 | $this->assertEquals( $newest['users'][2]->ID, $u2 ); |
| 395 | } |