diff --git a/tests/phpunit/tests/term/wpInsertTerm.php b/tests/phpunit/tests/term/wpInsertTerm.php index 24a67e0fe5313..5c3925453772f 100644 --- a/tests/phpunit/tests/term/wpInsertTerm.php +++ b/tests/phpunit/tests/term/wpInsertTerm.php @@ -910,6 +910,19 @@ public function test_wp_insert_term_with_empty_name_after_db_sanitization() { $this->assertSame( 'invalid_term_name', $term->get_error_code() ); } + /** + * @ticket 38243 + */ + public function test_wp_insert_term_with_invalid_utf8_name_should_not_create_blank_term() { + $count_before = wp_count_terms( array( 'taxonomy' => 'post_tag' ) ); + + $term = wp_insert_term( urldecode( '360%BF' ), 'post_tag' ); + + $this->assertWPError( $term ); + $this->assertSame( 'invalid_term_name', $term->get_error_code() ); + $this->assertSame( $count_before, wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); + } + /** * @ticket 31270 */ diff --git a/tests/phpunit/tests/term/wpUpdateTerm.php b/tests/phpunit/tests/term/wpUpdateTerm.php index eff2dfbbe6852..7c922cfa212fa 100644 --- a/tests/phpunit/tests/term/wpUpdateTerm.php +++ b/tests/phpunit/tests/term/wpUpdateTerm.php @@ -83,6 +83,30 @@ public function test_wp_update_term_name_empty_string() { _unregister_taxonomy( 'wptests_tax' ); } + /** + * @ticket 38243 + */ + public function test_wp_update_term_with_invalid_utf8_name_should_return_wp_error() { + $t = self::factory()->term->create( + array( + 'name' => 'Foo', + 'taxonomy' => 'post_tag', + ) + ); + + $found = wp_update_term( + $t, + 'post_tag', + array( + 'name' => urldecode( '360%BF' ), + ) + ); + + $this->assertWPError( $found ); + $this->assertSame( 'empty_term_name', $found->get_error_code() ); + $this->assertSame( 'Foo', get_term( $t )->name ); + } + /** * @ticket 29614 */