You appear to be a bot. Output may be restricted
Description
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.
Usage
WP_UnitTestCase::assertQueryTrue();
Parameters
Returns
voidSource
File name: oik-batch/tests/testcase.phpLines:
1 to 62 of 62
function assertQueryTrue(/* ... */) { global $wp_query; $all = array( 'is_404', 'is_admin', 'is_archive', 'is_attachment', 'is_author', 'is_category', 'is_comment_feed', 'is_date', 'is_day', 'is_embed', 'is_feed', 'is_front_page', 'is_home', 'is_month', 'is_page', 'is_paged', 'is_post_type_archive', 'is_posts_page', 'is_preview', 'is_robots', 'is_search', 'is_single', 'is_singular', 'is_tag', 'is_tax', 'is_time', 'is_trackback', 'is_year', ); $true = func_get_args(); foreach ( $true as $true_thing ) { $this->assertContains( $true_thing, $all, "{$true_thing}() is not handled by assertQueryTrue()." ); } $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, ', ' ) . ' is expected to be true. '; if ( count($not_false) ) $message .= implode( $not_false, ', ' ) . ' is expected to be false.'; $this->assertTrue( $passed, $message ); }View on GitHub