From b189d26960b5eb6a7d93685c68f4c357bf0b9311 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 6 Jun 2016 21:03:34 +0000 Subject: [PATCH] Add test demonstrating that `wp_insert_term()` will suffix a slug if the new term's auto-generated slug matches that of an existing term. See #37009. git-svn-id: https://develop.svn.wordpress.org/trunk@37641 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/term/wpInsertTerm.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/phpunit/tests/term/wpInsertTerm.php b/tests/phpunit/tests/term/wpInsertTerm.php index 386b66fa15..f636092095 100644 --- a/tests/phpunit/tests/term/wpInsertTerm.php +++ b/tests/phpunit/tests/term/wpInsertTerm.php @@ -642,6 +642,26 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { } + /** + * @ticket 37009 + */ + public function test_term_whose_slug_matches_existing_term_but_name_does_not_should_get_suffixed_slug() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t1 = self::factory()->term->create( array( + 'name' => 'Foo#bar', + 'taxonomy' => 'wptests_tax', + ) ); + + $created = wp_insert_term( 'Foo$bar', 'wptests_tax' ); + + $this->assertArrayHasKey( 'term_id', $created ); + + $created_term = get_term( $created['term_id'] ); + $this->assertSame( 'Foo$bar', $created_term->name ); + $this->assertSame( 'foobar-2', $created_term->slug ); + } + /** * @ticket 35321 */