Make WordPress Core


Ignore:
Timestamp:
01/17/2015 08:08:04 PM (10 years ago)
Author:
boonebgorges
Message:

Move wp_get_object_terms() tests into their own file.

See #26999.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term.php

    r30985 r31230  
    10631063
    10641064    /**
    1065      * @ticket 26339
    1066      */
    1067     function test_get_object_terms() {
    1068         $post_id = $this->factory->post->create();
    1069         $terms_1 = array('foo', 'bar', 'baz');
    1070 
    1071         wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
    1072         add_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) );
    1073         $terms = wp_get_object_terms( $post_id, $this->taxonomy );
    1074         remove_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) );
    1075         foreach ( $terms as $term ) {
    1076             $this->assertInternalType( 'object', $term );
    1077         }
    1078     }
    1079 
    1080     function filter_get_object_terms( $terms ) {
    1081         $term_ids = wp_list_pluck( $terms, 'term_id' );
    1082         // all terms should still be objects
    1083         return $terms;
    1084     }
    1085 
    1086     function test_get_object_terms_by_slug() {
    1087         $post_id = $this->factory->post->create();
    1088 
    1089         $terms_1 = array('Foo', 'Bar', 'Baz');
    1090         $terms_1_slugs = array('foo', 'bar', 'baz');
    1091 
    1092         // set the initial terms
    1093         $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
    1094         $this->assertEquals( 3, count($tt_1) );
    1095 
    1096         // make sure they're correct
    1097         $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 't.term_id'));
    1098         $this->assertEquals( $terms_1_slugs, $terms );
    1099     }
    1100 
    1101     /**
    1102      * @ticket 11003
    1103      */
    1104     function test_wp_get_object_terms_no_dupes() {
    1105         $post_id1 = $this->factory->post->create();
    1106         $post_id2 = $this->factory->post->create();
    1107         $cat_id = $this->factory->category->create();
    1108         $cat_id2 = $this->factory->category->create();
    1109         wp_set_post_categories( $post_id1, array( $cat_id, $cat_id2 ) );
    1110         wp_set_post_categories( $post_id2, $cat_id );
    1111 
    1112         $terms = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category' );
    1113         $this->assertCount( 2, $terms );
    1114         $this->assertEquals( array( $cat_id, $cat_id2 ), wp_list_pluck( $terms, 'term_id' ) );
    1115 
    1116         $terms2 = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category', array(
    1117             'fields' => 'all_with_object_id'
    1118         ) );
    1119 
    1120         $this->assertCount( 3, $terms2 );
    1121         $this->assertEquals( array( $cat_id, $cat_id, $cat_id2 ), wp_list_pluck( $terms2, 'term_id' ) );
    1122     }
    1123 
    1124     /**
    1125      * @ticket 17646
    1126      */
    1127     function test_get_object_terms_types() {
    1128         $post_id = $this->factory->post->create();
    1129         $term = wp_insert_term( 'one', $this->taxonomy );
    1130         wp_set_object_terms( $post_id, $term, $this->taxonomy );
    1131 
    1132         $terms = wp_get_object_terms( $post_id, $this->taxonomy, array( 'fields' => 'all_with_object_id' ) );
    1133         $term = array_shift( $terms );
    1134         $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' );
    1135         foreach ( $int_fields as $field )
    1136             $this->assertInternalType( 'int', $term->$field, $field );
    1137 
    1138         $terms = wp_get_object_terms( $post_id, $this->taxonomy, array( 'fields' => 'ids' ) );
    1139         $term = array_shift( $terms );
    1140         $this->assertInternalType( 'int', $term, 'term' );
    1141     }
    1142 
    1143     /**
    11441065     * @ticket 26570
    11451066     */
Note: See TracChangeset for help on using the changeset viewer.