Make WordPress Core


Ignore:
Timestamp:
10/09/2014 02:48:47 AM (12 years ago)
Author:
boonebgorges
Message:

Fix term_exists() for parent = 0.

Passing a 0 (or '0') as the 'parent' param of term_exists() should limit
results to terms with no parent.

Adds unit test.

Fixes #29851.

File:
1 edited

Legend:

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

    r29862 r29863  
    137137                $this->assertInternalType( 'array', $found );
    138138                $this->assertEquals( $t, $found['term_id'] );
     139        }
     140
     141        /**
     142         * @ticket 29851
     143         */
     144        public function test_term_exists_taxonomy_nonempty_parent_0_should_return_false_for_child_term() {
     145                register_taxonomy( 'foo', 'post', array(
     146                        'hierarchical' => true,
     147                ) );
     148
     149                $parent_term = $this->factory->term->create( array(
     150                        'taxonomy' => 'foo',
     151                ) );
     152
     153                $t = $this->factory->term->create( array(
     154                        'taxonomy' => 'foo',
     155                        'parent' => $parent_term,
     156                        'slug' => 'child-term',
     157                ) );
     158
     159                $found = term_exists( 'child-term', 'foo', 0 );
     160
     161                _unregister_taxonomy( 'foo' );
     162
     163                $this->assertSame( null, $found['term_id'] );
    139164        }
    140165
Note: See TracChangeset for help on using the changeset viewer.