From 9dafca7e2c4439214121bfbe8694e67bddabcdde Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 23 Oct 2014 13:52:57 +0000 Subject: [PATCH] Add unit tests for 'append' argument of wp_set_object_terms(). See #29624. git-svn-id: https://develop.svn.wordpress.org/trunk@29997 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/term.php | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/phpunit/tests/term.php b/tests/phpunit/tests/term.php index 5ec9b246cd..5f1e9aa621 100644 --- a/tests/phpunit/tests/term.php +++ b/tests/phpunit/tests/term.php @@ -1304,6 +1304,69 @@ class Tests_Term extends WP_UnitTestCase { $this->assertTrue( is_wp_error($result) ); } + public function test_wp_set_object_terms_append_true() { + register_taxonomy( 'wptests_tax', 'post' ); + $p = $this->factory->post->create(); + $t1 = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + ) ); + $t2 = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + ) ); + + $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' ); + $this->assertNotEmpty( $added1 ); + $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) ); + + $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', true ); + $this->assertNotEmpty( $added2 ); + $this->assertEqualSets( array( $t1, $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) ); + + _unregister_taxonomy( 'wptests_tax' ); + } + + public function test_wp_set_object_terms_append_false() { + register_taxonomy( 'wptests_tax', 'post' ); + $p = $this->factory->post->create(); + $t1 = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + ) ); + $t2 = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + ) ); + + $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' ); + $this->assertNotEmpty( $added1 ); + $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) ); + + $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', false ); + $this->assertNotEmpty( $added2 ); + $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) ); + + _unregister_taxonomy( 'wptests_tax' ); + } + + public function test_wp_set_object_terms_append_default_to_false() { + register_taxonomy( 'wptests_tax', 'post' ); + $p = $this->factory->post->create(); + $t1 = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + ) ); + $t2 = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + ) ); + + $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' ); + $this->assertNotEmpty( $added1 ); + $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) ); + + $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax' ); + $this->assertNotEmpty( $added2 ); + $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) ); + + _unregister_taxonomy( 'wptests_tax' ); + } + function test_change_object_terms_by_id() { // set some terms on an object; then change them while leaving one intact