From 8037b9f53ec4ba2ccd86fca510c8e8f2a0b6dcd2 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Thu, 22 Aug 2024 21:21:43 -0400 Subject: [PATCH] Tests: align mock.php with main branch (sans spacing diffs) Ref gh-5531 --- test/data/mock.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/data/mock.php b/test/data/mock.php index 5cff30c34..9e7a96e27 100644 --- a/test/data/mock.php +++ b/test/data/mock.php @@ -59,7 +59,22 @@ class MockServer { } else { header( 'Content-type: text/html' ); } - echo 'QUnit.assert.ok( true, "mock executed" );'; + + if ( !empty( $req->query['cors'] ) ) { + header( "Access-Control-Allow-Origin: *" ); + } + + if ( !empty( $req->query['callback'] ) ) { + $headers = array_combine( + array_map( 'strtolower', array_keys( $req->headers ) ), + array_values( $req->headers ) + ); + + echo cleanCallback( $req->query['callback'] ) . + "(" . json_encode( [ 'headers' => $headers ] ) . ")"; + } else { + echo 'QUnit.assert.ok( true, "mock executed" );'; + } } // Used to be in test.js, but was renamed to testbar.php @@ -75,6 +90,10 @@ QUnit.assert.ok( true, "mock executed");'; header( 'Content-type: application/json' ); } + if ( isset( $req->query['cors'] ) ) { + header( 'Access-Control-Allow-Origin: *' ); + } + if ( isset( $req->query['array'] ) ) { echo '[ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ]'; } else { @@ -196,16 +215,12 @@ QUnit.assert.ok( true, "mock executed");'; } protected function cspFrame( $req ) { - // This is CSP only for browsers with "Content-Security-Policy" header support - // i.e. no old WebKit or old Firefox header( "Content-Security-Policy: default-src 'self'; report-uri ./mock.php?action=cspLog" ); header( 'Content-type: text/html' ); echo file_get_contents( __DIR__ . '/csp.include.html' ); } protected function cspNonce( $req ) { - // This is CSP only for browsers with "Content-Security-Policy" header support - // i.e. no old WebKit or old Firefox $test = $req->query['test'] ? '-' . $req->query['test'] : ''; header( "Content-Security-Policy: script-src 'nonce-jquery+hardcoded+nonce'; report-uri ./mock.php?action=cspLog" ); header( 'Content-type: text/html' );