Tests: align mock.php with main branch (sans spacing diffs)

Ref gh-5531
This commit is contained in:
Timmy Willison 2024-08-22 21:21:43 -04:00
parent ed18576506
commit 8037b9f53e

View File

@ -59,8 +59,23 @@ class MockServer {
} else {
header( 'Content-type: text/html' );
}
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
// https://github.com/jquery/jquery/commit/d89c278a33#commitcomment-23423165
@ -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' );