@@ -387,7 +387,7 @@ public function test_output_schema_describes_single_post_and_query_responses():
387387 $ this ->assertSame ( 'object ' , $ schema ['type ' ], 'The output schema should describe object responses. ' );
388388 $ this ->assertCount ( 2 , $ schema ['oneOf ' ], 'The output schema should describe single-post and query responses. ' );
389389 $ this ->assertSame ( 'object ' , $ post_schema ['type ' ], 'The single-post response should be described as an object. ' );
390- $ this ->assertArrayNotHasKey ( ' required ' , $ post_schema , 'Individual post fields should remain optional . ' );
390+ $ this ->assertSame ( array ( ' id ' ) , $ post_schema[ ' required ' ] , 'Only the always-returned id should be required in a post . ' );
391391 $ this ->assertFalse ( $ post_schema ['additionalProperties ' ], 'Returned posts should not allow unknown properties. ' );
392392 $ this ->assertArrayHasKey ( 'type ' , $ post_schema ['properties ' ], 'The post schema should describe the post type as type. ' );
393393 $ this ->assertArrayNotHasKey ( 'post_type ' , $ post_schema ['properties ' ], 'The post schema should not expose the post type as post_type. ' );
@@ -1865,6 +1865,11 @@ public function test_query_mode_rejects_parent_filter_for_non_hierarchical_post_
18651865
18661866 $ this ->assertWPError ( $ result , 'The parent filter should be rejected for non-hierarchical post types. ' );
18671867 $ this ->assertSame ( 'content_invalid_filter ' , $ result ->get_error_code (), 'Unsupported parent filters should return a filter error. ' );
1868+ $ this ->assertSame (
1869+ array ( 'parent ' => $ result ->get_error_message () ),
1870+ $ result ->get_error_data ()['params ' ],
1871+ 'The error data should map the unsupported parent filter to the error message. '
1872+ );
18681873 }
18691874
18701875 /**
@@ -1930,6 +1935,11 @@ public function test_query_mode_rejects_author_filter_for_post_type_without_auth
19301935
19311936 $ this ->assertWPError ( $ result , 'The author_slug filter should be rejected for post types without author support. ' );
19321937 $ this ->assertSame ( 'content_invalid_filter ' , $ result ->get_error_code (), 'Unsupported author filters should return a filter error. ' );
1938+ $ this ->assertSame (
1939+ array ( 'author_slug ' => $ result ->get_error_message () ),
1940+ $ result ->get_error_data ()['params ' ],
1941+ 'The error data should map the unsupported author_slug filter to the error message. '
1942+ );
19331943 }
19341944
19351945 /**
@@ -3601,7 +3611,7 @@ public function test_gmt_date_recovers_from_a_null_stored_gmt_date( string $fiel
36013611 }
36023612
36033613 /**
3604- * A post with no usable date at all reports the documented empty-string sentinel .
3614+ * A post with no usable date at all reports null .
36053615 *
36063616 * @ticket 66268
36073617 * @since 7.2.0
@@ -3614,7 +3624,7 @@ public function test_gmt_date_recovers_from_a_null_stored_gmt_date( string $fiel
36143624 * @param string $local_date Unused. Present to match the shared data provider shape.
36153625 * @param string $expected Unused. Present to match the shared data provider shape.
36163626 */
3617- public function test_gmt_date_is_empty_when_no_usable_date_exists ( string $ field , string $ gmt_column , string $ local_column , string $ local_date , string $ expected ): void {
3627+ public function test_gmt_date_is_null_when_no_usable_date_exists ( string $ field , string $ gmt_column , string $ local_column , string $ local_date , string $ expected ): void {
36183628 $ this ->login_as ( 'administrator ' );
36193629 $ this ->register_ability ();
36203630
@@ -3635,7 +3645,71 @@ public function test_gmt_date_is_empty_when_no_usable_date_exists( string $field
36353645 )
36363646 );
36373647
3638- $ this ->assertSame ( '' , $ result [ $ field ], 'An unresolvable GMT date should be the empty-string sentinel. ' );
3648+ $ this ->assertIsArray ( $ result , 'An unresolvable GMT date should pass output validation. ' );
3649+ $ this ->assertArrayHasKey ( $ field , $ result , 'An unresolvable GMT date should still be returned. ' );
3650+ $ this ->assertNull ( $ result [ $ field ], 'An unresolvable GMT date should be null. ' );
3651+ }
3652+
3653+ /**
3654+ * Data provider for date fields.
3655+ *
3656+ * @since 7.2.0
3657+ *
3658+ * @return array<string, array{field: string, column: string}>
3659+ */
3660+ public function data_date_fields (): array {
3661+ return array (
3662+ 'date ' => array (
3663+ 'field ' => 'date ' ,
3664+ 'column ' => 'post_date ' ,
3665+ ),
3666+ 'date_gmt ' => array (
3667+ 'field ' => 'date_gmt ' ,
3668+ 'column ' => 'post_date_gmt ' ,
3669+ ),
3670+ 'modified ' => array (
3671+ 'field ' => 'modified ' ,
3672+ 'column ' => 'post_modified ' ,
3673+ ),
3674+ 'modified_gmt ' => array (
3675+ 'field ' => 'modified_gmt ' ,
3676+ 'column ' => 'post_modified_gmt ' ,
3677+ ),
3678+ );
3679+ }
3680+
3681+ /**
3682+ * A malformed stored date reports null instead of failing output validation.
3683+ *
3684+ * A zero month still parses, but formats with a negative year, which the `date-time`
3685+ * format of the output schema rejects.
3686+ *
3687+ * @ticket 66268
3688+ * @since 7.2.0
3689+ *
3690+ * @dataProvider data_date_fields
3691+ *
3692+ * @param string $field The ability output field to request.
3693+ * @param string $column The cached post column to corrupt.
3694+ */
3695+ public function test_malformed_date_is_null ( string $ field , string $ column ): void {
3696+ $ this ->login_as ( 'administrator ' );
3697+ $ this ->register_ability ();
3698+
3699+ $ post_id = self ::factory ()->post ->create ( array ( 'post_status ' => 'publish ' ) );
3700+
3701+ $ this ->replace_cached_post_date_columns ( $ post_id , array ( $ column => '0000-00-01 00:00:00 ' ) );
3702+
3703+ $ result = wp_get_ability ( 'core/content-query ' )->execute (
3704+ array (
3705+ 'id ' => $ post_id ,
3706+ 'fields ' => array ( 'id ' , $ field ),
3707+ )
3708+ );
3709+
3710+ $ this ->assertIsArray ( $ result , 'A malformed date should pass output validation. ' );
3711+ $ this ->assertArrayHasKey ( $ field , $ result , 'A malformed date should still be returned. ' );
3712+ $ this ->assertNull ( $ result [ $ field ], 'A malformed date should be null. ' );
36393713 }
36403714
36413715 /**
@@ -3717,6 +3791,11 @@ public function test_execute_callback_rejects_an_author_slug_that_names_no_user(
37173791
37183792 $ this ->assertWPError ( $ result , 'An author_slug that names no user must not silently widen the query to all authors. ' );
37193793 $ this ->assertSame ( 'content_invalid_filter ' , $ result ->get_error_code (), 'An unhonorable author_slug filter should fail closed as an invalid filter. ' );
3794+ $ this ->assertSame (
3795+ array ( 'author_slug ' => $ result ->get_error_message () ),
3796+ $ result ->get_error_data ()['params ' ],
3797+ 'The error data should map the unmatched author_slug filter to the error message. '
3798+ );
37203799 }
37213800
37223801 /**
@@ -3789,6 +3868,11 @@ public function test_execute_callback_rejects_non_integer_parent_filter(): void
37893868
37903869 $ this ->assertWPError ( $ result , 'A non-integer parent filter must not silently coerce to a top-level (0) query. ' );
37913870 $ this ->assertSame ( 'content_invalid_filter ' , $ result ->get_error_code (), 'An unhonorable parent filter should fail closed as an invalid filter. ' );
3871+ $ this ->assertSame (
3872+ array ( 'parent ' => $ result ->get_error_message () ),
3873+ $ result ->get_error_data ()['params ' ],
3874+ 'The error data should map the non-integer parent filter to the error message. '
3875+ );
37923876 }
37933877
37943878 /**
@@ -3817,6 +3901,11 @@ public function test_execute_callback_rejects_include_with_no_valid_ids(): void
38173901
38183902 $ this ->assertWPError ( $ result , 'An include filter with no valid IDs must not fall through to an unrestricted query. ' );
38193903 $ this ->assertSame ( 'content_invalid_filter ' , $ result ->get_error_code (), 'An empty-after-parsing include should fail closed as an invalid filter. ' );
3904+ $ this ->assertSame (
3905+ array ( 'include ' => $ result ->get_error_message () ),
3906+ $ result ->get_error_data ()['params ' ],
3907+ 'The error data should map the include filter to the error message. '
3908+ );
38203909 }
38213910
38223911 /**
@@ -3855,6 +3944,11 @@ public function test_author_slug_filter_only_names_users_the_current_user_may_se
38553944 $ hidden = $ query ( array ( 'publish ' ), self ::$ user_ids ['author_secondary ' ] );
38563945 $ this ->assertWPError ( $ hidden , 'A subscriber should not learn that an author without published posts exists. ' );
38573946 $ this ->assertSame ( 'content_invalid_filter ' , $ hidden ->get_error_code (), 'A hidden author should be reported like a missing one. ' );
3947+ $ this ->assertSame (
3948+ array ( 'author_slug ' => $ hidden ->get_error_message () ),
3949+ $ hidden ->get_error_data ()['params ' ],
3950+ 'The error data should map the hidden author_slug filter to the error message. '
3951+ );
38583952
38593953 $ this ->login_as ( 'editor ' );
38603954 $ drafts = $ query ( array ( 'draft ' ), self ::$ user_ids ['author_secondary ' ] );
0 commit comments