Changeset 37647
- Timestamp:
- 06/06/2016 09:34:22 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/wpSetObjectTerms.php
r37644 r37647 310 310 311 311 } 312 313 public function test_should_create_term_that_does_not_exist() { 314 register_taxonomy( 'wptests_tax', 'post' ); 315 316 $this->assertFalse( get_term_by( 'slug', 'foo', 'wptests_tax' ) ); 317 318 $tt_ids = wp_set_object_terms( self::$post_ids[0], 'foo', 'wptests_tax' ); 319 320 $this->assertNotEmpty( $tt_ids ); 321 $term = get_term( $tt_ids[0] ); 322 $this->assertInstanceOf( 'WP_Term', $term ); 323 $this->assertSame( 'foo', $term->slug ); 324 } 325 326 public function test_should_find_existing_term_by_slug_match() { 327 register_taxonomy( 'wptests_tax', 'post' ); 328 329 $t = self::factory()->term->create( array( 330 'taxonomy' => 'wptests_tax', 331 'slug' => 'foo', 332 'name' => 'Bar', 333 ) ); 334 335 $tt_ids = wp_set_object_terms( self::$post_ids[0], 'foo', 'wptests_tax' ); 336 337 $this->assertNotEmpty( $tt_ids ); 338 $term = get_term( $tt_ids[0] ); 339 $this->assertInstanceOf( 'WP_Term', $term ); 340 $this->assertSame( $t, $term->term_id ); 341 } 342 343 public function test_should_find_existing_term_by_name_match() { 344 register_taxonomy( 'wptests_tax', 'post' ); 345 346 $t = self::factory()->term->create( array( 347 'taxonomy' => 'wptests_tax', 348 'slug' => 'foo', 349 'name' => 'Bar', 350 ) ); 351 352 $tt_ids = wp_set_object_terms( self::$post_ids[0], 'Bar', 'wptests_tax' ); 353 354 $this->assertNotEmpty( $tt_ids ); 355 $term = get_term( $tt_ids[0] ); 356 $this->assertInstanceOf( 'WP_Term', $term ); 357 $this->assertSame( $t, $term->term_id ); 358 } 359 360 public function test_should_give_precedence_to_slug_match_over_name_match() { 361 register_taxonomy( 'wptests_tax', 'post' ); 362 363 $t1 = self::factory()->term->create( array( 364 'taxonomy' => 'wptests_tax', 365 'slug' => 'foo', 366 'name' => 'Bar', 367 ) ); 368 369 $t2 = self::factory()->term->create( array( 370 'taxonomy' => 'wptests_tax', 371 'slug' => 'bar', 372 'name' => 'Foo', 373 ) ); 374 375 $tt_ids = wp_set_object_terms( self::$post_ids[0], 'Bar', 'wptests_tax' ); 376 377 $this->assertNotEmpty( $tt_ids ); 378 $term = get_term( $tt_ids[0] ); 379 $this->assertInstanceOf( 'WP_Term', $term ); 380 $this->assertSame( $t2, $term->term_id ); 381 } 382 383 public function test_non_existent_integers_should_be_ignored() { 384 register_taxonomy( 'wptests_tax', 'post' ); 385 386 $tt_ids = wp_set_object_terms( self::$post_ids[0], 12345, 'wptests_tax' ); 387 388 $this->assertSame( array(), $tt_ids ); 389 } 312 390 }
Note: See TracChangeset
for help on using the changeset viewer.