Ticket #42860: 42860.diff
File 42860.diff, 1.9 KB (added by , 7 years ago) |
---|
-
tests/phpunit/tests/post/query.php
643 643 $this->assertEquals( 2, $q->max_num_pages ); 644 644 } 645 645 646 /** 647 * @ticket 42860 648 */ 649 public function test_set_found_posts_fields_posts_is_string() { 650 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { 651 $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); 652 return; 653 } 654 655 $q = new WP_Query( 656 array( 657 'post_type' => 'wptests_pt', 658 'posts_per_page' => 1, 659 ) 646 public function set_found_posts_provider() { 647 // count return 0 for null, but 1 for other data you may not expect 648 return array( 649 array( null, 0 ), 650 array( '', 1 ), 651 array( "To life, to life, l'chaim", 1 ), 652 array( false, 1 ), 660 653 ); 661 662 $q->posts = "To life, to life, l'chaim";663 664 $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' );665 $methd->setAccessible( true );666 $methd->invoke( $q, array( 'no_found_rows' => false ), array() );667 668 $this->assertEquals( 1, $q->found_posts );669 654 } 670 655 671 656 /** 672 657 * @ticket 42860 658 * 659 * @dataProvider set_found_posts_provider 673 660 */ 674 public function test_set_found_posts_ fields_posts_is_null() {661 public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) { 675 662 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { 676 663 $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); 677 664 return; … … 684 671 ) 685 672 ); 686 673 687 $q->posts = null;674 $q->posts = $posts; 688 675 689 676 $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' ); 690 677 $methd->setAccessible( true ); 691 678 $methd->invoke( $q, array( 'no_found_rows' => false ), array() ); 692 679 693 $this->assertEquals( 0, $q->found_posts );680 $this->assertEquals( $expected, $q->found_posts ); 694 681 } 695 682 696 683 }