| | 171 | |
| | 172 | /** |
| | 173 | * @ticket 17689 |
| | 174 | */ |
| | 175 | function test_duplicate_name() { |
| | 176 | $term = $this->factory->tag->create_and_get( array( 'name' => 'Bozo' ) ); |
| | 177 | $this->assertFalse( is_wp_error( $term ) ); |
| | 178 | $this->assertTrue( empty( $term->errors ) ); |
| | 179 | |
| | 180 | // Test existing term name with unique slug |
| | 181 | $term1 = $this->factory->tag->create( array( 'name' => 'Bozo', 'slug' => 'bozo1' ) ); |
| | 182 | $this->assertFalse( is_wp_error( $term1 ) ); |
| | 183 | $this->assertTrue( empty($term1->errors ) ); |
| | 184 | |
| | 185 | // Test an existing term name |
| | 186 | $term2 = $this->factory->tag->create( array( 'name' => 'Bozo' ) ); |
| | 187 | $this->assertTrue( is_wp_error( $term2 ) ); |
| | 188 | $this->assertNotEmpty( $term2->errors ); |
| | 189 | |
| | 190 | // Test named terms ending in special characters |
| | 191 | $term3 = $this->factory->tag->create( array( 'name' => 'T$' ) ); |
| | 192 | $term4 = $this->factory->tag->create( array( 'name' => 'T$$' ) ); |
| | 193 | $term5 = $this->factory->tag->create( array( 'name' => 'T$$$' ) ); |
| | 194 | $term6 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) ); |
| | 195 | $term7 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) ); |
| | 196 | $this->assertTrue( is_wp_error( $term7 ) ); |
| | 197 | $this->assertNotEmpty( $term7->errors ); |
| | 198 | $this->assertEquals( $term6, $term7->error_data['term_exists'] ); |
| | 199 | |
| | 200 | $terms = array_map( 'get_tag', array( $term3, $term4, $term5, $term6 ) ); |
| | 201 | $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) ); |
| | 202 | |
| | 203 | // Test named terms with only special characters |
| | 204 | $term8 = $this->factory->tag->create( array( 'name' => '$' ) ); |
| | 205 | $term9 = $this->factory->tag->create( array( 'name' => '$$' ) ); |
| | 206 | $term10 = $this->factory->tag->create( array( 'name' => '$$$' ) ); |
| | 207 | $term11 = $this->factory->tag->create( array( 'name' => '$$$$' ) ); |
| | 208 | $term12 = $this->factory->tag->create( array( 'name' => '$$$$' ) ); |
| | 209 | $this->assertTrue( is_wp_error( $term12 ) ); |
| | 210 | $this->assertNotEmpty( $term12->errors ); |
| | 211 | $this->assertEquals( $term11, $term12->error_data['term_exists'] ); |
| | 212 | |
| | 213 | $terms = array_map( 'get_tag', array( $term8, $term9, $term10, $term11 ) ); |
| | 214 | $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) ); |
| | 215 | } |