From 47f6031fbd0e707bfc24657e3efc6fe219d9bbaf Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Jan 2018 20:51:06 +0000 Subject: [PATCH] Query: Improve tests for set_found_posts dealing with non arrays Use a data provider and include tests for `false` and `''`. Previous: [42581] [42585] See #42860 git-svn-id: https://develop.svn.wordpress.org/trunk@42594 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post/query.php | 37 ++++++++++-------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php index be27b8b168..ac87ad1554 100644 --- a/tests/phpunit/tests/post/query.php +++ b/tests/phpunit/tests/post/query.php @@ -643,35 +643,22 @@ class Tests_Post_Query extends WP_UnitTestCase { $this->assertEquals( 2, $q->max_num_pages ); } - /** - * @ticket 42860 - */ - public function test_set_found_posts_fields_posts_is_string() { - if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { - $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); - return; - } - - $q = new WP_Query( - array( - 'post_type' => 'wptests_pt', - 'posts_per_page' => 1, - ) + public function set_found_posts_provider() { + // count return 0 for null, but 1 for other data you may not expect + return array( + array( null, 0 ), + array( '', 1 ), + array( "To life, to life, l'chaim", 1 ), + array( false, 1 ), ); - - $q->posts = "To life, to life, l'chaim"; - - $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' ); - $methd->setAccessible( true ); - $methd->invoke( $q, array( 'no_found_rows' => false ), array() ); - - $this->assertEquals( 1, $q->found_posts ); } /** * @ticket 42860 + * + * @dataProvider set_found_posts_provider */ - public function test_set_found_posts_fields_posts_is_null() { + public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) { if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); return; @@ -684,13 +671,13 @@ class Tests_Post_Query extends WP_UnitTestCase { ) ); - $q->posts = null; + $q->posts = $posts; $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' ); $methd->setAccessible( true ); $methd->invoke( $q, array( 'no_found_rows' => false ), array() ); - $this->assertEquals( 0, $q->found_posts ); + $this->assertEquals( $expected, $q->found_posts ); } }