Changeset 47343 for branches/3.7/tests/phpunit/tests/term.php
- Timestamp:
- 02/22/2020 12:05:12 PM (6 years ago)
- Location:
- branches/3.7
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tests/phpunit/tests/term.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.7
- Property svn:mergeinfo changed
-
branches/3.7/tests/phpunit/tests/term.php
r25551 r47343 388 388 } 389 389 390 /**391 * @ticket 5809392 */393 function test_update_shared_term() {394 $random_tax = __FUNCTION__;395 396 register_taxonomy( $random_tax, 'post' );397 398 $post_id = $this->factory->post->create();399 400 $old_name = 'Initial';401 402 $t1 = wp_insert_term( $old_name, 'category' );403 $t2 = wp_insert_term( $old_name, 'post_tag' );404 405 $this->assertEquals( $t1['term_id'], $t2['term_id'] );406 407 wp_set_post_categories( $post_id, array( $t1['term_id'] ) );408 wp_set_post_tags( $post_id, array( (int) $t2['term_id'] ) );409 410 $new_name = 'Updated';411 412 // create the term in a third taxonomy, just to keep things interesting413 $t3 = wp_insert_term( $old_name, $random_tax );414 wp_set_post_terms( $post_id, array( (int) $t3['term_id'] ), $random_tax );415 $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );416 417 $t2_updated = wp_update_term( $t2['term_id'], 'post_tag', array(418 'name' => $new_name419 ) );420 421 $this->assertNotEquals( $t2_updated['term_id'], $t3['term_id'] );422 423 // make sure the terms have split424 $this->assertEquals( $old_name, get_term_field( 'name', $t1['term_id'], 'category' ) );425 $this->assertEquals( $new_name, get_term_field( 'name', $t2_updated['term_id'], 'post_tag' ) );426 427 // and that they are still assigned to the correct post428 $this->assertPostHasTerms( $post_id, array( $t1['term_id'] ), 'category' );429 $this->assertPostHasTerms( $post_id, array( $t2_updated['term_id'] ), 'post_tag' );430 $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax );431 432 // clean up433 unset( $GLOBALS['wp_taxonomies'][ $random_tax ] );434 }435 436 390 private function assertPostHasTerms( $post_id, $expected_term_ids, $taxonomy ) { 437 391 $assigned_term_ids = wp_get_object_terms( $post_id, $taxonomy, array( … … 440 394 441 395 $this->assertEquals( $expected_term_ids, $assigned_term_ids ); 442 }443 444 /**445 * @ticket 24189446 */447 function test_object_term_cache_when_term_changes() {448 $post_id = $this->factory->post->create();449 $tag_id = $this->factory->tag->create( array( 'description' => 'My Amazing Tag' ) );450 451 $tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' );452 453 $terms = get_the_terms( $post_id, 'post_tag' );454 $this->assertEquals( $tag_id, $terms[0]->term_id );455 $this->assertEquals( 'My Amazing Tag', $terms[0]->description );456 457 $_updated = wp_update_term( $tag_id, 'post_tag', array(458 'description' => 'This description is even more amazing!'459 ) );460 461 $_new_term = get_term( $tag_id, 'post_tag' );462 $this->assertEquals( $tag_id, $_new_term->term_id );463 $this->assertEquals( 'This description is even more amazing!', $_new_term->description );464 465 $terms = get_the_terms( $post_id, 'post_tag' );466 $this->assertEquals( $tag_id, $terms[0]->term_id );467 $this->assertEquals( 'This description is even more amazing!', $terms[0]->description );468 396 } 469 397
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)