| | 536 | |
| | 537 | function test_post_password() { |
| | 538 | $post_id1 = (string) $this->factory->post->create( array( 'post_password' => '' ) ); |
| | 539 | $post_id2 = (string) $this->factory->post->create( array( 'post_password' => 'burrito' ) ); |
| | 540 | $post_id3 = (string) $this->factory->post->create( array( 'post_password' => 'burrito' ) ); |
| | 541 | |
| | 542 | // there are too many posts already in the database |
| | 543 | $args = array( 'post__in' => array( $post_id1, $post_id2, $post_id3 ), 'fields' => 'ids', 'orderby' => 'ID' ); |
| | 544 | |
| | 545 | $result1 = $this->q->query( array_merge( $args, array( 'has_password' => true ) ) ); |
| | 546 | $this->assertEquals( array( $post_id3, $post_id2 ), $result1 ); |
| | 547 | $result2 = $this->q->query( array_merge( $args, array( 'has_password' => false ) ) ); |
| | 548 | $this->assertEquals( array( $post_id1 ), $result2 ); |
| | 549 | $result3 = $this->q->query( array_merge( $args, array( 'has_password' => null ) ) ); |
| | 550 | $this->assertEquals( array( $post_id1 ), $result3 ); |
| | 551 | |
| | 552 | $result4 = $this->q->query( array_merge( $args, array( 'has_password' => true, 'post_password' => '' ) ) ); |
| | 553 | $this->assertEquals( array(), $result4 ); |
| | 554 | $result5 = $this->q->query( array_merge( $args, array( 'has_password' => false, 'post_password' => '' ) ) ); |
| | 555 | $this->assertEquals( array( $post_id1 ), $result5 ); |
| | 556 | $result6 = $this->q->query( array_merge( $args, array( 'has_password' => null, 'post_password' => '' ) ) ); |
| | 557 | $this->assertEquals( array( $post_id1 ), $result6 ); |
| | 558 | |
| | 559 | $result7 = $this->q->query( array_merge( $args, array( 'has_password' => true, 'post_password' => 'burrito' ) ) ); |
| | 560 | $this->assertEquals( array( $post_id3, $post_id2 ), $result7 ); |
| | 561 | $result8 = $this->q->query( array_merge( $args, array( 'has_password' => false, 'post_password' => 'burrito' ) ) ); |
| | 562 | $this->assertEquals( array(), $result8 ); |
| | 563 | $result9 = $this->q->query( array_merge( $args, array( 'has_password' => null, 'post_password' => 'burrito' ) ) ); |
| | 564 | $this->assertEquals( array(), $result9 ); |
| | 565 | |
| | 566 | $result10 = $this->q->query( array_merge( $args, array( 'post_password' => '' ) ) ); |
| | 567 | $this->assertEquals( array( $post_id1 ), $result10 ); |
| | 568 | $result11 = $this->q->query( array_merge( $args, array( 'post_password' => 'burrito' ) ) ); |
| | 569 | $this->assertEquals( array( $post_id3, $post_id2 ), $result11 ); |
| | 570 | } |