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

Try/60642 fixture tests #6723

Closed
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
Prev Previous commit
Next Next commit
Debug
  • Loading branch information
anton-vlasenko authored and Anton Vlasenko committed Jun 4, 2024
commit 22e4a4f07c3f18e162a73dd6d6898c56d3bed92e
19 changes: 14 additions & 5 deletions tests/phpunit/tests/rest-api/rest-schema-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ public function test_build_wp_api_client_fixtures() {
);
$this->assertNotEmpty( $data, $route['name'] . ' route should return data.' );

$data['debug_post_id'] = $post_id;
$data['debug_update_post_id'] = $update_post;
$data['debug_page_id'] = $page_id;
$data['debug_update_page_id'] = $update_page;
$fixture = $this->normalize_fixture( $data, $route['name'] );
$mocked_responses .= "\nmockedApiResponse." . $route['name'] . ' = '
. json_encode( $fixture, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES )
Expand Down Expand Up @@ -765,6 +761,19 @@ private function normalize_fixture( $data, $path ) {

$datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' );

global $wpdb;
$posts = $wpdb->get_results("SELECT id, post_title, post_name as slug FROM $wpdb->posts");

//Save all titles
$post_data = array();
foreach( $posts as $post ) {
$post_data[] = $post->id;
$post_data[] = $post->post_title;
$post_data[] = $post->slug;
}

$post_data = implode(',', $post_data);

foreach ( $data as $key => $value ) {
if ( is_string( $value ) ) {
if ( in_array( $key, $datetime_keys, true ) ) {
Expand All @@ -774,7 +783,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';
$data[ $key ] = $post_data;
continue;
}
}
Expand Down