| 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 | |
| 372 | $this->assertEquals( $alpha['users'][0]->id, $u3 ); |
| 373 | $this->assertEquals( $alpha['users'][1]->id, $u2 ); |
| 374 | } |
| 375 | |
| 376 | public function test_friends_get_newest() { |
| 377 | $u1 = $this->factory->user->create(); |
| 378 | $u2 = $this->factory->user->create(); |
| 379 | $u3 = $this->factory->user->create(); |
| 380 | $u4 = $this->factory->user->create(); |
| 381 | |
| 382 | // request friendship |
| 383 | friends_add_friend( $u1, $u2, true ); |
| 384 | friends_add_friend( $u1, $u3, true ); |
| 385 | friends_add_friend( $u1, $u4, true ); |
| 386 | |
| 387 | bp_update_user_last_activity( $u2, date( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) ) ); |
| 388 | bp_update_user_last_activity( $u3, date( 'Y-m-d H:i:s', time() - ( 5 * DAY_IN_SECONDS ) ) ); |
| 389 | bp_update_user_last_activity( $u4, date( 'Y-m-d H:i:s', time() - ( 3 * DAY_IN_SECONDS ) ) ); |
| 390 | |
| 391 | $newest = friends_get_newest( $u1 ); |
| 392 | |
| 393 | $this->assertEquals( $newest['users'][0]->id, $u4 ); |
| 394 | $this->assertEquals( $newest['users'][1]->id, $u3 ); |
| 395 | $this->assertEquals( $newest['users'][2]->id, $u2 ); |
| 396 | } |