Make WordPress Core

Changeset 55460


Ignore:
Timestamp:
03/04/2023 11:50:26 AM (14 months ago)
Author:
SergeyBiryukov
Message:

Tests: Make sure the correct query is tested for term limits in taxonomy queries.

By hooking into terms_pre_query after the fixture posts and terms are created but before the actual taxonomy query runs, we ensure that the correct SQL query from WP_Term_Query::get_terms() is tested for requested term limits, rather than the one initiated from wp_insert_post() or wp_insert_term() via term_exists().

Follow-up to [52921], [53037].

Props david.binda.
Fixes #57342.

File:
1 edited

Legend:

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

    r53037 r55460  
    16291629     */
    16301630    public function test_tax_terms_should_limit_query() {
    1631         $filter = new MockAction();
    1632         add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
    16331631        register_taxonomy( 'wptests_tax', 'post' );
    16341632        $name = 'foobar';
     
    16431641        wp_set_object_terms( $p, array( $t ), 'wptests_tax' );
    16441642
     1643        $filter = new MockAction();
     1644        add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
     1645
    16451646        $q = new WP_Query(
    16461647            array(
     
    16571658
    16581659        $filter_args = $filter->get_args();
    1659         $query       = $filter_args[1][1]->request;
     1660        $query       = $filter_args[0][1]->request;
    16601661
    16611662        $this->assertSameSets( array( $p ), $q->posts );
     
    16691670     */
    16701671    public function test_tax_terms_should_limit_query_to_one() {
    1671         $filter = new MockAction();
    1672         add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
    16731672        register_taxonomy( 'wptests_tax', 'post' );
    16741673        $name = 'foobar';
     
    16831682        wp_set_object_terms( $p, array( $t ), 'wptests_tax' );
    16841683
     1684        $filter = new MockAction();
     1685        add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
     1686
    16851687        $q = new WP_Query(
    16861688            array(
     
    16971699
    16981700        $filter_args = $filter->get_args();
    1699         $query       = $filter_args[1][1]->request;
     1701        $query       = $filter_args[0][1]->request;
    17001702
    17011703        $this->assertSameSets( array( $p ), $q->posts );
     
    17091711     */
    17101712    public function test_hierarchical_taxonomies_do_not_limit_query() {
    1711         $filter = new MockAction();
    1712         add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
    17131713        register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
    17141714        $name = 'foobar';
     
    17231723        wp_set_object_terms( $p, array( $t ), 'wptests_tax' );
    17241724
     1725        $filter = new MockAction();
     1726        add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
     1727
    17251728        $q = new WP_Query(
    17261729            array(
Note: See TracChangeset for help on using the changeset viewer.