Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fixture replacements for the "class_list" REST API field #6727

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor fixture replacements.
  • Loading branch information
anton-vlasenko authored and Anton Vlasenko committed Jun 4, 2024
commit c15b616135f00860767f5ef8337c01554c50899a
20 changes: 9 additions & 11 deletions tests/phpunit/tests/rest-api/rest-schema-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ public function test_build_wp_api_client_fixtures() {
'oembeds.author_url' => 'http://example.org',
'oembeds.html' => '<blockquote class="wp-embedded-content">...</blockquote>...',
'PostsCollection.0.id' => 4,
'PostsCollection.0.class_list.0' => 'post-4',
'PostsCollection.0.guid.rendered' => 'http://example.org/?p=4',
'PostsCollection.0.link' => 'http://example.org/?p=4',
'PostsCollection.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4',
Expand All @@ -590,6 +591,7 @@ public function test_build_wp_api_client_fixtures() {
'PostsCollection.0._links.wp:term.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4',
'PostsCollection.0._links.wp:term.1.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4',
'PostModel.id' => 4,
'PostModel.class_list.0' => 'post-4',
'PostModel.guid.rendered' => 'http://example.org/?p=4',
'PostModel.link' => 'http://example.org/?p=4',
'postRevisions.0.author' => 2,
Expand Down Expand Up @@ -621,6 +623,7 @@ public function test_build_wp_api_client_fixtures() {
'autosave.slug' => '4-autosave-v1',
'autosave.guid.rendered' => 'http://example.org/?p=6',
'PagesCollection.0.id' => 7,
'PagesCollection.0.class_list.0' => 'post-7',
'PagesCollection.0.guid.rendered' => 'http://example.org/?page_id=7',
'PagesCollection.0.link' => 'http://example.org/?page_id=7',
'PagesCollection.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7',
Expand All @@ -632,6 +635,7 @@ public function test_build_wp_api_client_fixtures() {
'PagesCollection.0._links.predecessor-version.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/9',
'PagesCollection.0._links.wp:attachment.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7',
'PageModel.id' => 7,
'PageModel.class_list.0' => 'post-7',
'PageModel.guid.rendered' => 'http://example.org/?page_id=7',
'PageModel.link' => 'http://example.org/?page_id=7',
'pageRevisions.0.author' => 2,
Expand Down Expand Up @@ -663,6 +667,7 @@ public function test_build_wp_api_client_fixtures() {
'pageAutosave.slug' => '7-autosave-v1',
'pageAutosave.guid.rendered' => 'http://example.org/?p=9',
'MediaCollection.0.id' => 10,
'MediaCollection.0.class_list.0' => 'post-10',
'MediaCollection.0.guid.rendered' => 'http://example.org/?attachment_id=10',
'MediaCollection.0.link' => 'http://example.org/?attachment_id=10',
'MediaCollection.0.description.rendered' => '<p class="attachment"><!-- <a...><img.../></a> --></p>',
Expand All @@ -672,6 +677,7 @@ public function test_build_wp_api_client_fixtures() {
'MediaCollection.0._links.about.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/types/attachment',
'MediaCollection.0._links.replies.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10',
'MediaModel.id' => 10,
'MediaModel.class_list.0' => 'post-10',
'MediaModel.guid.rendered' => 'http://example.org/?attachment_id=10',
'MediaModel.link' => 'http://example.org/?attachment_id=10',
'MediaModel.description.rendered' => '<p class="attachment"><!-- <a...><img.../></a> --></p>',
Expand Down Expand Up @@ -762,17 +768,9 @@ private function normalize_fixture( $data, $path ) {
$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 ) ) {
// Normalize the class value to ensure test stability.
$data[ $key ] = 'post-1073';
continue;
}
if ( is_string( $value ) && in_array( $key, $datetime_keys, true ) ) {
$data[ $key ] = '2017-02-14T00:00:00';
continue;
}

$data[ $key ] = $this->normalize_fixture( $value, "$path.$key" );
Expand Down
Loading