wordpress-develop/tests/phpunit/tests/term/wpDeleteObjectTermRelationships.php
Sergey Biryukov 8be943d06e Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate.
This ensures that not only the array values being compared are equal, but also that their type is the same.

These new methods replace most of the existing instances of `assertEqualSets()` and `assertEqualSetsWithIndex()`.

Going forward, stricter type checking by using `assertSameSets()` or `assertSameSetsWithIndex()` should generally be preferred, to make the tests more reliable.

Follow-up to [48937].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48939 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-04 07:01:00 +00:00

57 lines
2.3 KiB
PHP

<?php
/**
* @group taxonomy
* @covers ::wp_delete_object_term_relationships
*/
class Tests_Term_WpDeleteObjectTermRelationships extends WP_UnitTestCase {
public function test_single_taxonomy() {
register_taxonomy( 'wptests_tax1', 'post' );
register_taxonomy( 'wptests_tax2', 'post' );
$t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) );
$t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) );
$object_id = 567;
wp_set_object_terms( $object_id, array( $t1 ), 'wptests_tax1' );
wp_set_object_terms( $object_id, array( $t2 ), 'wptests_tax2' );
// Confirm the setup.
$terms = wp_get_object_terms( $object_id, array( 'wptests_tax1', 'wptests_tax2' ), array( 'fields' => 'ids' ) );
$this->assertSameSets( array( $t1, $t2 ), $terms );
// wp_delete_object_term_relationships() doesn't have a return value.
wp_delete_object_term_relationships( $object_id, 'wptests_tax2' );
$terms = wp_get_object_terms( $object_id, array( 'wptests_tax1', 'wptests_tax2' ), array( 'fields' => 'ids' ) );
$this->assertSameSets( array( $t1 ), $terms );
}
public function test_array_of_taxonomies() {
register_taxonomy( 'wptests_tax1', 'post' );
register_taxonomy( 'wptests_tax2', 'post' );
register_taxonomy( 'wptests_tax3', 'post' );
$t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) );
$t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) );
$t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax3' ) );
$object_id = 567;
wp_set_object_terms( $object_id, array( $t1 ), 'wptests_tax1' );
wp_set_object_terms( $object_id, array( $t2 ), 'wptests_tax2' );
wp_set_object_terms( $object_id, array( $t3 ), 'wptests_tax3' );
// Confirm the setup.
$terms = wp_get_object_terms( $object_id, array( 'wptests_tax1', 'wptests_tax2', 'wptests_tax3' ), array( 'fields' => 'ids' ) );
$this->assertSameSets( array( $t1, $t2, $t3 ), $terms );
// wp_delete_object_term_relationships() doesn't have a return value.
wp_delete_object_term_relationships( $object_id, array( 'wptests_tax1', 'wptests_tax3' ) );
$terms = wp_get_object_terms( $object_id, array( 'wptests_tax1', 'wptests_tax2', 'wptests_tax3' ), array( 'fields' => 'ids' ) );
$this->assertSameSets( array( $t2 ), $terms );
}
}