Changeset 35185
- Timestamp:
- 10/15/2015 03:47:36 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term.php
r35032 r35185 5 5 */ 6 6 class Tests_Term extends WP_UnitTestCase { 7 var $taxonomy = 'category'; 7 protected $taxonomy = 'category'; 8 protected static $post_ids = array(); 9 10 public static function setUpBeforeClass() { 11 parent::setUpBeforeClass(); 12 13 $factory = new WP_UnitTest_Factory(); 14 15 self::$post_ids = $factory->post->create_many( 5 ); 16 17 self::commit_transaction(); 18 } 19 20 public static function tearDownAfterClass() { 21 parent::tearDownAfterClass(); 22 23 array_map( 'wp_delete_post', self::$post_ids ); 24 25 self::commit_transaction(); 26 } 8 27 9 28 /** … … 54 73 function test_wp_count_terms() { 55 74 $count = wp_count_terms( 'category', array( 'hide_empty' => true ) ); 56 // the terms inserted in setUp aren't attached to any posts, so should return 0 57 // this previously returned 2 58 $this->assertEquals( 0, $count ); 75 // there are 5 posts, all Uncategorized 76 $this->assertEquals( 1, $count ); 59 77 } 60 78 … … 71 89 72 90 // Create a post. 73 $post_id = $this->factory->post->create();91 $post_id = self::$post_ids[0]; 74 92 75 93 /* … … 148 166 149 167 function test_set_object_terms_by_id() { 150 $ids = $this->factory->post->create_many(5);168 $ids = self::$post_ids; 151 169 152 170 $terms = array(); … … 159 177 160 178 foreach ($ids as $id) { 161 162 163 179 $tt = wp_set_object_terms( $id, array_values($term_id), $this->taxonomy ); 180 // should return three term taxonomy ids 181 $this->assertEquals( 3, count($tt) ); 164 182 } 165 183 … … 178 196 179 197 function test_set_object_terms_by_name() { 180 $ids = $this->factory->post->create_many(5);198 $ids = self::$post_ids; 181 199 182 200 $terms = array( 183 rand_str(), 184 rand_str(), 185 rand_str()); 201 rand_str(), 202 rand_str(), 203 rand_str() 204 ); 186 205 187 206 foreach ($ids as $id) { 188 189 190 191 192 193 194 195 207 $tt = wp_set_object_terms( $id, $terms, $this->taxonomy ); 208 // should return three term taxonomy ids 209 $this->assertEquals( 3, count($tt) ); 210 // remember which term has which term_id 211 for ($i=0; $i<3; $i++) { 212 $term = get_term_by('name', $terms[$i], $this->taxonomy); 213 $term_id[$terms[$i]] = intval($term->term_id); 214 } 196 215 } 197 216 … … 210 229 211 230 function test_set_object_terms_invalid() { 212 $post_id = $this->factory->post->create();213 214 231 // bogus taxonomy 215 $result = wp_set_object_terms( $post_id, array(rand_str()), rand_str() );232 $result = wp_set_object_terms( self::$post_ids[0], array(rand_str()), rand_str() ); 216 233 $this->assertTrue( is_wp_error($result) ); 217 234 } … … 219 236 public function test_wp_set_object_terms_append_true() { 220 237 register_taxonomy( 'wptests_tax', 'post' ); 221 $p = $this->factory->post->create();238 $p = self::$post_ids[0]; 222 239 $t1 = $this->factory->term->create( array( 223 240 'taxonomy' => 'wptests_tax', … … 240 257 public function test_wp_set_object_terms_append_false() { 241 258 register_taxonomy( 'wptests_tax', 'post' ); 242 $p = $this->factory->post->create();259 $p = self::$post_ids[0]; 243 260 $t1 = $this->factory->term->create( array( 244 261 'taxonomy' => 'wptests_tax', … … 261 278 public function test_wp_set_object_terms_append_default_to_false() { 262 279 register_taxonomy( 'wptests_tax', 'post' ); 263 $p = $this->factory->post->create();280 $p = self::$post_ids[0]; 264 281 $t1 = $this->factory->term->create( array( 265 282 'taxonomy' => 'wptests_tax', … … 283 300 // set some terms on an object; then change them while leaving one intact 284 301 285 $post_id = $this->factory->post->create();302 $post_id = self::$post_ids[0]; 286 303 287 304 // first set: 3 terms … … 327 344 // set some terms on an object; then change them while leaving one intact 328 345 329 $post_id = $this->factory->post->create();346 $post_id = self::$post_ids[0]; 330 347 331 348 $terms_1 = array('foo', 'bar', 'baz'); … … 357 374 */ 358 375 function test_wp_add_remove_object_terms() { 359 $posts = $this->factory->post->create_many( 5 );376 $posts = self::$post_ids; 360 377 $tags = $this->factory->tag->create_many( 5 ); 361 378 … … 431 448 */ 432 449 function test_wp_set_post_categories() { 433 $post_id = $this->factory->post->create();450 $post_id = self::$post_ids[0]; 434 451 $post = get_post( $post_id ); 435 452 … … 487 504 */ 488 505 function test_object_term_cache() { 489 $post_id = $this->factory->post->create();506 $post_id = self::$post_ids[0]; 490 507 491 508 $terms_1 = array('foo', 'bar', 'baz'); … … 516 533 */ 517 534 function test_object_term_cache_when_term_changes() { 518 $post_id = $this->factory->post->create(); 519 $tag_id = $this->factory->tag->create( array( 'description' => 'My Amazing Tag' ) ); 535 $post_id = self::$post_ids[0]; 536 $tag_id = $this->factory->tag->create( array( 537 'name' => 'Amaze Tag', 538 'description' => 'My Amazing Tag' 539 ) ); 520 540 521 541 $tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' ); … … 542 562 */ 543 563 public function test_get_the_terms_should_not_cache_wp_term_objects() { 544 $p = $this->factory->post->create();564 $p = self::$post_ids[0]; 545 565 register_taxonomy( 'wptests_tax', 'post' ); 546 566 $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) ); … … 561 581 */ 562 582 public function test_get_the_terms_should_return_wp_term_objects_from_cache() { 563 $p = $this->factory->post->create();583 $p = self::$post_ids[0]; 564 584 register_taxonomy( 'wptests_tax', 'post' ); 565 585 $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) ); … … 581 601 public function test_get_the_terms_should_return_zero_indexed_array_when_cache_is_empty() { 582 602 register_taxonomy( 'wptests_tax', 'post' ); 583 $p = $this->factory->post->create();603 $p = self::$post_ids[0]; 584 604 wp_set_object_terms( $p, array( 'foo', 'bar' ), 'wptests_tax' ); 585 605 … … 594 614 public function test_get_the_terms_should_return_zero_indexed_array_when_cache_is_primed() { 595 615 register_taxonomy( 'wptests_tax', 'post' ); 596 $p = $this->factory->post->create();616 $p = self::$post_ids[0]; 597 617 wp_set_object_terms( $p, array( 'foo', 'bar' ), 'wptests_tax' ); 598 618
Note: See TracChangeset
for help on using the changeset viewer.