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
This commit is contained in:
Aaron Jorbin 2018-01-24 20:51:06 +00:00
parent dd9122b011
commit 47f6031fbd
1 changed files with 12 additions and 25 deletions

View File

@ -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 );
}
}