Make WordPress Core


Ignore:
Timestamp:
10/10/2015 02:12:40 AM (9 years ago)
Author:
boonebgorges
Message:

Return WP_Term objects from get_terms().

Props boonebgorges, flixos90, DrewAPicture.
See #14162.

File:
1 edited

Legend:

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

    r34828 r34998  
    15731573    }
    15741574
     1575    /**
     1576     * @ticket 14162
     1577     */
     1578    public function test_should_return_wp_term_objects() {
     1579        register_taxonomy( 'wptests_tax', 'post' );
     1580        $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     1581
     1582        $found = get_terms( 'wptests_tax', array(
     1583            'hide_empty' => false,
     1584            'fields' => 'all',
     1585        ) );
     1586
     1587        $this->assertNotEmpty( $found );
     1588
     1589        foreach ( $found as $term ) {
     1590            $this->assertInstanceOf( 'WP_Term', $term );
     1591        }
     1592    }
     1593
     1594    /**
     1595     * @ticket 14162
     1596     */
     1597    public function test_should_prime_individual_term_cache_when_fields_is_all() {
     1598        global $wpdb;
     1599
     1600        register_taxonomy( 'wptests_tax', 'post' );
     1601        $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     1602
     1603        $found = get_terms( 'wptests_tax', array(
     1604            'hide_empty' => false,
     1605            'fields' => 'all',
     1606        ) );
     1607
     1608        $num_queries = $wpdb->num_queries;
     1609        $term0 = get_term( $terms[0] );
     1610        $this->assertSame( $num_queries, $wpdb->num_queries );
     1611
     1612    }
     1613
    15751614    protected function create_hierarchical_terms_and_posts() {
    15761615        $terms = array();
Note: See TracChangeset for help on using the changeset viewer.