Skip to content

Commit 8037b9f

Browse files
committed
Tests: align mock.php with main branch (sans spacing diffs)
Ref jquerygh-5531
1 parent ed18576 commit 8037b9f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

test/data/mock.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,22 @@ protected function script( $req ) {
5959
} else {
6060
header( 'Content-type: text/html' );
6161
}
62-
echo 'QUnit.assert.ok( true, "mock executed" );';
62+
63+
if ( !empty( $req->query['cors'] ) ) {
64+
header( "Access-Control-Allow-Origin: *" );
65+
}
66+
67+
if ( !empty( $req->query['callback'] ) ) {
68+
$headers = array_combine(
69+
array_map( 'strtolower', array_keys( $req->headers ) ),
70+
array_values( $req->headers )
71+
);
72+
73+
echo cleanCallback( $req->query['callback'] ) .
74+
"(" . json_encode( [ 'headers' => $headers ] ) . ")";
75+
} else {
76+
echo 'QUnit.assert.ok( true, "mock executed" );';
77+
}
6378
}
6479

6580
// Used to be in test.js, but was renamed to testbar.php
@@ -75,6 +90,10 @@ protected function json( $req ) {
7590
header( 'Content-type: application/json' );
7691
}
7792

93+
if ( isset( $req->query['cors'] ) ) {
94+
header( 'Access-Control-Allow-Origin: *' );
95+
}
96+
7897
if ( isset( $req->query['array'] ) ) {
7998
echo '[ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ]';
8099
} else {
@@ -196,16 +215,12 @@ protected function testHTML( $req ) {
196215
}
197216

198217
protected function cspFrame( $req ) {
199-
// This is CSP only for browsers with "Content-Security-Policy" header support
200-
// i.e. no old WebKit or old Firefox
201218
header( "Content-Security-Policy: default-src 'self'; report-uri ./mock.php?action=cspLog" );
202219
header( 'Content-type: text/html' );
203220
echo file_get_contents( __DIR__ . '/csp.include.html' );
204221
}
205222

206223
protected function cspNonce( $req ) {
207-
// This is CSP only for browsers with "Content-Security-Policy" header support
208-
// i.e. no old WebKit or old Firefox
209224
$test = $req->query['test'] ? '-' . $req->query['test'] : '';
210225
header( "Content-Security-Policy: script-src 'nonce-jquery+hardcoded+nonce'; report-uri ./mock.php?action=cspLog" );
211226
header( 'Content-type: text/html' );

0 commit comments

Comments
 (0)