From 108e85314b46591cea00f7e7fa507153c5468a6a Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 17 Jan 2015 20:08:04 +0000 Subject: [PATCH] Move `wp_get_object_terms()` tests into their own file. See #26999. git-svn-id: https://develop.svn.wordpress.org/trunk@31230 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/term.php | 79 ---------------- tests/phpunit/tests/term/wpGetObjectTerms.php | 93 +++++++++++++++++++ 2 files changed, 93 insertions(+), 79 deletions(-) create mode 100644 tests/phpunit/tests/term/wpGetObjectTerms.php diff --git a/tests/phpunit/tests/term.php b/tests/phpunit/tests/term.php index d717bf6af9..78f4d29dc0 100644 --- a/tests/phpunit/tests/term.php +++ b/tests/phpunit/tests/term.php @@ -1061,85 +1061,6 @@ class Tests_Term extends WP_UnitTestCase { $this->assertEquals( 0, $count ); } - /** - * @ticket 26339 - */ - function test_get_object_terms() { - $post_id = $this->factory->post->create(); - $terms_1 = array('foo', 'bar', 'baz'); - - wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); - add_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) ); - $terms = wp_get_object_terms( $post_id, $this->taxonomy ); - remove_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) ); - foreach ( $terms as $term ) { - $this->assertInternalType( 'object', $term ); - } - } - - function filter_get_object_terms( $terms ) { - $term_ids = wp_list_pluck( $terms, 'term_id' ); - // all terms should still be objects - return $terms; - } - - function test_get_object_terms_by_slug() { - $post_id = $this->factory->post->create(); - - $terms_1 = array('Foo', 'Bar', 'Baz'); - $terms_1_slugs = array('foo', 'bar', 'baz'); - - // set the initial terms - $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); - $this->assertEquals( 3, count($tt_1) ); - - // make sure they're correct - $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 't.term_id')); - $this->assertEquals( $terms_1_slugs, $terms ); - } - - /** - * @ticket 11003 - */ - function test_wp_get_object_terms_no_dupes() { - $post_id1 = $this->factory->post->create(); - $post_id2 = $this->factory->post->create(); - $cat_id = $this->factory->category->create(); - $cat_id2 = $this->factory->category->create(); - wp_set_post_categories( $post_id1, array( $cat_id, $cat_id2 ) ); - wp_set_post_categories( $post_id2, $cat_id ); - - $terms = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category' ); - $this->assertCount( 2, $terms ); - $this->assertEquals( array( $cat_id, $cat_id2 ), wp_list_pluck( $terms, 'term_id' ) ); - - $terms2 = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category', array( - 'fields' => 'all_with_object_id' - ) ); - - $this->assertCount( 3, $terms2 ); - $this->assertEquals( array( $cat_id, $cat_id, $cat_id2 ), wp_list_pluck( $terms2, 'term_id' ) ); - } - - /** - * @ticket 17646 - */ - function test_get_object_terms_types() { - $post_id = $this->factory->post->create(); - $term = wp_insert_term( 'one', $this->taxonomy ); - wp_set_object_terms( $post_id, $term, $this->taxonomy ); - - $terms = wp_get_object_terms( $post_id, $this->taxonomy, array( 'fields' => 'all_with_object_id' ) ); - $term = array_shift( $terms ); - $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' ); - foreach ( $int_fields as $field ) - $this->assertInternalType( 'int', $term->$field, $field ); - - $terms = wp_get_object_terms( $post_id, $this->taxonomy, array( 'fields' => 'ids' ) ); - $term = array_shift( $terms ); - $this->assertInternalType( 'int', $term, 'term' ); - } - /** * @ticket 26570 */ diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php new file mode 100644 index 0000000000..89a3d484ee --- /dev/null +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -0,0 +1,93 @@ +factory->post->create(); + + $terms_1 = array('Foo', 'Bar', 'Baz'); + $terms_1_slugs = array('foo', 'bar', 'baz'); + + // set the initial terms + $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); + $this->assertEquals( 3, count($tt_1) ); + + // make sure they're correct + $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 't.term_id')); + $this->assertEquals( $terms_1_slugs, $terms ); + } + + /** + * @ticket 11003 + */ + public function test_should_not_filter_out_duplicate_terms_associated_with_different_objects() { + $post_id1 = $this->factory->post->create(); + $post_id2 = $this->factory->post->create(); + $cat_id = $this->factory->category->create(); + $cat_id2 = $this->factory->category->create(); + wp_set_post_categories( $post_id1, array( $cat_id, $cat_id2 ) ); + wp_set_post_categories( $post_id2, $cat_id ); + + $terms = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category' ); + $this->assertCount( 2, $terms ); + $this->assertEquals( array( $cat_id, $cat_id2 ), wp_list_pluck( $terms, 'term_id' ) ); + + $terms2 = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category', array( + 'fields' => 'all_with_object_id' + ) ); + + $this->assertCount( 3, $terms2 ); + $this->assertEquals( array( $cat_id, $cat_id, $cat_id2 ), wp_list_pluck( $terms2, 'term_id' ) ); + } + + /** + * @ticket 17646 + */ + public function test_should_return_objects_with_int_properties() { + $post_id = $this->factory->post->create(); + $term = wp_insert_term( 'one', $this->taxonomy ); + wp_set_object_terms( $post_id, $term, $this->taxonomy ); + + $terms = wp_get_object_terms( $post_id, $this->taxonomy, array( 'fields' => 'all_with_object_id' ) ); + $term = array_shift( $terms ); + $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' ); + foreach ( $int_fields as $field ) + $this->assertInternalType( 'int', $term->$field, $field ); + + $terms = wp_get_object_terms( $post_id, $this->taxonomy, array( 'fields' => 'ids' ) ); + $term = array_shift( $terms ); + $this->assertInternalType( 'int', $term, 'term' ); + } + + /** + * @ticket 26339 + */ + public function test_references_should_be_reset_after_wp_get_object_terms_filter() { + $post_id = $this->factory->post->create(); + $terms_1 = array('foo', 'bar', 'baz'); + + wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); + add_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) ); + $terms = wp_get_object_terms( $post_id, $this->taxonomy ); + remove_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) ); + foreach ( $terms as $term ) { + $this->assertInternalType( 'object', $term ); + } + } + + public function filter_get_object_terms( $terms ) { + $term_ids = wp_list_pluck( $terms, 'term_id' ); + // all terms should still be objects + return $terms; + } +}