From 60a216d58759ee115ec68c11e3b32b4259a58313 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 2 Jan 2015 14:02:54 +0000 Subject: [PATCH] Add tests for `wp_delete_object_term_relationships()`. See #30879. git-svn-id: https://develop.svn.wordpress.org/trunk@31021 602fd350-edb4-49c9-b593-d223f7449a82 --- .../term/wpDeleteObjectTermRelationships.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/phpunit/tests/term/wpDeleteObjectTermRelationships.php diff --git a/tests/phpunit/tests/term/wpDeleteObjectTermRelationships.php b/tests/phpunit/tests/term/wpDeleteObjectTermRelationships.php new file mode 100644 index 0000000000..c4b7611153 --- /dev/null +++ b/tests/phpunit/tests/term/wpDeleteObjectTermRelationships.php @@ -0,0 +1,56 @@ +factory->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); + $t2 = $this->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->assertEqualSets( 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->assertEqualSets( 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 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); + $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); + $t3 = $this->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->assertEqualSets( 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->assertEqualSets( array( $t2 ), $terms ); + } +}