Make WordPress Core


Ignore:
Timestamp:
12/22/2013 06:30:09 PM (11 years ago)
Author:
wonderboymusic
Message:

Fix a regression for get_queried_object() by checking for category_name when cat isn't set - mainly is_category() being true for Uncategorized or when queried object is accessed in pre_get_posts. Also check for $query['terms'] when trying to assign a term as the queried object when is_tax() is true. Adds a unit test. See [26007] for how I originally broke this while fixing a bigger issue.

Props Chouby, jeremyfelt.
Fixes #26634, #26627.

File:
1 edited

Legend:

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

    r26007 r26864  
    1818
    1919    protected $cat;
     20    protected $uncat;
    2021    protected $tag;
    2122    protected $tax;
     
    4849        _make_cat_compat( $this->cat );
    4950        $this->tag = get_term( $this->tag_id, 'post_tag' );
     51
     52        $this->uncat = get_term_by( 'slug', 'uncategorized', 'category' );
     53        _make_cat_compat( $this->uncat );
    5054
    5155        add_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
     
    107111    }
    108112
     113    function test_cat_uncat_action_tax() {
     114        // category with tax added
     115        add_action( 'pre_get_posts', array( $this, '_cat_uncat_action_tax' ), 11 );
     116
     117        $this->go_to( home_url( "/category/uncategorized/" ) );
     118        $this->assertQueryTrue( 'is_category', 'is_archive' );
     119        $this->assertNotEmpty( get_query_var( 'cat' ) );
     120        $this->assertNotEmpty( get_query_var( 'tax_query' ) );
     121        $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
     122        $this->assertNotEmpty( get_query_var( 'term_id' ) );
     123        $this->assertEquals( get_queried_object(), $this->uncat );
     124
     125        remove_action( 'pre_get_posts', array( $this, '_cat_uncat_action_tax' ), 11 );
     126    }
     127
     128    function _cat_uncat_action_tax( &$query ) {
     129        $this->assertTrue( $query->is_category() );
     130        $this->assertTrue( $query->is_archive() );
     131        $this->assertNotEmpty( $query->get( 'category_name' ) );
     132        $this->assertNotEmpty( $query->get( 'tax_query' ) );
     133        $this->assertEquals( $query->get_queried_object(), $this->uncat );
     134    }
     135
    109136    function test_tax_query_tag_action_tax() {
    110137        // tax + tag with tax added
Note: See TracChangeset for help on using the changeset viewer.