Make WordPress Core

Changeset 1227 in tests


Ignore:
Timestamp:
03/01/2013 04:08:52 PM (12 years ago)
Author:
SergeyBiryukov
Message:

Tests for wp_add_object_terms() and wp_remove_object_terms(). props kovshenin. see #15475.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/term.php

    r1158 r1227  
    271271        $result = wp_set_object_terms( $post_id, array(rand_str()), rand_str() );
    272272        $this->assertTrue( is_wp_error($result) );
     273    }
     274
     275    /**
     276     * @ticket 15475
     277     */
     278    function test_wp_add_remove_object_terms() {
     279        $posts = $this->factory->post->create_many( 5 );
     280        $tags = $this->factory->tag->create_many( 5 );
     281
     282        $tt = wp_add_object_terms( $posts[0], $tags[1], 'post_tag' );
     283        $this->assertEquals( 1, count( $tt ) );
     284        $this->assertEquals( array( $tags[1] ), wp_get_object_terms( $posts[0], 'post_tag', array( 'fields' => 'ids' ) ) );
     285
     286        $three_tags = array( $tags[0], $tags[1], $tags[2] );
     287        $tt = wp_add_object_terms( $posts[1], $three_tags, 'post_tag' );
     288        $this->assertEquals( 3, count( $tt ) );
     289        $this->assertEquals( $three_tags, wp_get_object_terms( $posts[1], 'post_tag', array( 'fields' => 'ids' ) ) );
     290
     291        $this->assertTrue( wp_remove_object_terms( $posts[0], $tags[1], 'post_tag' ) );
     292        $this->assertFalse( wp_remove_object_terms( $posts[0], $tags[0], 'post_tag' ) );
     293        $this->assertInstanceOf( 'WP_Error', wp_remove_object_terms( $posts[0], $tags[1], 'non_existing_taxonomy' ) );
     294        $this->assertTrue( wp_remove_object_terms( $posts[1], $three_tags, 'post_tag' ) );
     295        $this->assertEquals( 0, count( wp_get_object_terms( $posts[1], 'post_tag' ) ) );
     296
     297        foreach ( $tags as $term_id )
     298            $this->assertTrue( wp_delete_term( $term_id, 'post_tag' ) );
     299
     300        foreach ( $posts as $post_id )
     301            $this->assertTrue( (bool) wp_delete_post( $post_id, true ) );
    273302    }
    274303
Note: See TracChangeset for help on using the changeset viewer.