| | 372 | |
| | 373 | /** |
| | 374 | * @ticket 16854 |
| | 375 | */ |
| | 376 | function test_query_author_vars() { |
| | 377 | $author_1 = $this->factory->user->create( array( 'user_login' => 'admin1', 'user_pass' => rand_str(), 'role' => 'author' ) ); |
| | 378 | $post_1 = $this->factory->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_1, 'post_date' => '2007-01-01 00:00:00' ) ); |
| | 379 | |
| | 380 | $author_2 = $this->factory->user->create( array( 'user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author' ) ); |
| | 381 | $post_2 = $this->factory->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_2, 'post_date' => '2007-01-01 00:00:00' ) ); |
| | 382 | |
| | 383 | $author_3 = $this->factory->user->create( array( 'user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author' ) ); |
| | 384 | $post_3 = $this->factory->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_3, 'post_date' => '2007-01-01 00:00:00' ) ); |
| | 385 | |
| | 386 | $author_4 = $this->factory->user->create( array( 'user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author' ) ); |
| | 387 | $post_4 = $this->factory->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_4, 'post_date' => '2007-01-01 00:00:00' ) ); |
| | 388 | |
| | 389 | $posts = $this->q->query( array( |
| | 390 | 'author' => '', |
| | 391 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 392 | ) ); |
| | 393 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 394 | $this->assertEqualSets( array( $author_1, $author_2, $author_3, $author_4 ), $author_ids ); |
| | 395 | |
| | 396 | $posts = $this->q->query( array( |
| | 397 | 'author' => 0, |
| | 398 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 399 | ) ); |
| | 400 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 401 | $this->assertEqualSets( array( $author_1, $author_2, $author_3, $author_4 ), $author_ids ); |
| | 402 | |
| | 403 | $posts = $this->q->query( array( |
| | 404 | 'author' => '0', |
| | 405 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 406 | ) ); |
| | 407 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 408 | $this->assertEqualSets( array( $author_1, $author_2, $author_3, $author_4 ), $author_ids ); |
| | 409 | |
| | 410 | $posts = $this->q->query( array( |
| | 411 | 'author' => $author_1, |
| | 412 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 413 | ) ); |
| | 414 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 415 | $this->assertEqualSets( array( $author_1 ), $author_ids ); |
| | 416 | |
| | 417 | $posts = $this->q->query( array( |
| | 418 | 'author' => "$author_1", |
| | 419 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 420 | ) ); |
| | 421 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 422 | $this->assertEqualSets( array( $author_1 ), $author_ids ); |
| | 423 | |
| | 424 | $posts = $this->q->query( array( |
| | 425 | 'author' => "{$author_1},{$author_2}", |
| | 426 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 427 | ) ); |
| | 428 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 429 | $this->assertEqualSets( array( $author_1, $author_2 ), $author_ids ); |
| | 430 | |
| | 431 | $posts = $this->q->query( array( |
| | 432 | 'author' => "-{$author_1},{$author_2}", |
| | 433 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 434 | ) ); |
| | 435 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 436 | $this->assertEqualSets( array( $author_2 ), $author_ids ); |
| | 437 | |
| | 438 | $posts = $this->q->query( array( |
| | 439 | 'author' => "{$author_1},-{$author_2}", |
| | 440 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 441 | ) ); |
| | 442 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 443 | $this->assertEqualSets( array( $author_1 ), $author_ids ); |
| | 444 | |
| | 445 | $posts = $this->q->query( array( |
| | 446 | 'author' => "-{$author_1},-{$author_2}", |
| | 447 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 448 | ) ); |
| | 449 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 450 | $this->assertEqualSets( array( $author_3, $author_4 ), $author_ids ); |
| | 451 | |
| | 452 | $posts = $this->q->query( array( |
| | 453 | 'author__in' => array( $author_1, $author_2 ), |
| | 454 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 455 | ) ); |
| | 456 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 457 | $this->assertEqualSets( array( $author_1, $author_2 ), $author_ids ); |
| | 458 | |
| | 459 | $posts = $this->q->query( array( |
| | 460 | 'author__not_in' => array( $author_1, $author_2 ), |
| | 461 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 462 | ) ); |
| | 463 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 464 | $this->assertEqualSets( array( $author_3, $author_4 ), $author_ids ); |
| | 465 | |
| | 466 | $posts = $this->q->query( array( |
| | 467 | 'author_name' => 'admin1', |
| | 468 | 'post__in' => array( $post_1, $post_2, $post_3, $post_4 ) |
| | 469 | ) ); |
| | 470 | $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) ); |
| | 471 | $this->assertEqualSets( array( $author_1 ), $author_ids ); |
| | 472 | } |