WordPress.org

Make WordPress Core

Ticket #24461: patch.diff

File patch.diff, 1.1 KB (added by sgrant, 7 years ago)

Test to reproduce a fatal error in _get_term_children

  • tests/phpunit/tests/term/getTerms.php

     
    394394                add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
    395395        }
    396396
     397        /**
     398         * @covers ::_get_term_children
     399         */
     400        public function test_get_term_children_handles_cycles() {
     401                remove_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10 );
     402
     403                $parent = $this->factory->category->create();
     404                $child = $this->factory->category->create( array( 'parent' => $parent ) );
     405                wp_update_term( $parent, 'category', array( 'parent' => $child ) );
     406
     407                add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
     408
     409                $result = _get_term_children( $parent, array( $parent, $child ), 'category' );
     410
     411                $this->assertEquals( array( $child ), $result );
     412        }
     413
    397414        public function test_get_terms_by_slug() {
    398415                $t1 = $this->factory->tag->create( array( 'slug' => 'foo' ) );
    399416                $t2 = $this->factory->tag->create( array( 'slug' => 'bar' ) );