From 9ba596555c00b36a2ce3045f3d3f1a20f0ef7976 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 3 Jun 2024 22:07:27 +0200 Subject: [PATCH 01/17] Add the class_list field. --- .../endpoints/class-wp-rest-posts-controller.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index ec1588b02fe57..97a04deace224 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1998,6 +1998,10 @@ public function prepare_item_for_response( $item, $request ) { $data['generated_slug'] = $sample_permalink[1]; } } + + if ( rest_is_field_included( 'class_list', $fields ) ) { + $data['class_list'] = get_post_class( array(), $post->ID ); + } } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; @@ -2353,6 +2357,15 @@ public function get_item_schema() { 'context' => array( 'edit' ), 'readonly' => true, ); + + $schema['properties']['class_list'] = array( + 'description' => __( 'An array of the class names for the post container element.' ), + 'type' => 'array', + 'context' => array( 'view', 'edit', 'embed' ), + 'items' => array( + 'type' => 'string', + ), + ); } if ( $post_type_obj->hierarchical ) { From e6bb75c8584a57cc2738393a6c9855bc416e2521 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 3 Jun 2024 22:46:47 +0200 Subject: [PATCH 02/17] Fix the failing test. --- tests/phpunit/tests/rest-api/rest-attachments-controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 956e8afd300b9..feaf1900d0830 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -1646,7 +1646,7 @@ public function test_get_item_schema() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 28, $properties ); + $this->assertCount( 29, $properties ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'alt_text', $properties ); $this->assertArrayHasKey( 'caption', $properties ); @@ -1681,6 +1681,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'type', $properties ); $this->assertArrayHasKey( 'missing_image_sizes', $properties ); $this->assertArrayHasKey( 'featured_media', $properties ); + $this->assertArrayHasKey( 'class_list', $properties ); } public function test_get_additional_field_registration() { From c3f58ebc3b83923d5d8a47afa2e9679c449cb7bc Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 3 Jun 2024 23:19:17 +0200 Subject: [PATCH 03/17] Fix the failing test. --- tests/phpunit/tests/rest-api/rest-pages-controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index 75c005b275152..209229256a11f 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -748,7 +748,7 @@ public function test_get_item_schema() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 24, $properties ); + $this->assertCount( 25, $properties ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'comment_status', $properties ); $this->assertArrayHasKey( 'content', $properties ); @@ -773,6 +773,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'template', $properties ); $this->assertArrayHasKey( 'title', $properties ); $this->assertArrayHasKey( 'type', $properties ); + $this->assertArrayHasKey( 'class_list', $properties ); } public function filter_theme_page_templates( $page_templates ) { From 8986cbb27f645f51cf455b3ae502a6c0c784cc58 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 3 Jun 2024 23:26:27 +0200 Subject: [PATCH 04/17] Fix the failing test. --- tests/phpunit/tests/rest-api/rest-posts-controller.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 12fac4dbebfa2..8b81b9f648651 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -4362,7 +4362,7 @@ public function test_get_item_schema() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 26, $properties ); + $this->assertCount( 27, $properties ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'comment_status', $properties ); $this->assertArrayHasKey( 'content', $properties ); @@ -4389,6 +4389,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'type', $properties ); $this->assertArrayHasKey( 'tags', $properties ); $this->assertArrayHasKey( 'categories', $properties ); + $this->assertArrayHasKey( 'class_list', $properties ); } /** @@ -4418,6 +4419,7 @@ public function test_get_post_view_context_properties() { $expected_keys = array( 'author', 'categories', + 'class_list', 'comment_status', 'content', 'date', @@ -4456,6 +4458,7 @@ public function test_get_post_edit_context_properties() { $expected_keys = array( 'author', 'categories', + 'class_list', 'comment_status', 'content', 'date', From 4b07732b3b6c802880ae7e7423f888f1f0caddcc Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 3 Jun 2024 23:42:11 +0200 Subject: [PATCH 05/17] Don't add to embed context. --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 97a04deace224..8b3c9762d3fc2 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -2359,9 +2359,9 @@ public function get_item_schema() { ); $schema['properties']['class_list'] = array( - 'description' => __( 'An array of the class names for the post container element.' ), + 'description' => __( 'An array of the CSS class names for the post container element.' ), 'type' => 'array', - 'context' => array( 'view', 'edit', 'embed' ), + 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'string', ), From a4aef1d694527eb47c7880be0cb77e7a10a14c4f Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 00:19:20 +0200 Subject: [PATCH 06/17] Updated mocked responses. --- .../class-wp-rest-posts-controller.php | 2 +- tests/qunit/fixtures/wp-api-generated.js | 114 +++++++++++++++++- 2 files changed, 113 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 8b3c9762d3fc2..6569cf5e25424 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -2359,7 +2359,7 @@ public function get_item_schema() { ); $schema['properties']['class_list'] = array( - 'description' => __( 'An array of the CSS class names for the post container element.' ), + 'description' => __( 'An array of the class names for the post container element.' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index ed7842acd09c4..c220f0b727763 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -669,6 +669,14 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "title": { "description": "The title for the post.", "type": "object", @@ -953,6 +961,14 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "title": { "description": "The title for the post.", "type": "object", @@ -1392,6 +1408,14 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "title": { "description": "The title for the post.", "type": "object", @@ -1867,6 +1891,14 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "parent": { "description": "The ID for the parent of the post.", "type": "integer", @@ -2123,6 +2155,14 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "parent": { "description": "The ID for the parent of the post.", "type": "integer", @@ -2534,6 +2574,14 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "title": { "description": "The title for the post.", "type": "object", @@ -2968,6 +3016,14 @@ mockedApiResponse.Schema = { ], "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "title": { "description": "The title for the post.", "type": "object", @@ -3175,6 +3231,14 @@ mockedApiResponse.Schema = { ], "required": false }, + "class_list": { + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + }, + "required": false + }, "title": { "description": "The title for the post.", "type": "object", @@ -12322,6 +12386,15 @@ mockedApiResponse.PostsCollection = [ 1 ], "tags": [], + "class_list": [ + "post-4", + "post", + "type-post", + "status-publish", + "format-standard", + "hentry", + "category-uncategorized" + ], "_links": { "self": [ { @@ -12421,7 +12494,16 @@ mockedApiResponse.PostModel = { "categories": [ 1 ], - "tags": [] + "tags": [], + "class_list": [ + "post-4", + "post", + "type-post", + "status-publish", + "format-standard", + "hentry", + "category-uncategorized" + ] }; mockedApiResponse.postRevisions = [ @@ -12613,6 +12695,13 @@ mockedApiResponse.PagesCollection = [ "meta": { "meta_key": "" }, + "class_list": [ + "post-7", + "page", + "type-page", + "status-publish", + "hentry" + ], "_links": { "self": [ { @@ -12696,7 +12785,14 @@ mockedApiResponse.PageModel = { "template": "", "meta": { "meta_key": "" - } + }, + "class_list": [ + "post-7", + "page", + "type-page", + "status-publish", + "hentry" + ] }; mockedApiResponse.pageRevisions = [ @@ -12878,6 +12974,13 @@ mockedApiResponse.MediaCollection = [ "meta": { "meta_key": "" }, + "class_list": [ + "post-10", + "attachment", + "type-attachment", + "status-inherit", + "hentry" + ], "description": { "rendered": "

" }, @@ -12940,6 +13043,13 @@ mockedApiResponse.MediaModel = { "meta": { "meta_key": "" }, + "class_list": [ + "post-10", + "attachment", + "type-attachment", + "status-inherit", + "hentry" + ], "description": { "rendered": "

" }, From 0b6dc03df7b8be92a289ae163c07b2e359caa8e7 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 00:33:08 +0200 Subject: [PATCH 07/17] Fix fixtures. --- tests/qunit/fixtures/wp-api-generated.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index c220f0b727763..21c11117aeabd 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -12387,7 +12387,7 @@ mockedApiResponse.PostsCollection = [ ], "tags": [], "class_list": [ - "post-4", + "post-2390", "post", "type-post", "status-publish", @@ -12496,7 +12496,7 @@ mockedApiResponse.PostModel = { ], "tags": [], "class_list": [ - "post-4", + "post-2390", "post", "type-post", "status-publish", @@ -12696,7 +12696,7 @@ mockedApiResponse.PagesCollection = [ "meta_key": "" }, "class_list": [ - "post-7", + "post-2393", "page", "type-page", "status-publish", @@ -12787,7 +12787,7 @@ mockedApiResponse.PageModel = { "meta_key": "" }, "class_list": [ - "post-7", + "post-2393", "page", "type-page", "status-publish", @@ -12975,7 +12975,7 @@ mockedApiResponse.MediaCollection = [ "meta_key": "" }, "class_list": [ - "post-10", + "post-2396", "attachment", "type-attachment", "status-inherit", @@ -13044,7 +13044,7 @@ mockedApiResponse.MediaModel = { "meta_key": "" }, "class_list": [ - "post-10", + "post-2396", "attachment", "type-attachment", "status-inherit", From 4a7051f5637d39577021a15f132a2b64a81b34f4 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 01:26:53 +0200 Subject: [PATCH 08/17] Normalize dynamic data. --- .../tests/rest-api/rest-schema-setup.php | 23 +++++++++++-------- tests/qunit/fixtures/wp-api-generated.js | 12 +++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 3296f15905c44..d32a43ed03657 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -760,16 +760,21 @@ private function normalize_fixture( $data, $path ) { } foreach ( $data as $key => $value ) { - if ( is_string( $value ) && ( - 'date' === $key || - 'date_gmt' === $key || - 'modified' === $key || - 'modified_gmt' === $key - ) ) { - $data[ $key ] = '2017-02-14T00:00:00'; - } else { - $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); + $datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' ); + + if ( is_string( $value ) ) { + if ( in_array( $key, $datetime_keys, true ) ) { + $data[ $key ] = '2017-02-14T00:00:00'; + continue; + } + + if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { + $data[ $key ] = 'post-1073'; + continue; + } } + + $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); } return $data; diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 21c11117aeabd..9f98c528e9587 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -12387,7 +12387,7 @@ mockedApiResponse.PostsCollection = [ ], "tags": [], "class_list": [ - "post-2390", + "post-1073", "post", "type-post", "status-publish", @@ -12496,7 +12496,7 @@ mockedApiResponse.PostModel = { ], "tags": [], "class_list": [ - "post-2390", + "post-1073", "post", "type-post", "status-publish", @@ -12696,7 +12696,7 @@ mockedApiResponse.PagesCollection = [ "meta_key": "" }, "class_list": [ - "post-2393", + "post-1073", "page", "type-page", "status-publish", @@ -12787,7 +12787,7 @@ mockedApiResponse.PageModel = { "meta_key": "" }, "class_list": [ - "post-2393", + "post-1073", "page", "type-page", "status-publish", @@ -12975,7 +12975,7 @@ mockedApiResponse.MediaCollection = [ "meta_key": "" }, "class_list": [ - "post-2396", + "post-1073", "attachment", "type-attachment", "status-inherit", @@ -13044,7 +13044,7 @@ mockedApiResponse.MediaModel = { "meta_key": "" }, "class_list": [ - "post-2396", + "post-1073", "attachment", "type-attachment", "status-inherit", From c393ade963e43b2ce208d75b9e1a74ef2780823c Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 01:29:07 +0200 Subject: [PATCH 09/17] Don't use "" for concatenation. --- tests/phpunit/tests/rest-api/rest-schema-setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index d32a43ed03657..ed66a8a49d049 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -774,7 +774,7 @@ private function normalize_fixture( $data, $path ) { } } - $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); + $data[ $key ] = $this->normalize_fixture( $value, $path . $key ); } return $data; From 4b973520ce24f907e02f1c7270a4bc1a6b047506 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 01:37:12 +0200 Subject: [PATCH 10/17] Fix fixtures. --- tests/qunit/fixtures/wp-api-generated.js | 64 ------------------------ 1 file changed, 64 deletions(-) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 9f98c528e9587..250c64cff1e5d 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -669,14 +669,6 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "title": { "description": "The title for the post.", "type": "object", @@ -961,14 +953,6 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "title": { "description": "The title for the post.", "type": "object", @@ -1408,14 +1392,6 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "title": { "description": "The title for the post.", "type": "object", @@ -1891,14 +1867,6 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "parent": { "description": "The ID for the parent of the post.", "type": "integer", @@ -2155,14 +2123,6 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "parent": { "description": "The ID for the parent of the post.", "type": "integer", @@ -2574,14 +2534,6 @@ mockedApiResponse.Schema = { "type": "string", "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "title": { "description": "The title for the post.", "type": "object", @@ -3016,14 +2968,6 @@ mockedApiResponse.Schema = { ], "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "title": { "description": "The title for the post.", "type": "object", @@ -3231,14 +3175,6 @@ mockedApiResponse.Schema = { ], "required": false }, - "class_list": { - "description": "An array of the class names for the post container element.", - "type": "array", - "items": { - "type": "string" - }, - "required": false - }, "title": { "description": "The title for the post.", "type": "object", From 3124c09209d698b9398cc27884071eeb78491456 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 01:40:06 +0200 Subject: [PATCH 11/17] The `class_list` field should not be mutable. --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 6569cf5e25424..a29f92c56fec7 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -2362,6 +2362,7 @@ public function get_item_schema() { 'description' => __( 'An array of the class names for the post container element.' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), + 'readonly' => true, 'items' => array( 'type' => 'string', ), From 0657411672bcb3b796bd8a64503098ac0dcf86da Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 02:11:24 +0200 Subject: [PATCH 12/17] Small optimization. --- tests/phpunit/tests/rest-api/rest-schema-setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index ed66a8a49d049..67f70d2ae7a06 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -759,9 +759,9 @@ private function normalize_fixture( $data, $path ) { return $data; } - foreach ( $data as $key => $value ) { - $datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' ); + $datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' ); + foreach ( $data as $key => $value ) { if ( is_string( $value ) ) { if ( in_array( $key, $datetime_keys, true ) ) { $data[ $key ] = '2017-02-14T00:00:00'; From 715274ae793955d4b2aab817774bc9067796f363 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 07:34:58 +0200 Subject: [PATCH 13/17] Revert the code to see if it fixes issue with CI jobs. --- .../tests/rest-api/rest-schema-setup.php | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 67f70d2ae7a06..3296f15905c44 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -759,22 +759,17 @@ private function normalize_fixture( $data, $path ) { return $data; } - $datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' ); - foreach ( $data as $key => $value ) { - if ( is_string( $value ) ) { - if ( in_array( $key, $datetime_keys, true ) ) { - $data[ $key ] = '2017-02-14T00:00:00'; - continue; - } - - if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { - $data[ $key ] = 'post-1073'; - continue; - } + if ( is_string( $value ) && ( + 'date' === $key || + 'date_gmt' === $key || + 'modified' === $key || + 'modified_gmt' === $key + ) ) { + $data[ $key ] = '2017-02-14T00:00:00'; + } else { + $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); } - - $data[ $key ] = $this->normalize_fixture( $value, $path . $key ); } return $data; From baf2b50b63cd4a215398d7e77643d52f9ff2c3cd Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 07:47:57 +0200 Subject: [PATCH 14/17] Fix the bug. --- .../tests/rest-api/rest-schema-setup.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 3296f15905c44..1c643574795ad 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -759,17 +759,22 @@ private function normalize_fixture( $data, $path ) { return $data; } + $datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' ); + foreach ( $data as $key => $value ) { - if ( is_string( $value ) && ( - 'date' === $key || - 'date_gmt' === $key || - 'modified' === $key || - 'modified_gmt' === $key - ) ) { - $data[ $key ] = '2017-02-14T00:00:00'; - } else { - $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); + if ( is_string( $value ) ) { + if ( in_array( $key, $datetime_keys, true ) ) { + $data[ $key ] = '2017-02-14T00:00:00'; + continue; + } + + if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { + $data[ $key ] = 'post-1073'; + continue; + } } + + $data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); } return $data; From 48c74a274f864ee4db6c17db2f259bd7d0978997 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 09:43:00 +0200 Subject: [PATCH 15/17] Test hypothesis. --- tests/phpunit/tests/rest-api/rest-schema-setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 1c643574795ad..42ce46dae78bb 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -769,8 +769,8 @@ private function normalize_fixture( $data, $path ) { } if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { - $data[ $key ] = 'post-1073'; - continue; + //$data[ $key ] = 'post-1073'; + //continue; } } From 55864158993f5ac7bfa35b50292bd2e935098ee3 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 09:50:32 +0200 Subject: [PATCH 16/17] Revert "Test hypothesis." This reverts commit 48c74a274f864ee4db6c17db2f259bd7d0978997. --- tests/phpunit/tests/rest-api/rest-schema-setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 42ce46dae78bb..1c643574795ad 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -769,8 +769,8 @@ private function normalize_fixture( $data, $path ) { } if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { - //$data[ $key ] = 'post-1073'; - //continue; + $data[ $key ] = 'post-1073'; + continue; } } From d24ee393411efe9f87ab5e51d2ea6878d7cecc7e Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 4 Jun 2024 10:40:52 +0200 Subject: [PATCH 17/17] Add a comment. --- tests/phpunit/tests/rest-api/rest-schema-setup.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 1c643574795ad..1569e24e42f3b 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -769,6 +769,7 @@ private function normalize_fixture( $data, $path ) { } if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { + // Normalize the class value to ensure test stability. $data[ $key ] = 'post-1073'; continue; }