Make WordPress Core

Ticket #15475: 15475.tests.diff

File 15475.tests.diff, 1.6 KB (added by kovshenin, 12 years ago)
  • tests/term.php

     
    272272                $this->assertTrue( is_wp_error($result) );
    273273        }
    274274
     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->assertTrue( wp_remove_object_terms( $posts[0], $tags[1], 'non_existing_taxonomy' ) instanceof WP_Error );
     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 ) );
     302        }
     303
    275304        function test_term_is_ancestor_of( ) {
    276305                $term = rand_str();
    277306                $term2 = rand_str();