Make WordPress Core

Ticket #42469: 42469.2.diff

File 42469.2.diff, 1.5 KB (added by birgire, 6 years ago)
  • src/wp-includes/class-wp-query.php

    diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php
    index afc8f96..5fb8dc5 100644
    class WP_Query { 
    30303030                         * @param string   $found_posts The query to run to find the found posts.
    30313031                         * @param WP_Query $this        The WP_Query instance (passed by reference).
    30323032                         */
    3033                         $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     3033                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
     3034
     3035                        $this->found_posts = (int) $wpdb->get_var( $found_posts_query );
    30343036                } else {
    30353037                        $this->found_posts = count( $this->posts );
    30363038                }
  • tests/phpunit/tests/post/query.php

    diff --git tests/phpunit/tests/post/query.php tests/phpunit/tests/post/query.php
    index 6ae8114..995568c 100644
    class Tests_Post_Query extends WP_UnitTestCase { 
    535535                $this->assertEquals( 2, $q->found_posts );
    536536                $this->assertEquals( 2, $q->max_num_pages );
    537537        }
     538
     539        /**
     540         * The found_posts property should be of type int, not string.
     541         *
     542         * @ticket 42469
     543         */
     544        public function test_found_posts_should_be_integer_not_string() {
     545                $this->post_id = self::factory()->post->create();
     546
     547                $q = new WP_Query( array(
     548                        'posts_per_page' => 1,
     549                ) );
     550
     551                $this->assertTrue( is_int( $q->found_posts ) );
     552                $this->assertFalse( is_string( $q->found_posts ) );
     553        }
    538554}