Make WordPress Core


Ignore:
Timestamp:
01/26/2015 06:08:59 PM (10 years ago)
Author:
boonebgorges
Message:

Ensure that 'pad_counts' is not discarded when the first of multiple taxonomies passed to get_terms() is non-hierarchical.

See #31118.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/getTerms.php

    r31280 r31284  
    13501350    }
    13511351
     1352    /**
     1353     * @ticket 31118
     1354     */
     1355    public function test_pad_counts_should_work_when_first_taxonomy_is_nonhierarchical_and_second_taxonomy_is_hierarchical() {
     1356        register_taxonomy( 'wptests_tax1', 'post', array( 'hierarchical' => false ) );
     1357        register_taxonomy( 'wptests_tax2', 'post', array( 'hierarchical' => true ) );
     1358
     1359        $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax1' ) );
     1360        $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax2' ) );
     1361        $t3 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t2 ) );
     1362
     1363        $posts = $this->factory->post->create_many( 3 );
     1364        wp_set_object_terms( $posts[0], $t1, 'wptests_tax1' );
     1365        wp_set_object_terms( $posts[1], $t2, 'wptests_tax2' );
     1366        wp_set_object_terms( $posts[2], $t3, 'wptests_tax2' );
     1367
     1368        $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array(
     1369            'pad_counts' => true,
     1370        ) );
     1371
     1372        $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
     1373
     1374        foreach ( $found as $f ) {
     1375            if ( $t1 == $f->term_id ) {
     1376                $this->assertEquals( 1, $f->count );
     1377            } elseif ( $t2 == $f->term_id ) {
     1378                $this->assertEquals( 2, $f->count );
     1379            } else {
     1380                $this->assertEquals( 1, $f->count );
     1381            }
     1382        }
     1383    }
     1384
    13521385    protected function create_hierarchical_terms_and_posts() {
    13531386        $terms = array();
Note: See TracChangeset for help on using the changeset viewer.