WordPress.org

Make WordPress Core

Changeset 1048 in tests


Ignore:
Timestamp:
09/26/12 22:57:32 (19 months ago)
Author:
scribu
Message:

add a third taxonomy when testing #WP5809

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/term.php

    r1042 r1048  
    325325     */ 
    326326    function test_update_shared_term() { 
    327         $post_id = $this->factory->post->create(); 
    328  
    329         $term_1 = 'Initial'; 
    330  
    331         $t1 = wp_insert_term( $term_1, 'category' ); 
    332         $t2 = wp_insert_term( $term_1, 'post_tag' ); 
     327        $random_tax = __FUNCTION__; 
     328 
     329        register_taxonomy( $random_tax, 'post' ); 
     330 
     331        $post_id = $this->factory->post->create(); 
     332 
     333        $old_name = 'Initial'; 
     334 
     335        $t1 = wp_insert_term( $old_name, 'category' ); 
     336        $t2 = wp_insert_term( $old_name, 'post_tag' ); 
    333337 
    334338        $this->assertEquals( $t1['term_id'], $t2['term_id'] ); 
     
    337341        wp_set_post_tags( $post_id, array( (int) $t2['term_id'] ) ); 
    338342 
    339         $term_2 = 'Updated'; 
     343        $new_name = 'Updated'; 
     344 
     345        // create the term in a third taxonomy, just to keep things interesting 
     346        $t3 = wp_insert_term( $old_name, $random_tax ); 
     347        wp_set_post_terms( $post_id, array( (int) $t3['term_id'] ), $random_tax ); 
     348        $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax ); 
     349 
    340350        $t2_updated = wp_update_term( $t2['term_id'], 'post_tag', array( 
    341             'name' => $term_2 
     351            'name' => $new_name 
    342352        ) ); 
    343353 
     354        $this->assertNotEquals( $t2_updated['term_id'], $t3['term_id'] ); 
     355 
    344356        // make sure the terms have split 
    345         $this->assertEquals( $term_1, get_term_field( 'name', $t1['term_id'], 'category' ) ); 
    346         $this->assertEquals( $term_2, get_term_field( 'name', $t2_updated['term_id'], 'post_tag' ) ); 
    347  
    348         // and that they are assigned to the correct post 
     357        $this->assertEquals( $old_name, get_term_field( 'name', $t1['term_id'], 'category' ) ); 
     358        $this->assertEquals( $new_name, get_term_field( 'name', $t2_updated['term_id'], 'post_tag' ) ); 
     359 
     360        // and that they are still assigned to the correct post 
    349361        $this->assertPostHasTerms( $post_id, array( $t1['term_id'] ), 'category' ); 
    350362        $this->assertPostHasTerms( $post_id, array( $t2_updated['term_id'] ), 'post_tag' ); 
     363        $this->assertPostHasTerms( $post_id, array( $t3['term_id'] ), $random_tax ); 
     364 
     365        // clean up 
     366        unset( $GLOBALS['wp_taxonomies'][ $random_tax ] ); 
    351367    } 
    352368 
Note: See TracChangeset for help on using the changeset viewer.