Make WordPress Core

Ticket #32946: 32946.2.diff

File 32946.2.diff, 1.9 KB (added by rodrigosprimo, 10 years ago)
  • tests/phpunit/tests/taxonomy.php

    diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php
    index 440df6a..8db5bfe 100644
    a b class Tests_Taxonomy extends WP_UnitTestCase { 
    251251                $this->assertEqualSets( $expected, $tax->object_type );
    252252        }
    253253
     254        public function test_get_objects_in_term_should_return_invalid_taxonomy_error() {
     255                $terms = get_objects_in_term( 1, 'invalid_taxonomy' );
     256                $this->assertInstanceOf( 'WP_Error', $terms );
     257                $this->assertEquals( 'Invalid taxonomy', $terms->get_error_message() );
     258        }
     259
     260        public function test_get_objects_in_term_should_return_empty_array() {
     261                $this->assertEquals( array(), get_objects_in_term( 1, 'post_tag' ) );
     262        }
     263
     264        public function test_get_objects_in_term_should_return_objects_ids() {
     265                $tag_id = $this->factory->tag->create();
     266                $cat_id = $this->factory->category->create();
     267                $posts_with_tag = array();
     268                $posts_with_category = array();
     269
     270                for ( $i = 0; $i < 3; $i++ ) {
     271                        $post_id = $this->factory->post->create();
     272                        wp_set_post_tags( $post_id, array( $tag_id ) );
     273                        $posts_with_tag[] = $post_id;
     274                }
     275
     276                for ( $i = 0; $i < 3; $i++ ) {
     277                        $post_id = $this->factory->post->create();
     278                        wp_set_post_categories( $post_id, array( $cat_id ) );
     279                        $posts_with_category[] = $post_id;
     280                }
     281
     282                for ( $i = 0; $i < 3; $i++ ) {
     283                        $this->factory->post->create();
     284                }
     285
     286                $posts_with_terms = array_merge( $posts_with_tag, $posts_with_category );
     287
     288                $this->assertEquals( $posts_with_tag, get_objects_in_term( $tag_id, 'post_tag' ) );
     289                $this->assertEquals( $posts_with_category, get_objects_in_term( $cat_id, 'category' ) );
     290                $this->assertEquals( $posts_with_terms, get_objects_in_term( array( $tag_id, $cat_id ), array( 'post_tag', 'category' ) ) );
     291                $this->assertEquals( array_reverse( $posts_with_tag ), get_objects_in_term( $tag_id, 'post_tag', array( 'order' => 'desc' ) ) );
     292        }
     293
    254294        /**
    255295         * @ticket 25706
    256296         */