Changeset 42343 for trunk/tests/phpunit/tests/term/getTheTerms.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/getTheTerms.php
r40353 r42343 5 5 */ 6 6 class Tests_Term_GetTheTerms extends WP_UnitTestCase { 7 protected $taxonomy = 'category';7 protected $taxonomy = 'category'; 8 8 protected static $post_ids = array(); 9 9 … … 18 18 $post_id = self::$post_ids[0]; 19 19 20 $terms_1 = array( 'foo', 'bar', 'baz');21 $terms_2 = array( 'bar', 'bing');20 $terms_1 = array( 'foo', 'bar', 'baz' ); 21 $terms_2 = array( 'bar', 'bing' ); 22 22 23 23 // Cache should be empty after a set. 24 24 $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); 25 $this->assertEquals( 3, count( $tt_1) );26 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) );25 $this->assertEquals( 3, count( $tt_1 ) ); 26 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) ); 27 27 28 28 // wp_get_object_terms() does not prime the cache. 29 wp_get_object_terms( $post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id') ); 30 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') ); 29 wp_get_object_terms( 30 $post_id, $this->taxonomy, array( 31 'fields' => 'names', 32 'orderby' => 't.term_id', 33 ) 34 ); 35 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) ); 31 36 32 37 // get_the_terms() does prime the cache. 33 38 $terms = get_the_terms( $post_id, $this->taxonomy ); 34 $cache = wp_cache_get( $post_id, $this->taxonomy . '_relationships' );39 $cache = wp_cache_get( $post_id, $this->taxonomy . '_relationships' ); 35 40 $this->assertInternalType( 'array', $cache ); 36 41 37 42 // Cache should be empty after a set. 38 43 $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); 39 $this->assertEquals( 2, count( $tt_2) );40 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) );44 $this->assertEquals( 2, count( $tt_2 ) ); 45 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) ); 41 46 } 42 47 … … 46 51 function test_object_term_cache_when_term_changes() { 47 52 $post_id = self::$post_ids[0]; 48 $tag_id = self::factory()->tag->create( array( 49 'name' => 'Amaze Tag', 50 'description' => 'My Amazing Tag' 51 ) ); 53 $tag_id = self::factory()->tag->create( 54 array( 55 'name' => 'Amaze Tag', 56 'description' => 'My Amazing Tag', 57 ) 58 ); 52 59 53 60 $tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' ); … … 57 64 $this->assertEquals( 'My Amazing Tag', $terms[0]->description ); 58 65 59 $_updated = wp_update_term( $tag_id, 'post_tag', array( 60 'description' => 'This description is even more amazing!' 61 ) ); 66 $_updated = wp_update_term( 67 $tag_id, 'post_tag', array( 68 'description' => 'This description is even more amazing!', 69 ) 70 ); 62 71 63 72 $_new_term = get_term( $tag_id, 'post_tag' ); … … 126 135 $p = self::$post_ids[0]; 127 136 128 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'fff' ) ); 129 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'aaa' ) ); 130 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'zzz' ) ); 137 $t1 = self::factory()->term->create( 138 array( 139 'taxonomy' => 'wptests_tax', 140 'name' => 'fff', 141 ) 142 ); 143 $t2 = self::factory()->term->create( 144 array( 145 'taxonomy' => 'wptests_tax', 146 'name' => 'aaa', 147 ) 148 ); 149 $t3 = self::factory()->term->create( 150 array( 151 'taxonomy' => 'wptests_tax', 152 'name' => 'zzz', 153 ) 154 ); 131 155 132 156 wp_set_object_terms( $p, array( $t1, $t2, $t3 ), 'wptests_tax' ); … … 142 166 */ 143 167 function test_get_the_terms_should_return_wp_error_when_taxonomy_is_unregistered() { 144 $p = self::$post_ids[0];168 $p = self::$post_ids[0]; 145 169 $terms = get_the_terms( $p, 'this-taxonomy-does-not-exist' ); 146 170 $this->assertWPError( $terms ); … … 184 208 185 209 $num_queries = $wpdb->num_queries; 186 $found = get_the_terms( self::$post_ids[0], 'wptests_tax' );210 $found = get_the_terms( self::$post_ids[0], 'wptests_tax' ); 187 211 188 212 $this->assertEqualSets( $terms, wp_list_pluck( $found, 'term_id' ) ); … … 203 227 204 228 // Create Test Category. 205 $term_id = self::factory()->term->create( array( 206 'taxonomy' => 'wptests_tax', 207 ) ); 229 $term_id = self::factory()->term->create( 230 array( 231 'taxonomy' => 'wptests_tax', 232 ) 233 ); 208 234 209 235 $post_id = self::factory()->post->create(); … … 230 256 231 257 // Create Test Category. 232 $term_ids = self::factory()->term->create_many( 2, array( 233 'taxonomy' => 'wptests_tax', 234 ) ); 258 $term_ids = self::factory()->term->create_many( 259 2, array( 260 'taxonomy' => 'wptests_tax', 261 ) 262 ); 235 263 236 264 $post_id = self::factory()->post->create();
Note: See TracChangeset
for help on using the changeset viewer.