Make WordPress Core


Ignore:
Timestamp:
03/07/2014 07:29:01 PM (12 years ago)
Author:
wonderboymusic
Message:

In get_terms(), leverage get_term_children() over _get_term_children() when making sure to show empty terms that have children in a hierarchical taxonomy while avoiding duplicates.

Adds unit test for child_of param. Adjusts unit tests for get_terms().

See [27108] and [27125].
Props SergeyBiryukov.
Fixes #27123.

File:
1 edited

Legend:

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

    r27197 r27458  
    277277
    278278                $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) );
    279                 $this->assertNotEmpty( $terms );
     279                $this->assertEquals( 2, count( $terms ) );
    280280                $this->assertEquals( wp_list_pluck( $terms, 'name' ), array( 'Cheese', 'Crackers' ) );
    281281        }
     
    297297
    298298                $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) );
    299                 $this->assertNotEmpty( $terms );
     299                $this->assertEquals( 1, count( $terms ) );
    300300                $this->assertEquals( array( 'Cheese' ), wp_list_pluck( $terms, 'name' ) );
    301301
     
    321321
    322322                $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) );
    323                 $this->assertNotEmpty( $terms );
     323                $this->assertEquals( 1, count( $terms ) );
    324324                $this->assertEquals( array( 'term1' ), wp_list_pluck( $terms, 'name' ) );
    325325
    326326                _unregister_taxonomy( $tax );
    327327        }
     328
     329        /**
     330         * @ticket 27123
     331         */
     332        function test_get_terms_child_of() {
     333                $parent = $this->factory->category->create();
     334                $child = $this->factory->category->create( array( 'parent' => $parent ) );
     335
     336                $terms = get_terms( 'category', array( 'child_of' => $parent, 'hide_empty' => false ) );
     337                $this->assertEquals( 1, count( $terms ) );
     338        }
    328339}
Note: See TracChangeset for help on using the changeset viewer.