Make WordPress Core

Changeset 42594


Ignore:
Timestamp:
01/24/2018 08:51:06 PM (7 years ago)
Author:
jorbin
Message:

Query: Improve tests for set_found_posts dealing with non arrays

Use a data provider and include tests for false and ''.

Previous: [42581] [42585]

See #42860

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/query.php

    r42585 r42594  
    644644    }
    645645
     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 ),
     653        );
     654    }
     655
    646656    /**
    647657     * @ticket 42860
    648      */
    649     public function test_set_found_posts_fields_posts_is_string() {
     658     *
     659     * @dataProvider set_found_posts_provider
     660     */
     661    public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) {
    650662        if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    651663            $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
     
    660672        );
    661673
    662         $q->posts = "To life, to life, l'chaim";
     674        $q->posts = $posts;
    663675
    664676        $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' );
     
    666678        $methd->invoke( $q, array( 'no_found_rows' => false ), array() );
    667679
    668         $this->assertEquals( 1, $q->found_posts );
    669     }
    670 
    671     /**
    672      * @ticket 42860
    673      */
    674     public function test_set_found_posts_fields_posts_is_null() {
    675         if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    676             $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
    677             return;
    678         }
    679 
    680         $q = new WP_Query(
    681             array(
    682                 'post_type'      => 'wptests_pt',
    683                 'posts_per_page' => 1,
    684             )
    685         );
    686 
    687         $q->posts = null;
    688 
    689         $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' );
    690         $methd->setAccessible( true );
    691         $methd->invoke( $q, array( 'no_found_rows' => false ), array() );
    692 
    693         $this->assertEquals( 0, $q->found_posts );
     680        $this->assertEquals( $expected, $q->found_posts );
    694681    }
    695682
Note: See TracChangeset for help on using the changeset viewer.