Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions tests/phpunit/tests/term/wpInsertTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,77 @@ public function test_wp_insert_term_with_empty_name_after_db_sanitization() {
$this->assertSame( 'invalid_term_name', $term->get_error_code() );
}

/**
* @ticket 31270
*/
public function test_wp_insert_term_root_level_term_with_same_name_as_child_should_get_clean_slug() {
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );

$t1 = self::factory()->term->create(
array(
'name' => 'Foo',
'taxonomy' => 'wptests_tax',
)
);

self::factory()->term->create(
array(
'name' => 'Bar',
'slug' => 'foo-bar',
'parent' => $t1,
'taxonomy' => 'wptests_tax',
)
);

$t3 = wp_insert_term( 'Bar', 'wptests_tax' );

$this->assertNotWPError( $t3 );
$t3_term = get_term( $t3['term_id'], 'wptests_tax' );
$this->assertSame( 'bar', $t3_term->slug );
}

/**
* @ticket 31270
*/
public function test_wp_insert_term_child_term_with_same_name_as_another_child_under_different_parent_should_get_clean_slug() {
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );

$t1 = self::factory()->term->create(
array(
'name' => 'Parent One',
'taxonomy' => 'wptests_tax',
)
);

$t2 = self::factory()->term->create(
array(
'name' => 'Parent Two',
'taxonomy' => 'wptests_tax',
)
);

self::factory()->term->create(
array(
'name' => 'Child',
'slug' => 'parent-one-child',
'parent' => $t1,
'taxonomy' => 'wptests_tax',
)
);

$t4 = wp_insert_term(
'Child',
'wptests_tax',
array(
'parent' => $t2,
)
);

$this->assertNotWPError( $t4 );
$t4_term = get_term( $t4['term_id'], 'wptests_tax' );
$this->assertSame( 'child', $t4_term->slug );
}

/** Helpers */

public function deleted_term_cb( $term, $tt_id, $taxonomy, $deleted_term, $object_ids ) {
Expand Down
Loading