Make WordPress Core

Ticket #42860: 42860.diff

File 42860.diff, 1.9 KB (added by jorbin, 7 years ago)
  • tests/phpunit/tests/post/query.php

     
    643643                $this->assertEquals( 2, $q->max_num_pages );
    644644        }
    645645
    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 ),
    660653                );
    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 );
    669654        }
    670655
    671656        /**
    672657         * @ticket 42860
     658         *
     659         * @dataProvider set_found_posts_provider
    673660         */
    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 ) {
    675662                if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    676663                        $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
    677664                        return;
     
    684671                        )
    685672                );
    686673
    687                 $q->posts = null;
     674                $q->posts = $posts;
    688675
    689676                $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' );
    690677                $methd->setAccessible( true );
    691678                $methd->invoke( $q, array( 'no_found_rows' => false ), array() );
    692679
    693                 $this->assertEquals( 0, $q->found_posts );
     680                $this->assertEquals( $expected, $q->found_posts );
    694681        }
    695682
    696683}