Changeset 31812 for trunk/tests/phpunit/tests/term.php
- Timestamp:
- 03/18/2015 01:27:15 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term.php
r31792 r31812 6 6 class Tests_Term extends WP_UnitTestCase { 7 7 var $taxonomy = 'category'; 8 9 function setUp() {10 parent::setUp();11 12 _clean_term_filters();13 // insert one term into every post taxonomy14 // otherwise term_ids and term_taxonomy_ids might be identical, which could mask bugs15 $term = rand_str();16 foreach(get_object_taxonomies('post') as $tax)17 wp_insert_term( $term, $tax );18 }19 20 function deleted_term_cb( $term, $tt_id, $taxonomy, $deleted_term ) {21 $this->assertInternalType( 'object', $deleted_term );22 $this->assertInternalType( 'int', $term );23 // Pesky string $this->assertInternalType( 'int', $tt_id );24 $this->assertEquals( $term, $deleted_term->term_id );25 $this->assertEquals( $taxonomy, $deleted_term->taxonomy );26 $this->assertEquals( $tt_id, $deleted_term->term_taxonomy_id );27 }28 29 function test_wp_insert_delete_term() {30 // a new unused term31 $term = rand_str();32 $this->assertNull( term_exists($term) );33 34 $initial_count = wp_count_terms( $this->taxonomy );35 36 $t = wp_insert_term( $term, $this->taxonomy );37 $this->assertInternalType( 'array', $t );38 $this->assertFalse( is_wp_error($t) );39 $this->assertTrue( $t['term_id'] > 0 );40 $this->assertTrue( $t['term_taxonomy_id'] > 0 );41 $this->assertEquals( $initial_count + 1, wp_count_terms($this->taxonomy) );42 43 // make sure the term exists44 $this->assertTrue( term_exists($term) > 0 );45 $this->assertTrue( term_exists($t['term_id']) > 0 );46 47 // now delete it48 add_filter( 'delete_term', array( $this, 'deleted_term_cb' ), 10, 4 );49 $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );50 remove_filter( 'delete_term', array( $this, 'deleted_term_cb' ), 10, 4 );51 $this->assertNull( term_exists($term) );52 $this->assertNull( term_exists($t['term_id']) );53 $this->assertEquals( $initial_count, wp_count_terms($this->taxonomy) );54 }55 56 public function test_wp_insert_term_taxonomy_does_not_exist() {57 $found = wp_insert_term( 'foo', 'bar' );58 59 $this->assertTrue( is_wp_error( $found ) );60 $this->assertSame( 'invalid_taxonomy', $found->get_error_code() );61 }62 63 public function test_wp_insert_term_pre_insert_term_filter_returns_wp_error() {64 add_filter( 'pre_insert_term', array( $this, '_pre_insert_term_callback' ) );65 $found = wp_insert_term( 'foo', 'post_tag' );66 remove_filter( 'pre_insert_term', array( $this, '_pre_insert_term_callback' ) );67 68 $this->assertTrue( is_wp_error( $found ) );69 $this->assertSame( 'custom_error', $found->get_error_code() );70 }71 72 public function test_wp_insert_term_term_0() {73 $found = wp_insert_term( 0, 'post_tag' );74 75 $this->assertTrue( is_wp_error( $found ) );76 $this->assertSame( 'invalid_term_id', $found->get_error_code() );77 }78 79 public function test_wp_insert_term_term_trims_to_empty_string() {80 $found = wp_insert_term( ' ', 'post_tag' );81 82 $this->assertTrue( is_wp_error( $found ) );83 $this->assertSame( 'empty_term_name', $found->get_error_code() );84 }85 86 public function test_wp_insert_term_parent_does_not_exist() {87 $found = wp_insert_term( 'foo', 'post_tag', array(88 'parent' => 999999,89 ) );90 91 $this->assertTrue( is_wp_error( $found ) );92 $this->assertSame( 'missing_parent', $found->get_error_code() );93 }94 95 public function test_wp_insert_term_unslash_name() {96 register_taxonomy( 'wptests_tax', 'post' );97 $found = wp_insert_term( 'Let\\\'s all say \\"Hooray\\" for WordPress taxonomy', 'wptests_tax' );98 99 $term = get_term( $found['term_id'], 'wptests_tax' );100 _unregister_taxonomy( 'wptests_tax' );101 102 $this->assertSame( 'Let\'s all say "Hooray" for WordPress taxonomy', $term->name );103 }104 105 public function test_wp_insert_term_unslash_description() {106 register_taxonomy( 'wptests_tax', 'post' );107 $found = wp_insert_term( 'Quality', 'wptests_tax', array(108 'description' => 'Let\\\'s all say \\"Hooray\\" for WordPress taxonomy',109 ) );110 111 $term = get_term( $found['term_id'], 'wptests_tax' );112 _unregister_taxonomy( 'wptests_tax' );113 114 $this->assertSame( 'Let\'s all say "Hooray" for WordPress taxonomy', $term->description );115 }116 117 public function test_wp_insert_term_parent_string() {118 register_taxonomy( 'wptests_tax', 'post' );119 $found = wp_insert_term( 'Quality', 'wptests_tax', array(120 'parent' => 'foo1',121 ) );122 123 $term = get_term( $found['term_id'], 'wptests_tax' );124 _unregister_taxonomy( 'wptests_tax' );125 126 // 'foo1' is cast to 0 in sanitize_term().127 $this->assertSame( 0, $term->parent );128 }129 130 public function test_wp_insert_term_slug_empty_string() {131 register_taxonomy( 'wptests_tax', 'post' );132 $found = wp_insert_term( 'Quality', 'wptests_tax', array(133 'slug' => '',134 ) );135 136 $term = get_term( $found['term_id'], 'wptests_tax' );137 _unregister_taxonomy( 'wptests_tax' );138 139 $this->assertSame( 'quality', $term->slug );140 141 }142 143 public function test_wp_insert_term_slug_whitespace_string() {144 register_taxonomy( 'wptests_tax', 'post' );145 $found = wp_insert_term( 'Quality', 'wptests_tax', array(146 'slug' => ' ',147 ) );148 149 $term = get_term( $found['term_id'], 'wptests_tax' );150 _unregister_taxonomy( 'wptests_tax' );151 152 $this->assertSame( 'quality', $term->slug );153 }154 155 public function test_wp_insert_term_slug_0() {156 register_taxonomy( 'wptests_tax', 'post' );157 $found = wp_insert_term( 'Quality', 'wptests_tax', array(158 'slug' => 0,159 ) );160 161 $term = get_term( $found['term_id'], 'wptests_tax' );162 _unregister_taxonomy( 'wptests_tax' );163 164 $this->assertSame( 'quality', $term->slug );165 }166 167 /**168 * @ticket 17689169 */170 public function test_wp_insert_term_duplicate_name() {171 $term = $this->factory->tag->create_and_get( array( 'name' => 'Bozo' ) );172 $this->assertFalse( is_wp_error( $term ) );173 $this->assertTrue( empty( $term->errors ) );174 175 // Test existing term name with unique slug176 $term1 = $this->factory->tag->create( array( 'name' => 'Bozo', 'slug' => 'bozo1' ) );177 $this->assertFalse( is_wp_error( $term1 ) );178 179 // Test an existing term name180 $term2 = $this->factory->tag->create( array( 'name' => 'Bozo' ) );181 $this->assertTrue( is_wp_error( $term2 ) );182 $this->assertNotEmpty( $term2->errors );183 184 // Test named terms ending in special characters185 $term3 = $this->factory->tag->create( array( 'name' => 'T$' ) );186 $term4 = $this->factory->tag->create( array( 'name' => 'T$$' ) );187 $term5 = $this->factory->tag->create( array( 'name' => 'T$$$' ) );188 $term6 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) );189 $term7 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) );190 $this->assertTrue( is_wp_error( $term7 ) );191 $this->assertNotEmpty( $term7->errors );192 $this->assertEquals( $term6, $term7->error_data['term_exists'] );193 194 $terms = array_map( 'get_tag', array( $term3, $term4, $term5, $term6 ) );195 $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) );196 197 // Test named terms with only special characters198 $term8 = $this->factory->tag->create( array( 'name' => '$' ) );199 $term9 = $this->factory->tag->create( array( 'name' => '$$' ) );200 $term10 = $this->factory->tag->create( array( 'name' => '$$$' ) );201 $term11 = $this->factory->tag->create( array( 'name' => '$$$$' ) );202 $term12 = $this->factory->tag->create( array( 'name' => '$$$$' ) );203 $this->assertTrue( is_wp_error( $term12 ) );204 $this->assertNotEmpty( $term12->errors );205 $this->assertEquals( $term11, $term12->error_data['term_exists'] );206 207 $terms = array_map( 'get_tag', array( $term8, $term9, $term10, $term11 ) );208 $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) );209 210 $term13 = $this->factory->tag->create( array( 'name' => 'A' ) );211 $this->assertFalse( is_wp_error( $term13 ) );212 $term14 = $this->factory->tag->create( array( 'name' => 'A' ) );213 $this->assertTrue( is_wp_error( $term14 ) );214 $term15 = $this->factory->tag->create( array( 'name' => 'A+', 'slug' => 'a' ) );215 $this->assertFalse( is_wp_error( $term15 ) );216 $term16 = $this->factory->tag->create( array( 'name' => 'A+' ) );217 $this->assertTrue( is_wp_error( $term16 ) );218 $term17 = $this->factory->tag->create( array( 'name' => 'A++' ) );219 $this->assertFalse( is_wp_error( $term17 ) );220 $term18 = $this->factory->tag->create( array( 'name' => 'A-', 'slug' => 'a' ) );221 $this->assertFalse( is_wp_error( $term18 ) );222 $term19 = $this->factory->tag->create( array( 'name' => 'A-' ) );223 $this->assertTrue( is_wp_error( $term19 ) );224 $term20 = $this->factory->tag->create( array( 'name' => 'A--' ) );225 $this->assertFalse( is_wp_error( $term20 ) );226 }227 228 /**229 * @ticket 31328230 */231 public function test_wp_insert_term_should_not_allow_duplicate_names_when_slug_is_a_duplicate_of_the_same_term_in_non_hierarchical_taxonomy() {232 register_taxonomy( 'wptests_tax', 'post' );233 $t1 = $this->factory->term->create( array(234 'name' => 'Foo',235 'slug' => 'foo',236 'taxonomy' => 'wptests_tax',237 ) );238 239 $t2 = wp_insert_term( 'Foo', 'wptests_tax', array(240 'slug' => 'foo',241 ) );242 243 $this->assertWPError( $t2 );244 $this->assertSame( 'term_exists', $t2->get_error_code() );245 }246 247 /**248 * @ticket 31328249 */250 public function test_wp_insert_term_should_not_allow_duplicate_names_when_slug_is_a_duplicate_of_a_different_term_in_non_hierarchical_taxonomy() {251 register_taxonomy( 'wptests_tax', 'post' );252 $t1 = $this->factory->term->create( array(253 'name' => 'Foo',254 'slug' => 'foo',255 'taxonomy' => 'wptests_tax',256 ) );257 258 $t2 = $this->factory->term->create( array(259 'name' => 'Bar',260 'slug' => 'bar',261 'taxonomy' => 'wptests_tax',262 ) );263 264 $t3 = wp_insert_term( 'Foo', 'wptests_tax', array(265 'slug' => 'bar',266 ) );267 268 $this->assertWPError( $t3 );269 $this->assertSame( 'term_exists', $t3->get_error_code() );270 }271 272 /**273 * @ticket 31328274 */275 public function test_wp_insert_term_should_allow_duplicate_names_when_a_unique_slug_has_been_provided_in_non_hierarchical_taxonomy() {276 register_taxonomy( 'wptests_tax', 'post' );277 $t1 = $this->factory->term->create( array(278 'name' => 'Foo',279 'slug' => 'foo',280 'taxonomy' => 'wptests_tax',281 ) );282 283 $t2 = wp_insert_term( 'Foo', 'wptests_tax', array(284 'slug' => 'foo-unique',285 ) );286 287 $this->assertFalse( is_wp_error( $t2 ) );288 289 $t2_term = get_term( $t2['term_id'], 'wptests_tax' );290 $this->assertSame( 'foo-unique', $t2_term->slug );291 $this->assertSame( 'Foo', $t2_term->name );292 }293 294 /**295 * @ticket 31328296 */297 public function test_wp_insert_term_should_not_allow_duplicate_names_when_the_slug_is_not_provided_in_non_hierarchical_taxonomy() {298 register_taxonomy( 'wptests_tax', 'post' );299 $t1 = $this->factory->term->create( array(300 'name' => 'Foo',301 'slug' => 'foo',302 'taxonomy' => 'wptests_tax',303 ) );304 305 $t2 = wp_insert_term( 'Foo', 'wptests_tax' );306 307 $this->assertWPError( $t2 );308 $this->assertSame( 'term_exists', $t2->get_error_code() );309 }310 311 /**312 * @ticket 31328313 */314 public function test_wp_insert_term_should_not_allow_duplicate_names_when_slug_is_a_duplicate_of_the_same_term_in_hierarchical_taxonomy() {315 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );316 $t1 = $this->factory->term->create( array(317 'name' => 'Foo',318 'slug' => 'foo',319 'taxonomy' => 'wptests_tax',320 ) );321 322 $t2 = wp_insert_term( 'Foo', 'wptests_tax', array(323 'slug' => 'foo',324 ) );325 326 $this->assertWPError( $t2 );327 $this->assertSame( 'term_exists', $t2->get_error_code() );328 }329 330 /**331 * @ticket 31328332 */333 public function test_wp_insert_term_should_not_allow_duplicate_names_when_slug_is_a_duplicate_of_a_different_term_at_same_hierarchy_level_in_hierarchical_taxonomy() {334 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );335 $t1 = $this->factory->term->create( array(336 'name' => 'Foo',337 'slug' => 'foo',338 'taxonomy' => 'wptests_tax',339 ) );340 341 $t2 = $this->factory->term->create( array(342 'name' => 'Bar',343 'slug' => 'bar',344 'taxonomy' => 'wptests_tax',345 ) );346 347 $t3 = wp_insert_term( 'Foo', 'wptests_tax', array(348 'slug' => 'bar',349 ) );350 351 $this->assertWPError( $t3 );352 $this->assertSame( 'term_exists', $t3->get_error_code() );353 }354 355 /**356 * @ticket 31328357 */358 public function test_wp_insert_term_should_allow_duplicate_names_when_slug_is_a_duplicate_of_a_term_at_different_hierarchy_level_in_hierarchical_taxonomy() {359 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );360 $t1 = $this->factory->term->create( array(361 'name' => 'Foo',362 'slug' => 'foo',363 'taxonomy' => 'wptests_tax',364 ) );365 366 $t2 = $this->factory->term->create();367 368 $t3 = $this->factory->term->create( array(369 'name' => 'Bar',370 'slug' => 'bar',371 'parent' => $t2,372 'taxonomy' => 'wptests_tax',373 ) );374 375 $t4 = wp_insert_term( 'Foo', 'wptests_tax', array(376 'slug' => 'bar',377 ) );378 379 $this->assertFalse( is_wp_error( $t4 ) );380 $t4_term = get_term( $t4['term_id'], 'wptests_tax' );381 382 // `wp_unique_term_slug()` allows term creation but iterates the slug.383 $this->assertSame( 'bar-2', $t4_term->slug );384 $this->assertSame( 'Foo', $t4_term->name );385 }386 387 /**388 * @ticket 31328389 */390 public function test_wp_insert_term_should_allow_duplicate_names_when_a_unique_slug_has_been_provided_in_hierarchical_taxonomy() {391 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );392 $t1 = $this->factory->term->create( array(393 'name' => 'Foo',394 'slug' => 'foo',395 'taxonomy' => 'wptests_tax',396 ) );397 398 $t2 = wp_insert_term( 'Foo', 'wptests_tax', array(399 'slug' => 'foo-unique',400 ) );401 402 $this->assertFalse( is_wp_error( $t2 ) );403 404 $t2_term = get_term( $t2['term_id'], 'wptests_tax' );405 $this->assertSame( 'foo-unique', $t2_term->slug );406 $this->assertSame( 'Foo', $t2_term->name );407 }408 409 /**410 * @ticket 31328411 */412 public function test_wp_insert_term_should_not_allow_duplicate_names_when_the_slug_is_not_provided_in_hierarchical_taxonomy() {413 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );414 $t1 = $this->factory->term->create( array(415 'name' => 'Foo',416 'slug' => 'foo',417 'taxonomy' => 'wptests_tax',418 ) );419 420 $t2 = wp_insert_term( 'Foo', 'wptests_tax' );421 422 $this->assertWPError( $t2 );423 $this->assertSame( 'term_exists', $t2->get_error_code() );424 }425 /**426 * @ticket 5809427 */428 public function test_wp_insert_term_duplicate_slug_same_taxonomy() {429 register_taxonomy( 'wptests_tax', 'post' );430 $t = $this->factory->term->create( array(431 'name' => 'Foo',432 'slug' => 'foo',433 'taxonomy' => 'wptests_tax',434 ) );435 436 $term = get_term( $t, 'wptests_tax' );437 438 $created = wp_insert_term( 'Foo 2', 'wptests_tax', array(439 'slug' => 'foo',440 ) );441 442 $created_term = get_term( $created['term_id'], 'wptests_tax' );443 $this->assertSame( 'foo-2', $created_term->slug );444 445 _unregister_taxonomy( 'wptests_tax', 'post' );446 }447 448 /**449 * @ticket 5809450 */451 public function test_wp_insert_term_duplicate_slug_different_taxonomy() {452 register_taxonomy( 'wptests_tax', 'post' );453 register_taxonomy( 'wptests_tax_2', 'post' );454 $t = $this->factory->term->create( array(455 'name' => 'Foo',456 'slug' => 'foo',457 'taxonomy' => 'wptests_tax',458 ) );459 460 $term = get_term( $t, 'wptests_tax' );461 462 $created = wp_insert_term( 'Foo 2', 'wptests_tax_2', array(463 'slug' => 'foo',464 ) );465 466 $this->assertFalse( is_wp_error( $created ) );467 468 $new_term = get_term( $created['term_id'], 'wptests_tax_2' );469 470 $this->assertSame( 'foo', $new_term->slug );471 472 _unregister_taxonomy( 'wptests_tax', 'post' );473 }474 475 /**476 * @ticket 5809477 */478 public function test_wp_insert_term_duplicate_slug_different_taxonomy_before_410_schema_change() {479 480 $db_version = get_option( 'db_version' );481 update_option( 'db_version', 30055 );482 483 register_taxonomy( 'wptests_tax', 'post' );484 register_taxonomy( 'wptests_tax_2', 'post' );485 $t = $this->factory->term->create( array(486 'name' => 'Foo',487 'slug' => 'foo',488 'taxonomy' => 'wptests_tax',489 ) );490 491 $term = get_term( $t, 'wptests_tax' );492 493 $created = wp_insert_term( 'Foo 2', 'wptests_tax_2', array(494 'slug' => 'foo',495 ) );496 497 $this->assertFalse( is_wp_error( $created ) );498 499 $new_term = get_term( $created['term_id'], 'wptests_tax_2' );500 501 /*502 * As of 4.1, we no longer create a shared term, but we also do not503 * allow for duplicate slugs.504 */505 $this->assertSame( 'foo-2', $new_term->slug );506 $this->assertNotEquals( $new_term->term_id, $term->term_id );507 508 _unregister_taxonomy( 'wptests_tax', 'post' );509 update_option( 'db_version', $db_version );510 }511 512 public function test_wp_insert_term_alias_of_no_term_group() {513 register_taxonomy( 'wptests_tax', 'post' );514 $t1 = $this->factory->term->create( array(515 'taxonomy' => 'wptests_tax',516 ) );517 $term_1 = get_term( $t1, 'wptests_tax' );518 519 $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array(520 'alias_of' => $term_1->slug,521 ) );522 $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );523 524 $updated_term_1 = get_term( $term_1->term_id, 'wptests_tax' );525 526 $term = get_term( $created_term_ids['term_id'], 'wptests_tax' );527 _unregister_taxonomy( 'wptests_tax' );528 529 $this->assertSame( 0, $term_1->term_group );530 $this->assertNotEmpty( $created_term->term_group );531 $this->assertSame( $created_term->term_group, $updated_term_1->term_group );532 }533 534 public function test_wp_insert_term_alias_of_existing_term_group() {535 register_taxonomy( 'wptests_tax', 'post' );536 $t1 = $this->factory->term->create( array(537 'taxonomy' => 'wptests_tax',538 ) );539 $term_1 = get_term( $t1, 'wptests_tax' );540 541 $t2 = $this->factory->term->create( array(542 'taxonomy' => 'wptests_tax',543 'alias_of' => $term_1->slug,544 ) );545 $term_2 = get_term( $t2, 'wptests_tax' );546 547 $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array(548 'alias_of' => $term_2->slug,549 ) );550 $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );551 _unregister_taxonomy( 'wptests_tax' );552 553 $this->assertNotEmpty( $created_term->term_group );554 $this->assertSame( $created_term->term_group, $term_2->term_group );555 }556 557 public function test_wp_insert_term_alias_of_nonexistent_term() {558 register_taxonomy( 'wptests_tax', 'post' );559 $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array(560 'alias_of' => 'foo',561 ) );562 $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );563 _unregister_taxonomy( 'wptests_tax' );564 565 $this->assertSame( 0, $created_term->term_group );566 }567 568 /**569 * @ticket 5809570 */571 public function test_wp_insert_term_should_not_create_shared_term() {572 register_taxonomy( 'wptests_tax', 'post' );573 register_taxonomy( 'wptests_tax_2', 'post' );574 575 $t1 = wp_insert_term( 'Foo', 'wptests_tax' );576 $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' );577 578 $this->assertNotEquals( $t1['term_id'], $t2['term_id'] );579 }580 581 public function test_wp_insert_term_should_return_term_id_and_term_taxonomy_id() {582 register_taxonomy( 'wptests_tax', 'post' );583 $found = wp_insert_term( 'foo', 'wptests_tax' );584 585 $term_by_id = get_term( $found['term_id'], 'wptests_tax' );586 $term_by_slug = get_term_by( 'slug', 'foo', 'wptests_tax' );587 $term_by_ttid = get_term_by( 'term_taxonomy_id', $found['term_taxonomy_id'], 'wptests_tax' );588 589 _unregister_taxonomy( 'wptests_tax' );590 591 $this->assertInternalType( 'array', $found );592 $this->assertNotEmpty( $found['term_id'] );593 $this->assertNotEmpty( $found['term_taxonomy_id'] );594 $this->assertNotEmpty( $term_by_id );595 $this->assertEquals( $term_by_id, $term_by_slug );596 $this->assertEquals( $term_by_id, $term_by_ttid );597 }598 599 public function test_wp_insert_term_should_clean_term_cache() {600 register_taxonomy( 'wptests_tax', 'post', array(601 'hierarchical' => true,602 ) );603 604 $t = $this->factory->term->create( array(605 'taxonomy' => 'wptests_tax',606 ) );607 608 /**609 * It doesn't appear that WordPress itself ever sets these610 * caches, but we should ensure that they're being cleared for611 * compatibility with third-party addons. Prime the caches612 * manually.613 */614 wp_cache_set( 'all_ids', array( 1, 2, 3 ), 'wptests_tax' );615 wp_cache_set( 'get', array( 1, 2, 3 ), 'wptests_tax' );616 617 $found = wp_insert_term( 'foo', 'wptests_tax', array(618 'parent' => $t,619 ) );620 _unregister_taxonomy( 'wptests_tax' );621 622 $this->assertSame( false, wp_cache_get( 'all_ids', 'wptests_tax' ) );623 $this->assertSame( false, wp_cache_get( 'get', 'wptests_tax' ) );624 625 $cached_children = get_option( 'wptests_tax_children' );626 $this->assertNotEmpty( $cached_children[ $t ] );627 $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ] ) );628 }629 630 public function test_wp_update_term_taxonomy_does_not_exist() {631 $found = wp_update_term( 1, 'bar' );632 633 $this->assertTrue( is_wp_error( $found ) );634 $this->assertSame( 'invalid_taxonomy', $found->get_error_code() );635 }636 637 public function test_wp_update_term_term_empty_string_should_return_wp_error() {638 $found = wp_update_term( '', 'post_tag' );639 640 $this->assertTrue( is_wp_error( $found ) );641 $this->assertSame( 'invalid_term', $found->get_error_code() );642 }643 644 public function test_wp_update_term_unslash_name() {645 register_taxonomy( 'wptests_tax', 'post' );646 $t = $this->factory->term->create( array(647 'taxonomy' => 'wptests_tax',648 ) );649 650 $found = wp_update_term( $t, 'wptests_tax', array(651 'name' => 'Let\\\'s all say \\"Hooray\\" for WordPress taxonomy',652 ) );653 654 $term = get_term( $found['term_id'], 'wptests_tax' );655 _unregister_taxonomy( 'wptests_tax' );656 657 $this->assertSame( 'Let\'s all say "Hooray" for WordPress taxonomy', $term->name );658 }659 660 public function test_wp_update_term_unslash_description() {661 register_taxonomy( 'wptests_tax', 'post' );662 $t = $this->factory->term->create( array(663 'taxonomy' => 'wptests_tax',664 ) );665 666 $found = wp_update_term( $t, 'wptests_tax', array(667 'description' => 'Let\\\'s all say \\"Hooray\\" for WordPress taxonomy',668 ) );669 670 $term = get_term( $found['term_id'], 'wptests_tax' );671 _unregister_taxonomy( 'wptests_tax' );672 673 $this->assertSame( 'Let\'s all say "Hooray" for WordPress taxonomy', $term->description );674 }675 676 public function test_wp_update_term_name_empty_string() {677 register_taxonomy( 'wptests_tax', 'post' );678 $t = $this->factory->term->create( array(679 'taxonomy' => 'wptests_tax',680 ) );681 682 $found = wp_update_term( $t, 'wptests_tax', array(683 'name' => '',684 ) );685 686 $this->assertTrue( is_wp_error( $found ) );687 $this->assertSame( 'empty_term_name', $found->get_error_code() );688 _unregister_taxonomy( 'wptests_tax' );689 }690 691 /**692 * @ticket 29614693 */694 function test_wp_update_term_parent_does_not_exist() {695 register_taxonomy( 'wptests_tax', array(696 'hierarchical' => true,697 ) );698 $fake_term_id = 787878;699 700 $this->assertNull( term_exists( $fake_term_id, 'wptests_tax' ) );701 702 $t = $this->factory->term->create( array(703 'taxonomy' => 'wptests_tax',704 ) );705 706 $found = wp_update_term( $t, 'wptests_tax', array(707 'parent' => $fake_term_id,708 ) );709 710 $this->assertWPError( $found );711 $this->assertSame( 'missing_parent', $found->get_error_code() );712 713 $term = get_term( $t, 'wptests_tax' );714 $this->assertEquals( 0, $term->parent );715 _unregister_taxonomy( 'wptests_tax' );716 }717 718 public function test_wp_update_term_slug_empty_string_while_not_updating_name() {719 register_taxonomy( 'wptests_tax', 'post' );720 $t = $this->factory->term->create( array(721 'taxonomy' => 'wptests_tax',722 'name' => 'Foo Bar',723 ) );724 725 $found = wp_update_term( $t, 'wptests_tax', array(726 'slug' => '',727 ) );728 729 $term = get_term( $t, 'wptests_tax' );730 $this->assertSame( 'foo-bar', $term->slug );731 _unregister_taxonomy( 'wptests_tax' );732 }733 734 public function test_wp_update_term_slug_empty_string_while_updating_name() {735 register_taxonomy( 'wptests_tax', 'post' );736 $t = $this->factory->term->create( array(737 'taxonomy' => 'wptests_tax',738 ) );739 740 $found = wp_update_term( $t, 'wptests_tax', array(741 'name' => 'Foo Bar',742 'slug' => '',743 ) );744 745 $term = get_term( $t, 'wptests_tax' );746 $this->assertSame( 'foo-bar', $term->slug );747 _unregister_taxonomy( 'wptests_tax' );748 }749 750 public function test_wp_update_term_slug_set_slug() {751 register_taxonomy( 'wptests_tax', 'post' );752 $t = $this->factory->term->create( array(753 'taxonomy' => 'wptests_tax',754 ) );755 756 $found = wp_update_term( $t, 'wptests_tax', array(757 'slug' => 'foo-bar',758 ) );759 760 $term = get_term( $t, 'wptests_tax' );761 $this->assertSame( 'foo-bar', $term->slug );762 _unregister_taxonomy( 'wptests_tax' );763 }764 765 /**766 * @ticket 5809767 */768 public function test_wp_update_term_should_not_create_duplicate_slugs_within_the_same_taxonomy() {769 register_taxonomy( 'wptests_tax', 'post' );770 771 $t1 = $this->factory->term->create( array(772 'name' => 'Foo',773 'slug' => 'foo',774 'taxonomy' => 'wptests_tax',775 ) );776 777 $t2 = $this->factory->term->create( array(778 'name' => 'Bar',779 'slug' => 'bar',780 'taxonomy' => 'wptests_tax',781 ) );782 783 $updated = wp_update_term( $t2, 'wptests_tax', array(784 'slug' => 'foo',785 ) );786 787 $this->assertWPError( $updated );788 $this->assertSame( 'duplicate_term_slug', $updated->get_error_code() );789 }790 791 /**792 * @ticket 5809793 */794 public function test_wp_update_term_should_allow_duplicate_slugs_in_different_taxonomy() {795 register_taxonomy( 'wptests_tax', 'post' );796 register_taxonomy( 'wptests_tax_2', 'post' );797 798 $t1 = $this->factory->term->create( array(799 'name' => 'Foo',800 'slug' => 'foo',801 'taxonomy' => 'wptests_tax',802 ) );803 804 $t2 = $this->factory->term->create( array(805 'name' => 'Foo',806 'slug' => 'bar',807 'taxonomy' => 'wptests_tax_2',808 ) );809 810 $updated = wp_update_term( $t2, 'wptests_tax_2', array(811 'slug' => 'foo',812 ) );813 814 $this->assertFalse( is_wp_error( $updated ) );815 816 $t1_term = get_term( $t1, 'wptests_tax' );817 $t2_term = get_term( $t2, 'wptests_tax_2' );818 $this->assertSame( $t1_term->slug, $t2_term->slug );819 }820 821 /**822 * @ticket 30780823 */824 public function test_wp_update_term_should_allow_duplicate_names_in_different_taxonomies() {825 register_taxonomy( 'wptests_tax', 'post' );826 register_taxonomy( 'wptests_tax_2', 'post' );827 828 $t1 = $this->factory->term->create( array(829 'name' => 'Foo',830 'slug' => 'foo',831 'taxonomy' => 'wptests_tax',832 ) );833 834 $t2 = $this->factory->term->create( array(835 'name' => 'Bar',836 'slug' => 'bar',837 'taxonomy' => 'wptests_tax_2',838 ) );839 840 $updated = wp_update_term( $t2, 'wptests_tax_2', array(841 'name' => 'Foo',842 ) );843 844 $this->assertFalse( is_wp_error( $updated ) );845 846 $t2_term = get_term( $t2, 'wptests_tax_2' );847 $this->assertSame( 'Foo', $t2_term->name );848 }849 850 /**851 * @ticket 30780852 */853 public function test_wp_update_term_should_allow_duplicate_names_at_different_levels_of_the_same_taxonomy() {854 register_taxonomy( 'wptests_tax', 'post', array(855 'hierarchical' => true,856 ) );857 858 $t1 = $this->factory->term->create( array(859 'name' => 'Foo',860 'slug' => 'foo',861 'taxonomy' => 'wptests_tax',862 ) );863 864 $t2 = $this->factory->term->create( array(865 'name' => 'Bar',866 'slug' => 'bar',867 'taxonomy' => 'wptests_tax',868 'parent' => $t1,869 ) );870 871 $t3 = $this->factory->term->create( array(872 'name' => 'Bar Child',873 'slug' => 'bar-child',874 'taxonomy' => 'wptests_tax',875 'parent' => $t2,876 ) );877 878 $updated = wp_update_term( $t3, 'wptests_tax', array(879 'name' => 'Bar',880 ) );881 882 $this->assertFalse( is_wp_error( $updated ) );883 884 $t3_term = get_term( $t3, 'wptests_tax' );885 $this->assertSame( 'Bar', $t3_term->name );886 }887 888 /**889 * @ticket 5809890 */891 public function test_wp_update_term_should_split_shared_term() {892 global $wpdb;893 894 register_taxonomy( 'wptests_tax', 'post' );895 register_taxonomy( 'wptests_tax_2', 'post' );896 897 $t1 = wp_insert_term( 'Foo', 'wptests_tax' );898 $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' );899 900 // Manually modify because split terms shouldn't naturally occur.901 $wpdb->update( $wpdb->term_taxonomy,902 array( 'term_id' => $t1['term_id'] ),903 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ),904 array( '%d' ),905 array( '%d' )906 );907 908 $posts = $this->factory->post->create_many( 2 );909 wp_set_object_terms( $posts[0], array( 'Foo' ), 'wptests_tax' );910 wp_set_object_terms( $posts[1], array( 'Foo' ), 'wptests_tax_2' );911 912 // Verify that the terms are shared.913 $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );914 $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );915 $this->assertSame( $t1_terms[0]->term_id, $t2_terms[0]->term_id );916 917 wp_update_term( $t2_terms[0]->term_id, 'wptests_tax_2', array(918 'name' => 'New Foo',919 ) );920 921 $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );922 $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );923 $this->assertNotEquals( $t1_terms[0]->term_id, $t2_terms[0]->term_id );924 }925 926 /**927 * @ticket 5809928 */929 public function test_wp_update_term_should_not_split_shared_term_before_410_schema_change() {930 global $wpdb;931 932 $db_version = get_option( 'db_version' );933 update_option( 'db_version', 30055 );934 935 register_taxonomy( 'wptests_tax', 'post' );936 register_taxonomy( 'wptests_tax_2', 'post' );937 938 $t1 = wp_insert_term( 'Foo', 'wptests_tax' );939 $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' );940 941 // Manually modify because split terms shouldn't naturally occur.942 $wpdb->update( $wpdb->term_taxonomy,943 array( 'term_id' => $t1['term_id'] ),944 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ),945 array( '%d' ),946 array( '%d' )947 );948 949 $posts = $this->factory->post->create_many( 2 );950 wp_set_object_terms( $posts[0], array( 'Foo' ), 'wptests_tax' );951 wp_set_object_terms( $posts[1], array( 'Foo' ), 'wptests_tax_2' );952 953 // Verify that the term is shared.954 $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );955 $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );956 $this->assertSame( $t1_terms[0]->term_id, $t2_terms[0]->term_id );957 958 wp_update_term( $t2_terms[0]->term_id, 'wptests_tax_2', array(959 'name' => 'New Foo',960 ) );961 962 // Term should still be shared.963 $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );964 $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );965 $this->assertSame( $t1_terms[0]->term_id, $t2_terms[0]->term_id );966 967 update_option( 'db_version', $db_version );968 }969 970 public function test_wp_update_term_alias_of_no_term_group() {971 register_taxonomy( 'wptests_tax', 'post' );972 $t1 = $this->factory->term->create( array(973 'taxonomy' => 'wptests_tax',974 ) );975 $term_1 = get_term( $t1, 'wptests_tax' );976 977 $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax' );978 wp_update_term( $created_term_ids['term_id'], 'wptests_tax', array(979 'alias_of' => $term_1->slug,980 ) );981 $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );982 983 $updated_term_1 = get_term( $t1, 'wptests_tax' );984 _unregister_taxonomy( 'wptests_tax' );985 986 $this->assertSame( 0, $term_1->term_group );987 $this->assertNotEmpty( $created_term->term_group );988 $this->assertSame( $created_term->term_group, $updated_term_1->term_group );989 }990 991 public function test_wp_update_term_alias_of_existing_term_group() {992 register_taxonomy( 'wptests_tax', 'post' );993 $t1 = $this->factory->term->create( array(994 'taxonomy' => 'wptests_tax',995 ) );996 $term_1 = get_term( $t1, 'wptests_tax' );997 998 $t2 = $this->factory->term->create( array(999 'taxonomy' => 'wptests_tax',1000 'alias_of' => $term_1->slug,1001 ) );1002 $term_2 = get_term( $t2, 'wptests_tax' );1003 1004 $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax' );1005 wp_update_term( $created_term_ids['term_id'], 'wptests_tax', array(1006 'alias_of' => $term_2->slug,1007 ) );1008 $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );1009 _unregister_taxonomy( 'wptests_tax' );1010 1011 $this->assertNotEmpty( $created_term->term_group );1012 $this->assertSame( $created_term->term_group, $term_2->term_group );1013 }1014 1015 public function test_wp_update_term_alias_of_nonexistent_term() {1016 register_taxonomy( 'wptests_tax', 'post' );1017 $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax' );1018 wp_update_term( $created_term_ids['term_id'], 'wptests_tax', array(1019 'alias_of' => 'bar',1020 ) );1021 $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' );1022 _unregister_taxonomy( 'wptests_tax' );1023 1024 $this->assertSame( 0, $created_term->term_group );1025 }1026 1027 public function test_wp_update_term_slug_same_as_old_slug() {1028 register_taxonomy( 'wptests_tax', 'post' );1029 $t = $this->factory->term->create( array(1030 'taxonomy' => 'wptests_tax',1031 'slug' => 'foo',1032 ) );1033 1034 $found = wp_update_term( $t, 'wptests_tax', array(1035 'slug' => 'foo',1036 ) );1037 1038 $term = get_term( $t, 'wptests_tax' );1039 1040 $this->assertSame( $t, $found['term_id'] );1041 $this->assertSame( 'foo', $term->slug );1042 _unregister_taxonomy( 'wptests_tax' );1043 }1044 1045 public function test_wp_update_term_duplicate_slug_generated_due_to_empty_slug_param() {1046 register_taxonomy( 'wptests_tax', 'post' );1047 $t1 = $this->factory->term->create( array(1048 'taxonomy' => 'wptests_tax',1049 'slug' => 'foo-bar',1050 ) );1051 $t2 = $this->factory->term->create( array(1052 'taxonomy' => 'wptests_tax',1053 'name' => 'not foo bar',1054 ) );1055 1056 $found = wp_update_term( $t2, 'wptests_tax', array(1057 'slug' => '',1058 'name' => 'Foo? Bar!', // Will sanitize to 'foo-bar'.1059 ) );1060 1061 $term = get_term( $t2, 'wptests_tax' );1062 1063 $this->assertSame( $t2, $found['term_id'] );1064 $this->assertSame( 'foo-bar-2', $term->slug );1065 _unregister_taxonomy( 'wptests_tax' );1066 }1067 1068 public function test_wp_update_term_duplicate_slug_with_changed_parent() {1069 register_taxonomy( 'wptests_tax', 'post', array(1070 'hierarchical' => true,1071 ) );1072 $p = $this->factory->term->create( array(1073 'taxonomy' => 'wptests_tax',1074 ) );1075 $t1 = $this->factory->term->create( array(1076 'taxonomy' => 'wptests_tax',1077 'slug' => 'foo-bar',1078 ) );1079 $t2 = $this->factory->term->create( array(1080 'taxonomy' => 'wptests_tax',1081 ) );1082 1083 $found = wp_update_term( $t2, 'wptests_tax', array(1084 'parent' => $p,1085 'slug' => 'foo-bar',1086 ) );1087 1088 $term = get_term( $t2, 'wptests_tax' );1089 $parent_term = get_term( $p, 'wptests_tax' );1090 1091 $this->assertSame( $t2, $found['term_id'] );1092 $this->assertSame( 'foo-bar-' . $parent_term->slug, $term->slug );1093 _unregister_taxonomy( 'wptests_tax' );1094 }1095 1096 public function test_wp_update_term_duplicate_slug_failure() {1097 register_taxonomy( 'wptests_tax', 'post' );1098 $t1 = $this->factory->term->create( array(1099 'taxonomy' => 'wptests_tax',1100 'slug' => 'foo-bar',1101 ) );1102 $t2 = $this->factory->term->create( array(1103 'taxonomy' => 'wptests_tax',1104 'slug' => 'my-old-slug',1105 ) );1106 1107 $found = wp_update_term( $t2, 'wptests_tax', array(1108 'slug' => 'foo-bar',1109 ) );1110 1111 $term = get_term( $t2, 'wptests_tax' );1112 1113 $this->assertWPError( $found );1114 $this->assertSame( 'duplicate_term_slug', $found->get_error_code() );1115 $this->assertSame( 'my-old-slug', $term->slug );1116 _unregister_taxonomy( 'wptests_tax' );1117 }1118 1119 public function test_wp_update_term_should_return_term_id_and_term_taxonomy_id() {1120 register_taxonomy( 'wptests_tax', 'post' );1121 $t = $this->factory->term->create( array(1122 'taxonomy' => 'wptests_tax',1123 ) );1124 $found = wp_update_term( $t, 'wptests_tax', array(1125 'slug' => 'foo',1126 ) );1127 1128 $term_by_id = get_term( $found['term_id'], 'wptests_tax' );1129 $term_by_slug = get_term_by( 'slug', 'foo', 'wptests_tax' );1130 $term_by_ttid = get_term_by( 'term_taxonomy_id', $found['term_taxonomy_id'], 'wptests_tax' );1131 1132 _unregister_taxonomy( 'wptests_tax' );1133 1134 $this->assertInternalType( 'array', $found );1135 $this->assertNotEmpty( $found['term_id'] );1136 $this->assertNotEmpty( $found['term_taxonomy_id'] );1137 $this->assertNotEmpty( $term_by_id );1138 $this->assertEquals( $term_by_id, $term_by_slug );1139 $this->assertEquals( $term_by_id, $term_by_ttid );1140 }1141 1142 public function test_wp_update_term_should_clean_object_term_cache() {1143 register_taxonomy( 'wptests_tax_for_post', 'post' );1144 register_taxonomy( 'wptests_tax_for_page', 'page' );1145 $post = $this->factory->post->create();1146 $page = $this->factory->post->create( array(1147 'post_type' => 'page',1148 ) );1149 1150 $t_for_post = $this->factory->term->create( array(1151 'taxonomy' => 'wptests_tax_for_post',1152 ) );1153 $t_for_page = $this->factory->term->create( array(1154 'taxonomy' => 'wptests_tax_for_page',1155 ) );1156 1157 wp_set_post_terms( $post, array( $t_for_post ), 'wptests_tax_for_post' );1158 wp_set_post_terms( $page, array( $t_for_page ), 'wptests_tax_for_page' );1159 1160 // Prime caches and verify.1161 update_object_term_cache( array( $post ), 'post' );1162 update_object_term_cache( array( $page ), 'page' );1163 $this->assertNotEmpty( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );1164 $this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );1165 1166 // Update a term in just one of the taxonomies.1167 $found = wp_update_term( $t_for_post, 'wptests_tax_for_post', array(1168 'slug' => 'foo',1169 ) );1170 1171 // Only the relevant cache should have been cleared.1172 $this->assertFalse( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );1173 $this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );1174 }1175 1176 public function test_wp_update_term_should_clean_term_cache() {1177 register_taxonomy( 'wptests_tax', 'post', array(1178 'hierarchical' => true,1179 ) );1180 1181 $t1 = $this->factory->term->create( array(1182 'taxonomy' => 'wptests_tax',1183 ) );1184 $t2 = $this->factory->term->create( array(1185 'taxonomy' => 'wptests_tax',1186 ) );1187 1188 /*1189 * It doesn't appear that WordPress itself ever sets these1190 * caches, but we should ensure that they're being cleared for1191 * compatibility with third-party addons. Prime the caches1192 * manually.1193 */1194 wp_cache_set( 'all_ids', array( 1, 2, 3 ), 'wptests_tax' );1195 wp_cache_set( 'get', array( 1, 2, 3 ), 'wptests_tax' );1196 1197 $found = wp_update_term( $t1, 'wptests_tax', array(1198 'parent' => $t2,1199 ) );1200 _unregister_taxonomy( 'wptests_tax' );1201 1202 $this->assertSame( false, wp_cache_get( 'all_ids', 'wptests_tax' ) );1203 $this->assertSame( false, wp_cache_get( 'get', 'wptests_tax' ) );1204 1205 $cached_children = get_option( 'wptests_tax_children' );1206 $this->assertNotEmpty( $cached_children[ $t2 ] );1207 $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t2 ] ) );1208 }1209 8 1210 9 /** … … 1832 631 $this->assertWPError( $cat_id2 ); 1833 632 } 1834 1835 /**1836 * @ticket 307801837 */1838 public function test_wp_update_term_should_assign_new_slug_when_reassigning_parent_as_long_as_there_is_no_other_term_with_the_same_slug() {1839 register_taxonomy( 'wptests_tax', 'post', array(1840 'hierarchical' => true,1841 ) );1842 register_taxonomy( 'wptests_tax_2', 'post', array(1843 'hierarchical' => true,1844 ) );1845 1846 $t1 = $this->factory->term->create( array(1847 'taxonomy' => 'wptests_tax',1848 'slug' => 'parent-term',1849 ) );1850 1851 $t2 = $this->factory->term->create( array(1852 'taxonomy' => 'wptests_tax',1853 'slug' => 'foo',1854 ) );1855 1856 wp_update_term( $t2, 'wptests_tax', array(1857 'parent' => $t1,1858 ) );1859 1860 $t2_term = get_term( $t2, 'wptests_tax' );1861 1862 $this->assertSame( 'foo', $t2_term->slug );1863 1864 _unregister_taxonomy( 'wptests_tax' );1865 }1866 1867 /**1868 * @ticket 307801869 */1870 public function test_wp_update_term_should_not_assign_new_slug_when_reassigning_parent_as_long_as_there_is_no_other_slug_conflict_within_the_taxonomy() {1871 register_taxonomy( 'wptests_tax', 'post', array(1872 'hierarchical' => true,1873 ) );1874 register_taxonomy( 'wptests_tax_2', 'post', array(1875 'hierarchical' => true,1876 ) );1877 1878 $t1 = $this->factory->term->create( array(1879 'taxonomy' => 'wptests_tax',1880 'slug' => 'parent-term',1881 ) );1882 1883 // Same slug but in a different tax.1884 $t2 = $this->factory->term->create( array(1885 'taxonomy' => 'wptests_tax_2',1886 'slug' => 'foo',1887 ) );1888 1889 $t3 = $this->factory->term->create( array(1890 'taxonomy' => 'wptests_tax',1891 'slug' => 'foo',1892 ) );1893 1894 wp_update_term( $t3, 'wptests_tax', array(1895 'parent' => $t1,1896 ) );1897 1898 $t3_term = get_term( $t3, 'wptests_tax' );1899 1900 $this->assertSame( 'foo', $t3_term->slug );1901 1902 _unregister_taxonomy( 'wptests_tax' );1903 }1904 1905 /** Helpers **********************************************************/1906 1907 public function _pre_insert_term_callback() {1908 return new WP_Error( 'custom_error' );1909 }1910 633 }
Note: See TracChangeset
for help on using the changeset viewer.