Skip to content

Commit 9f3a80c

Browse files
committed
Improve tests for send_validate_response
1 parent cdc0132 commit 9f3a80c

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

tests/php/test-class-amp-theme-support.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,11 +1900,23 @@ public function test_prepare_response_for_validating_non_amp_page() {
19001900
/** @return array */
19011901
public function get_data_to_test_prepare_response_for_validating_amp_page() {
19021902
return [
1903-
'no-store' => [
1904-
false,
1903+
'no-store' => [
1904+
'args' => [
1905+
AMP_Validation_Manager::VALIDATE_QUERY_VAR_NONCE => AMP_Validation_Manager::get_amp_validate_nonce(),
1906+
],
19051907
],
1906-
'store' => [
1907-
true,
1908+
'store' => [
1909+
'args' => [
1910+
AMP_Validation_Manager::VALIDATE_QUERY_VAR_NONCE => AMP_Validation_Manager::get_amp_validate_nonce(),
1911+
AMP_Validation_Manager::VALIDATE_QUERY_VAR_CACHE => true,
1912+
],
1913+
],
1914+
'store_but_omit_styleshets' => [
1915+
'args' => [
1916+
AMP_Validation_Manager::VALIDATE_QUERY_VAR_NONCE => AMP_Validation_Manager::get_amp_validate_nonce(),
1917+
AMP_Validation_Manager::VALIDATE_QUERY_VAR_CACHE => true,
1918+
AMP_Validation_Manager::VALIDATE_QUERY_VAR_OMIT_STYLESHEETS => true,
1919+
],
19081920
],
19091921
];
19101922
}
@@ -1915,34 +1927,33 @@ public function get_data_to_test_prepare_response_for_validating_amp_page() {
19151927
* @dataProvider get_data_to_test_prepare_response_for_validating_amp_page
19161928
* @covers AMP_Theme_Support::prepare_response()
19171929
* @covers AMP_Validation_Manager::send_validate_response()
1918-
*
1919-
* @param bool $store Whether to store results.
19201930
*/
1921-
public function test_prepare_response_for_validating_amp_page( $store ) {
1931+
public function test_prepare_response_for_validating_amp_page( $args ) {
19221932
wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) );
19231933
$this->set_template_mode( AMP_Theme_Support::STANDARD_MODE_SLUG );
19241934
$this->go_to( '/' );
19251935

1926-
$_GET[ AMP_Validation_Manager::VALIDATE_QUERY_VAR ] = [
1927-
AMP_Validation_Manager::VALIDATE_QUERY_VAR_NONCE => AMP_Validation_Manager::get_amp_validate_nonce(),
1928-
];
1929-
if ( $store ) {
1930-
$_GET[ AMP_Validation_Manager::VALIDATE_QUERY_VAR ][ AMP_Validation_Manager::VALIDATE_QUERY_VAR_CACHE ] = 'true';
1931-
}
1936+
$_GET[ AMP_Validation_Manager::VALIDATE_QUERY_VAR ] = $args;
19321937
AMP_Validation_Manager::init_validate_request();
1933-
$response = AMP_Theme_Support::prepare_response( '<html amp><head></head><body><amp-layout layout="bad"></amp-layout></body></html>' );
1938+
AMP_Theme_Support::finish_init();
1939+
$response = AMP_Theme_Support::prepare_response( '<html amp><head><style>body{color:red}</style></head><body><amp-layout layout="bad"></amp-layout></body></html>' );
19341940
$this->assertJson( $response );
19351941
$data = json_decode( $response, true );
19361942
$this->assertArrayHasKey( 'http_status_code', $data );
19371943
$this->assertArrayHasKey( 'php_fatal_error', $data );
19381944
$this->assertArrayHasKey( 'queried_object', $data );
19391945
$this->assertArrayHasKey( 'url', $data );
1940-
$this->assertArrayHasKey( 'stylesheets', $data );
1946+
if ( ! empty( $args[ AMP_Validation_Manager::VALIDATE_QUERY_VAR_OMIT_STYLESHEETS ] ) ) {
1947+
$this->assertArrayNotHasKey( 'stylesheets', $data );
1948+
} else {
1949+
$this->assertArrayHasKey( 'stylesheets', $data );
1950+
}
19411951
$this->assertArrayHasKey( 'results', $data );
19421952
$this->assertCount( 1, $data['results'] );
19431953
$this->assertEquals( 'SPECIFIED_LAYOUT_INVALID', $data['results'][0]['error']['code'] );
1954+
$this->assertTrue( $data['revalidated'] );
19441955

1945-
if ( $store ) {
1956+
if ( ! empty( $args[ AMP_Validation_Manager::VALIDATE_QUERY_VAR_CACHE ] ) ) {
19461957
$this->assertArrayHasKey( 'validated_url_post', $data );
19471958
$this->assertArrayHasKey( 'id', $data['validated_url_post'] );
19481959
$this->assertArrayHasKey( 'edit_link', $data['validated_url_post'] );

tests/php/validation/test-class-amp-validation-manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,14 +2408,15 @@ function () {
24082408
return;
24092409
}
24102410

2411+
$this->assertJson( $response );
24112412
$data = json_decode( $response, true );
2412-
$this->assertEquals( JSON_ERROR_NONE, json_last_error() );
24132413
$this->assertIsArray( $data );
24142414

24152415
$this->assertArrayHasKey( 'http_status_code', $data );
24162416
$this->assertArrayHasKey( 'php_fatal_error', $data );
24172417
$this->assertArrayHasKey( 'queried_object', $data );
24182418
$this->assertArrayHasKey( 'url', $data );
2419+
$this->assertFalse( $data['revalidated'] );
24192420
$this->assertEquals( $url, $data['url'] );
24202421
if ( ! empty( $args[ AMP_Validation_Manager::VALIDATE_QUERY_VAR_OMIT_STYLESHEETS ] ) ) {
24212422
$this->assertArrayNotHasKey( 'stylesheets', $data );

0 commit comments

Comments
 (0)