@@ -879,6 +879,82 @@ public function assertNonEmptyMultidimensionalArray( $array, $message = '' ) {
879879 }
880880 }
881881
882+ /**
883+ * Checks each of the WP_Query is_* functions/properties against expected boolean value.
884+ *
885+ * Any properties that are listed by name as parameters will be expected to be true; all others are
886+ * expected to be false. For example, assertQueryTrue( 'is_single', 'is_feed' ) means is_single()
887+ * and is_feed() must be true and everything else must be false to pass.
888+ *
889+ * @since 2.5.0
890+ * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`.
891+ * @since 5.3.0 Formalized the existing `...$prop` parameter by adding it
892+ * to the function signature.
893+ *
894+ * @param string ...$prop Any number of WP_Query properties that are expected to be true for the current request.
895+ */
896+ public function assertQueryTrue ( ...$ prop ) {
897+ global $ wp_query ;
898+
899+ $ all = array (
900+ 'is_404 ' ,
901+ 'is_admin ' ,
902+ 'is_archive ' ,
903+ 'is_attachment ' ,
904+ 'is_author ' ,
905+ 'is_category ' ,
906+ 'is_comment_feed ' ,
907+ 'is_date ' ,
908+ 'is_day ' ,
909+ 'is_embed ' ,
910+ 'is_feed ' ,
911+ 'is_front_page ' ,
912+ 'is_home ' ,
913+ 'is_privacy_policy ' ,
914+ 'is_month ' ,
915+ 'is_page ' ,
916+ 'is_paged ' ,
917+ 'is_post_type_archive ' ,
918+ 'is_posts_page ' ,
919+ 'is_preview ' ,
920+ 'is_robots ' ,
921+ 'is_favicon ' ,
922+ 'is_search ' ,
923+ 'is_single ' ,
924+ 'is_singular ' ,
925+ 'is_tag ' ,
926+ 'is_tax ' ,
927+ 'is_time ' ,
928+ 'is_trackback ' ,
929+ 'is_year ' ,
930+ );
931+
932+ foreach ( $ prop as $ true_thing ) {
933+ $ this ->assertContains ( $ true_thing , $ all , "Unknown conditional: {$ true_thing }. " );
934+ }
935+
936+ $ passed = true ;
937+ $ message = '' ;
938+
939+ foreach ( $ all as $ query_thing ) {
940+ $ result = is_callable ( $ query_thing ) ? call_user_func ( $ query_thing ) : $ wp_query ->$ query_thing ;
941+
942+ if ( in_array ( $ query_thing , $ prop , true ) ) {
943+ if ( ! $ result ) {
944+ $ message .= $ query_thing . ' is false but is expected to be true. ' . PHP_EOL ;
945+ $ passed = false ;
946+ }
947+ } elseif ( $ result ) {
948+ $ message .= $ query_thing . ' is true but is expected to be false. ' . PHP_EOL ;
949+ $ passed = false ;
950+ }
951+ }
952+
953+ if ( ! $ passed ) {
954+ $ this ->fail ( $ message );
955+ }
956+ }
957+
882958 /**
883959 * Helper function to convert a single-level array containing text strings to a named data provider.
884960 *
@@ -1105,82 +1181,6 @@ public function temp_filename() {
11051181 return tempnam ( $ tmp_dir , 'wpunit ' );
11061182 }
11071183
1108- /**
1109- * Checks each of the WP_Query is_* functions/properties against expected boolean value.
1110- *
1111- * Any properties that are listed by name as parameters will be expected to be true; all others are
1112- * expected to be false. For example, assertQueryTrue( 'is_single', 'is_feed' ) means is_single()
1113- * and is_feed() must be true and everything else must be false to pass.
1114- *
1115- * @since 2.5.0
1116- * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`.
1117- * @since 5.3.0 Formalized the existing `...$prop` parameter by adding it
1118- * to the function signature.
1119- *
1120- * @param string ...$prop Any number of WP_Query properties that are expected to be true for the current request.
1121- */
1122- public function assertQueryTrue ( ...$ prop ) {
1123- global $ wp_query ;
1124-
1125- $ all = array (
1126- 'is_404 ' ,
1127- 'is_admin ' ,
1128- 'is_archive ' ,
1129- 'is_attachment ' ,
1130- 'is_author ' ,
1131- 'is_category ' ,
1132- 'is_comment_feed ' ,
1133- 'is_date ' ,
1134- 'is_day ' ,
1135- 'is_embed ' ,
1136- 'is_feed ' ,
1137- 'is_front_page ' ,
1138- 'is_home ' ,
1139- 'is_privacy_policy ' ,
1140- 'is_month ' ,
1141- 'is_page ' ,
1142- 'is_paged ' ,
1143- 'is_post_type_archive ' ,
1144- 'is_posts_page ' ,
1145- 'is_preview ' ,
1146- 'is_robots ' ,
1147- 'is_favicon ' ,
1148- 'is_search ' ,
1149- 'is_single ' ,
1150- 'is_singular ' ,
1151- 'is_tag ' ,
1152- 'is_tax ' ,
1153- 'is_time ' ,
1154- 'is_trackback ' ,
1155- 'is_year ' ,
1156- );
1157-
1158- foreach ( $ prop as $ true_thing ) {
1159- $ this ->assertContains ( $ true_thing , $ all , "Unknown conditional: {$ true_thing }. " );
1160- }
1161-
1162- $ passed = true ;
1163- $ message = '' ;
1164-
1165- foreach ( $ all as $ query_thing ) {
1166- $ result = is_callable ( $ query_thing ) ? call_user_func ( $ query_thing ) : $ wp_query ->$ query_thing ;
1167-
1168- if ( in_array ( $ query_thing , $ prop , true ) ) {
1169- if ( ! $ result ) {
1170- $ message .= $ query_thing . ' is false but is expected to be true. ' . PHP_EOL ;
1171- $ passed = false ;
1172- }
1173- } elseif ( $ result ) {
1174- $ message .= $ query_thing . ' is true but is expected to be false. ' . PHP_EOL ;
1175- $ passed = false ;
1176- }
1177- }
1178-
1179- if ( ! $ passed ) {
1180- $ this ->fail ( $ message );
1181- }
1182- }
1183-
11841184 /**
11851185 * Selectively deletes a file.
11861186 *
0 commit comments