Skip to content

Commit

Permalink
Add messages to assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Oct 20, 2022
1 parent 45775e0 commit 9bc56a5
Showing 1 changed file with 101 additions and 20 deletions.
121 changes: 101 additions & 20 deletions tests/phpunit/tests/rest-api/rest-block-type-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,57 @@ public function test_get_item_deprecated() {
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$this->assertSameSets( array( 'hello_world' ), $data['editor_script_handles'] );
$this->assertSameSets( array( 'gutenberg' ), $data['script_handles'] );
$this->assertSameSets( array( 'foo_bar' ), $data['view_script_handles'] );
$this->assertSameSets( array( 'guten_tag' ), $data['editor_style_handles'] );
$this->assertSameSets( array( 'out_of_style' ), $data['style_handles'] );
$this->assertSameSets(
array( 'hello_world' ),
$data['editor_script_handles'],
"Endpoint doesn't return correct array for editor_script_handles."
);
$this->assertSameSets(
array( 'gutenberg' ),
$data['script_handles'],
"Endpoint doesn't return correct array for script_handles."
);
$this->assertSameSets(
array( 'foo_bar' ),
$data['view_script_handles'],
"Endpoint doesn't return correct array for view_script_handles."
);
$this->assertSameSets(
array( 'guten_tag' ),
$data['editor_style_handles'],
"Endpoint doesn't return correct array for editor_style_handles."
);
$this->assertSameSets(
array( 'out_of_style' ),
$data['style_handles'],
"Endpoint doesn't return correct array for style_handles."
);
// Deprecated properties.
$this->assertSame( 'hello_world', $data['editor_script'] );
$this->assertSame( 'gutenberg', $data['script'] );
$this->assertSame( 'foo_bar', $data['view_script'] );
$this->assertSame( 'guten_tag', $data['editor_style'] );
$this->assertSame( 'out_of_style', $data['style'] );
$this->assertSame(
'hello_world',
$data['editor_script'],
"Endpoint doesn't return correct string for editor_script."
);
$this->assertSame(
'gutenberg',
$data['script'],
"Endpoint doesn't return correct string for script."
);
$this->assertSame(
'foo_bar',
$data['view_script'],
"Endpoint doesn't return correct string for view_script."
);
$this->assertSame(
'guten_tag',
$data['editor_style'],
"Endpoint doesn't return correct string for editor_style."
);
$this->assertSame(
'out_of_style',
$data['style'],
"Endpoint doesn't return correct string for style."
);
}

/**
Expand All @@ -385,18 +425,59 @@ public function test_get_item_deprecated_with_arrays() {
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$this->assertSameSets( $settings['editor_script'], $data['editor_script_handles'] );
$this->assertSameSets( $settings['script'], $data['script_handles'] );
$this->assertSameSets( $settings['view_script'], $data['view_script_handles'] );
$this->assertSameSets( $settings['editor_style'], $data['editor_style_handles'] );
$this->assertSameSets( $settings['style'], $data['style_handles'] );
$this->assertSameSets(
$settings['editor_script'],
$data['editor_script_handles'],
"Endpoint doesn't return correct array for editor_script_handles."
);
$this->assertSameSets(
$settings['script'],
$data['script_handles'],
"Endpoint doesn't return correct array for script_handles."
);
$this->assertSameSets(
$settings['view_script'],
$data['view_script_handles'],
"Endpoint doesn't return correct array for view_script_handles."
);
$this->assertSameSets(
$settings['editor_style'],
$data['editor_style_handles'],
"Endpoint doesn't return correct array for editor_style_handles."
);
$this->assertSameSets(
$settings['style'],
$data['style_handles'],
"Endpoint doesn't return correct array for style_handles."
);
// Deprecated properties.
// Since the schema only allows strings or null (but no arrays), we return the first array item.
$this->assertSame( 'hello', $data['editor_script'] );
$this->assertSame( 'gutenberg', $data['script'] );
$this->assertSame( 'foo', $data['view_script'] );
$this->assertSame( 'guten', $data['editor_style'] );
$this->assertSame( 'out', $data['style'] );
// Deprecated properties.
$this->assertSame(
'hello',
$data['editor_script'],
"Endpoint doesn't return first array element for editor_script."
);
$this->assertSame(
'gutenberg',
$data['script'],
"Endpoint doesn't return first array element for script."
);
$this->assertSame(
'foo',
$data['view_script'],
"Endpoint doesn't return first array element for view_script."
);
$this->assertSame(
'guten',
$data['editor_style'],
"Endpoint doesn't return first array element for editor_style."
);
$this->assertSame(
'out',
$data['style'],
"Endpoint doesn't return first array element for style."
);
}

public function test_get_variation() {
Expand Down

0 comments on commit 9bc56a5

Please sign in to comment.