diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 66f472a859..2b082abffe 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -278,4 +278,48 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { $tmp_dir = realpath( $dir ); return tempnam( $tmp_dir, 'wpunit' ); } + + /** + * Check each of the WP_Query is_* functions/properties against expected boolean value. + * + * Any properties that are listed by name as parameters will be expected to be true; any others are + * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single() + * and is_feed() must be true and everything else must be false to pass. + * + * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request. + */ + function assertQueryTrue(/* ... */) { + global $wp_query; + $all = array( + 'is_single', 'is_preview', 'is_page', 'is_archive', 'is_date', 'is_year', 'is_month', 'is_day', 'is_time', + 'is_author', 'is_category', 'is_tag', 'is_tax', 'is_search', 'is_feed', 'is_comment_feed', 'is_trackback', + 'is_home', 'is_404', 'is_comments_popup', 'is_paged', 'is_admin', 'is_attachment', 'is_singular', 'is_robots', + 'is_posts_page', 'is_post_type_archive', + ); + $true = func_get_args(); + + $passed = true; + $not_false = $not_true = array(); // properties that were not set to expected values + + foreach ( $all as $query_thing ) { + $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->$query_thing; + + if ( in_array( $query_thing, $true ) ) { + if ( ! $result ) { + array_push( $not_true, $query_thing ); + $passed = false; + } + } else if ( $result ) { + array_push( $not_false, $query_thing ); + $passed = false; + } + } + + $message = ''; + if ( count($not_true) ) + $message .= implode( $not_true, ', ' ) . ' should be true. '; + if ( count($not_false) ) + $message .= implode( $not_false, ', ' ) . ' should be false.'; + $this->assertTrue( $passed, $message ); + } } diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 8a75395d63..a00a4b43eb 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -34,50 +34,6 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $GLOBALS['wp_rewrite']->init(); } - /** - * Check each of the WP_Query is_* functions/properties against expected boolean value. - * - * Any properties that are listed by name as parameters will be expected to be true; any others are - * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single() - * and is_feed() must be true and everything else must be false to pass. - * - * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request. - */ - function assertQueryTrue(/* ... */) { - global $wp_query; - $all = array( - 'is_single', 'is_preview', 'is_page', 'is_archive', 'is_date', 'is_year', 'is_month', 'is_day', 'is_time', - 'is_author', 'is_category', 'is_tag', 'is_tax', 'is_search', 'is_feed', 'is_comment_feed', 'is_trackback', - 'is_home', 'is_404', 'is_comments_popup', 'is_paged', 'is_admin', 'is_attachment', 'is_singular', 'is_robots', - 'is_posts_page', 'is_post_type_archive', - ); - $true = func_get_args(); - - $passed = true; - $not_false = $not_true = array(); // properties that were not set to expected values - - foreach ( $all as $query_thing ) { - $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->$query_thing; - - if ( in_array( $query_thing, $true ) ) { - if ( ! $result ) { - array_push( $not_true, $query_thing ); - $passed = false; - } - } else if ( $result ) { - array_push( $not_false, $query_thing ); - $passed = false; - } - } - - $message = ''; - if ( count($not_true) ) - $message .= implode( $not_true, ', ' ) . ' should be true. '; - if ( count($not_false) ) - $message .= implode( $not_false, ', ' ) . ' should be false.'; - $this->assertTrue( $passed, $message ); - } - function test_home() { $this->go_to('/'); $this->assertQueryTrue('is_home');