Make WordPress Core


Ignore:
Timestamp:
07/05/2020 09:32:26 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Query: Make sure the found_posts property of WP_Query is always an integer, to match the documented type.

This makes the property consistent with similar properties of other classes:

  • WP_Comment_Query::$found_comments
  • WP_Network_Query::$found_networks
  • WP_Site_Query::$found_sites
  • WP_User_Query::$total_users

Props birgire, PressLabs.
Fixes #42469.

File:
1 edited

Legend:

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

    r47122 r48328  
    653653
    654654                add_filter( 'split_the_query', '__return_true' );
     655
    655656                $q = new WP_Query(
    656657                        array(
     
    659660                        )
    660661                );
     662
    661663                remove_filter( 'split_the_query', '__return_true' );
    662664
     
    678680                // ! $split_the_query
    679681                add_filter( 'split_the_query', '__return_false' );
     682
    680683                $q = new WP_Query(
    681684                        array(
     
    684687                        )
    685688                );
     689
    686690                remove_filter( 'split_the_query', '__return_false' );
    687691
     
    722726        }
    723727
     728        /**
     729         * @ticket 42469
     730         */
     731        public function test_found_posts_should_be_integer_not_string() {
     732                $this->post_id = self::factory()->post->create();
     733
     734                $q = new WP_Query(
     735                        array(
     736                                'posts_per_page' => 1,
     737                        )
     738                );
     739
     740                $this->assertInternalType( 'int', $q->found_posts );
     741        }
     742
     743        /**
     744         * @ticket 42469
     745         */
     746        public function test_found_posts_should_be_integer_even_if_found_posts_filter_returns_string_value() {
     747                $this->post_id = self::factory()->post->create();
     748
     749                add_filter( 'found_posts', '__return_empty_string' );
     750
     751                $q = new WP_Query(
     752                        array(
     753                                'posts_per_page' => 1,
     754                        )
     755                );
     756
     757                remove_filter( 'found_posts', '__return_empty_string' );
     758
     759                $this->assertInternalType( 'int', $q->found_posts );
     760        }
    724761}
Note: See TracChangeset for help on using the changeset viewer.