From a59ebc0ed4ca581f55f8d577c429317631120b19 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 30 May 2015 13:03:07 +0000 Subject: [PATCH] Term unit test factory class should override `create_and_get()` method. The override is necessary because the `get_term()` call, which fetches the term object, needs the `'taxonomy'` argument passed to the factory method. Props dlh. Fixes #32536. git-svn-id: https://develop.svn.wordpress.org/trunk@32659 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/factory.php | 6 ++++++ tests/phpunit/tests/includes/factory.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/phpunit/includes/factory.php b/tests/phpunit/includes/factory.php index 4adec23e89..20bad89a96 100644 --- a/tests/phpunit/includes/factory.php +++ b/tests/phpunit/includes/factory.php @@ -252,6 +252,12 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { return wp_set_post_terms( $post_id, $terms, $taxonomy, $append ); } + function create_and_get( $args = array(), $generation_definitions = null ) { + $term_id = $this->create( $args, $generation_definitions ); + $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy; + return get_term( $term_id, $taxonomy ); + } + function get_object_by_id( $term_id ) { return get_term( $term_id, $this->taxonomy ); } diff --git a/tests/phpunit/tests/includes/factory.php b/tests/phpunit/tests/includes/factory.php index 34516861e6..9136eeca8c 100644 --- a/tests/phpunit/tests/includes/factory.php +++ b/tests/phpunit/tests/includes/factory.php @@ -28,4 +28,14 @@ class TestFactoryFor extends WP_UnitTestCase { $term = get_term( $id, 'post_tag' ); $this->assertEquals( $id, $term->term_id ); } + + /** + * @ticket 32536 + */ + public function test_term_factory_create_and_get_should_return_term_object() { + register_taxonomy( 'wptests_tax', 'post' ); + $term = $this->factory->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) ); + $this->assertInternalType( 'object', $term ); + $this->assertNotEmpty( $term->term_id ); + } }