Make WordPress Core

Ticket #46768: 46768.2.diff

File 46768.2.diff, 2.4 KB (added by deepaklalwani, 5 years ago)

Adds unit test cases

  • src/wp-includes/class-wp-term-query.php

    diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php
    index 37aecfd33b..8aba70a747 100644
    class WP_Term_Query { 
    616616                                $selects = array( 'COUNT(*)' );
    617617                                break;
    618618                        case 'id=>name':
    619                                 $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' );
     619                                $selects = array( 't.term_id', 't.name', 'tt.parent', 'tt.count', 'tt.taxonomy' );
    620620                                break;
    621621                        case 'id=>slug':
    622                                 $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );
     622                                $selects = array( 't.term_id', 't.slug', 'tt.parent', 'tt.count', 'tt.taxonomy' );
    623623                                break;
    624624                }
    625625
  • tests/phpunit/tests/term/getTerms.php

    diff --git tests/phpunit/tests/term/getTerms.php tests/phpunit/tests/term/getTerms.php
    index 2c20a191eb..d7d3cd6e81 100644
    class Tests_Term_getTerms extends WP_UnitTestCase { 
    719719                $this->assertEquals( 1, count( $terms ) );
    720720        }
    721721
     722        /**
     723         * @ticket 46768
     724         */
     725        function test_get_terms_child_of_fields_id_name() {
     726                $parent = self::factory()->category->create();
     727                $child  = self::factory()->category->create(
     728                        array(
     729                                'parent' => $parent,
     730                                'slug' => 'test-1',
     731                                'name' => 'Test 1',
     732                        )
     733                );
     734                $child2  = self::factory()->category->create(
     735                        array(
     736                                'parent' => $parent,
     737                                'slug' => 'test-2',
     738                                'name' => 'Test 2',
     739                        )
     740                );
     741
     742                $terms = get_terms(
     743                        'category',
     744                        array(
     745                                'child_of'   => $parent,
     746                                'hide_empty' => false,
     747                                'fields'      => 'id=>name',
     748                        )
     749                );
     750
     751                $this->assertEquals(
     752                        array(
     753                                $child  => 'Test 1',
     754                                $child2 => 'Test 2',
     755                        ),
     756                        $terms
     757                );
     758
     759        }
     760
     761        /**
     762         * @ticket 46768
     763         */
     764        function test_get_terms_child_of_fields_id_slug() {
     765                $parent = self::factory()->category->create();
     766                $child  = self::factory()->category->create(
     767                        array(
     768                                'parent' => $parent,
     769                                'slug' => 'test-1',
     770                                'name' => 'Test 1',
     771                        )
     772                );
     773                $child2  = self::factory()->category->create(
     774                        array(
     775                                'parent' => $parent,
     776                                'slug' => 'test-2',
     777                                'name' => 'Test 2',
     778                        )
     779                );
     780
     781                $terms = get_terms(
     782                        'category',
     783                        array(
     784                                'child_of'   => $parent,
     785                                'hide_empty' => false,
     786                                'fields'      => 'id=>slug',
     787                        )
     788                );
     789
     790                $this->assertEquals(
     791                        array(
     792                                $child  => 'test-1',
     793                                $child2 => 'test-2',
     794                        ),
     795                        $terms
     796                );
     797        }
     798
    722799        /**
    723800         * @ticket 31118
    724801         */