|
2 | 2 | /** |
3 | 3 | * Usage: |
4 | 4 | * |
5 | | - * $ php test/cfp-php.php |
6 | | - * $ php test/cfp-php.php "localhost:4000" |
7 | | - * $ TEST_SERVER="localhost:4000" php test/cfp-php.php |
| 5 | + * $ php test/static-dev.php |
| 6 | + * |
| 7 | + * $ php test/static-dev.php "localhost:4000" |
8 | 8 | */ |
9 | 9 |
|
10 | | -$server = getenv( 'TEST_SERVER' ) ?: @$argv[1] ?: 'localhost:4000'; |
| 10 | +require_once __DIR__ . '/Unit.php'; |
| 11 | +$server = @$argv[1] ?: 'localhost:4000'; |
11 | 12 |
|
12 | 13 | Unit::start(); |
13 | 14 |
|
14 | 15 | // Domain root |
15 | 16 |
|
16 | | -Unit::testHttp( $server, '/', [ |
| 17 | +Unit::testHttp( $server, '/', [], [ |
17 | 18 | 'status' => '301 Moved Permanently', |
18 | 19 | 'server' => 'nginx', |
19 | 20 | 'location' => 'https://releases.jquery.com/', |
20 | 21 | ] ); |
21 | 22 |
|
22 | 23 | // Static assets |
23 | 24 |
|
24 | | -Unit::testHttp( $server, '/jquery-3.0.0.js', [ |
| 25 | +Unit::testHttp( $server, '/jquery-3.0.0.js', [], [ |
25 | 26 | 'status' => '200 OK', |
26 | 27 | 'server' => 'nginx', |
27 | 28 | 'content-type' => 'application/javascript; charset=utf-8', |
28 | 29 | 'content-length' => '263268', |
29 | 30 | 'last-modified' => 'Fri, 18 Oct 1991 12:00:00 GMT', |
30 | 31 | 'connection' => 'keep-alive', |
31 | | - 'vary' => 'Accept-Encoding', |
| 32 | + 'vary' => 'Accept-Encoding, x-cdn-access', |
32 | 33 | 'etag' => '"28feccc0-40464"', |
33 | 34 | 'expires' => 'Thu, 31 Dec 2037 23:55:55 GMT', |
34 | | - 'cache-control' => 'max-age=315360000, public', |
| 35 | + 'cache-control' => 'max-age=315360000, public, no-transform', |
35 | 36 | 'access-control-allow-origin' => '*', |
36 | 37 | 'accept-ranges' => 'bytes', |
37 | 38 | ] ); |
38 | 39 |
|
39 | | -Unit::testHttp( $server, '/qunit/qunit-2.0.0.css', [ |
| 40 | +Unit::testHttp( $server, '/qunit/qunit-2.0.0.css', [], [ |
40 | 41 | 'status' => '200 OK', |
41 | 42 | 'server' => 'nginx', |
42 | 43 | 'content-type' => 'text/css', |
43 | 44 | 'content-length' => '7456', |
44 | 45 | 'last-modified' => 'Fri, 18 Oct 1991 12:00:00 GMT', |
45 | 46 | 'connection' => 'keep-alive', |
46 | | - 'vary' => 'Accept-Encoding', |
| 47 | + 'vary' => 'Accept-Encoding, x-cdn-access', |
47 | 48 | 'etag' => '"28feccc0-1d20"', |
48 | 49 | 'expires' => 'Thu, 31 Dec 2037 23:55:55 GMT', |
49 | | - 'cache-control' => 'max-age=315360000, public', |
| 50 | + 'cache-control' => 'max-age=315360000, public, no-transform', |
50 | 51 | 'access-control-allow-origin' => '*', |
51 | 52 | 'accept-ranges' => 'bytes', |
52 | 53 | ] ); |
53 | 54 |
|
54 | | -Unit::testHttp( $server, '/ui/1.10.0/themes/base/images/ui-icons_222222_256x240.png', [ |
| 55 | +Unit::testHttp( $server, '/ui/1.10.0/themes/base/images/ui-icons_222222_256x240.png', [], [ |
55 | 56 | 'status' => '200 OK', |
56 | 57 | 'server' => 'nginx', |
57 | 58 | 'content-type' => 'image/png', |
|
60 | 61 | 'connection' => 'keep-alive', |
61 | 62 | 'etag' => '"28feccc0-1111"', |
62 | 63 | 'expires' => 'Thu, 31 Dec 2037 23:55:55 GMT', |
63 | | - 'cache-control' => 'max-age=315360000, public', |
| 64 | + 'cache-control' => 'max-age=315360000, public, no-transform', |
64 | 65 | 'access-control-allow-origin' => '*', |
65 | 66 | 'accept-ranges' => 'bytes', |
66 | 67 | ] ); |
67 | 68 |
|
68 | | -Unit::testHttp( $server, '/jquery-2.0.0.min.map', [ |
| 69 | +Unit::testHttp( $server, '/jquery-2.0.0.min.map', [], [ |
69 | 70 | 'status' => '200 OK', |
70 | 71 | 'server' => 'nginx', |
71 | 72 | 'content-type' => 'application/octet-stream', |
|
74 | 75 | 'connection' => 'keep-alive', |
75 | 76 | 'etag' => '"28feccc0-1ec81"', |
76 | 77 | 'expires' => 'Thu, 31 Dec 2037 23:55:55 GMT', |
77 | | - 'cache-control' => 'max-age=315360000, public', |
| 78 | + 'cache-control' => 'max-age=315360000, public, no-transform', |
78 | 79 | 'access-control-allow-origin' => '*', |
79 | 80 | 'accept-ranges' => 'bytes', |
80 | 81 | ] ); |
81 | 82 |
|
82 | 83 | // Renamed files |
83 | 84 |
|
84 | | -Unit::testHttp( $server, '/jquery-git2.js', [ |
| 85 | +Unit::testHttp( $server, '/jquery-git2.js', [], [ |
85 | 86 | 'status' => '301 Moved Permanently', |
86 | 87 | 'server' => 'nginx', |
87 | 88 | 'location' => 'https://code.jquery.com/jquery-git.js', |
88 | 89 | ] ); |
89 | 90 |
|
90 | 91 | // Moved to releases, WordPress page |
91 | 92 |
|
92 | | -Unit::testHttp( $server, '/jquery/', [ |
| 93 | +Unit::testHttp( $server, '/jquery/', [], [ |
93 | 94 | 'status' => '301 Moved Permanently', |
94 | 95 | 'server' => 'nginx', |
95 | 96 | 'location' => 'https://releases.jquery.com/jquery/', |
96 | 97 | ] ); |
97 | 98 |
|
98 | 99 | // Moved to releases, WordPress page without trailing slash |
99 | 100 |
|
100 | | -Unit::testHttp( $server, '/jquery', [ |
| 101 | +Unit::testHttp( $server, '/jquery', [], [ |
101 | 102 | 'status' => '301 Moved Permanently', |
102 | 103 | 'server' => 'nginx', |
103 | 104 | 'location' => 'https://releases.jquery.com/jquery/', |
104 | 105 | ] ); |
105 | 106 |
|
106 | 107 | // Moved to releases, root -git file |
107 | 108 |
|
108 | | -Unit::testHttp( $server, '/jquery-git.js', [ |
| 109 | +Unit::testHttp( $server, '/jquery-git.js', [], [ |
109 | 110 | 'status' => '301 Moved Permanently', |
110 | 111 | 'server' => 'nginx', |
111 | 112 | 'location' => 'https://releases.jquery.com/git/jquery-git.js', |
112 | 113 | ] ); |
113 | 114 |
|
114 | 115 | // Moved to releases, nested -git file |
115 | 116 |
|
116 | | -Unit::testHttp( $server, '/color/jquery.color-git.min.js', [ |
| 117 | +Unit::testHttp( $server, '/color/jquery.color-git.min.js', [], [ |
117 | 118 | 'status' => '301 Moved Permanently', |
118 | 119 | 'server' => 'nginx', |
119 | 120 | 'location' => 'https://releases.jquery.com/git/color/jquery.color-git.min.js', |
120 | 121 | ] ); |
121 | 122 |
|
122 | | -Unit::testHttp( $server, '/qunit/qunit-git.css', [ |
| 123 | +Unit::testHttp( $server, '/qunit/qunit-git.css', [], [ |
123 | 124 | 'status' => '301 Moved Permanently', |
124 | 125 | 'server' => 'nginx', |
125 | 126 | 'location' => 'https://releases.jquery.com/git/qunit/qunit-git.css', |
126 | 127 | ] ); |
127 | 128 |
|
128 | | -Unit::testHttp( $server, '/mobile/git/jquery.mobile-git.min.map', [ |
| 129 | +Unit::testHttp( $server, '/mobile/git/jquery.mobile-git.min.map', [], [ |
129 | 130 | 'status' => '301 Moved Permanently', |
130 | 131 | 'server' => 'nginx', |
131 | 132 | 'location' => 'https://releases.jquery.com/git/mobile/git/jquery.mobile-git.min.map', |
132 | 133 | ] ); |
133 | 134 |
|
134 | 135 | // Moved to releases, any file under /mobile/git |
135 | 136 |
|
136 | | -Unit::testHttp( $server, '/mobile/git/images/icons-png/power-black.png', [ |
| 137 | +Unit::testHttp( $server, '/mobile/git/images/icons-png/power-black.png', [], [ |
137 | 138 | 'status' => '301 Moved Permanently', |
138 | 139 | 'server' => 'nginx', |
139 | 140 | 'location' => 'https://releases.jquery.com/git/mobile/git/images/icons-png/power-black.png', |
140 | 141 | ] ); |
141 | 142 |
|
142 | 143 | // Moved to releases, any file under /git (new-style URL) |
143 | 144 |
|
144 | | -Unit::testHttp( $server, '/git/qunit/qunit-git.css', [ |
| 145 | +Unit::testHttp( $server, '/git/qunit/qunit-git.css', [], [ |
145 | 146 | 'status' => '301 Moved Permanently', |
146 | 147 | 'server' => 'nginx', |
147 | 148 | 'location' => 'https://releases.jquery.com/git/qunit/qunit-git.css', |
148 | 149 | ] ); |
149 | 150 |
|
150 | 151 | Unit::end(); |
151 | | - |
152 | | -function jq_req( $url ) { |
153 | | - print "# $url\n"; |
154 | | - $ch = curl_init( $url ); |
155 | | - $resp = [ 'headers' => [], 'body' => null ]; |
156 | | - curl_setopt_array( $ch, [ |
157 | | - CURLOPT_RETURNTRANSFER => 1, |
158 | | - CURLOPT_FOLLOWLOCATION => 0, |
159 | | - CURLOPT_HEADERFUNCTION => function( $ch, $header ) use ( &$resp ) { |
160 | | - $len = strlen( $header ); |
161 | | - if ( preg_match( "/^(HTTP\/(?:1\.[01]|2)) (\d{3} .*)/", $header, $m ) ) { |
162 | | - $resp['headers'] = []; |
163 | | - $resp['headers']['status'] = trim( $m[2] ); |
164 | | - } else { |
165 | | - $parts = explode( ':', $header, 2 ); |
166 | | - if ( count( $parts ) === 2 ) { |
167 | | - $name = strtolower( $parts[0] ); |
168 | | - $val = trim( $parts[1] ); |
169 | | - if ( isset( $resp['headers'][$name] ) ) { |
170 | | - $resp['headers'][$name] .= ", $val"; |
171 | | - } else { |
172 | | - $resp['headers'][$name] = $val; |
173 | | - } |
174 | | - } |
175 | | - } |
176 | | - return $len; |
177 | | - }, |
178 | | - ] ); |
179 | | - try { |
180 | | - $ret = curl_exec( $ch ); |
181 | | - if ( $ret === false ) { |
182 | | - throw new Exception( curl_error( $ch ) ); |
183 | | - } |
184 | | - $resp['body'] = $ret; |
185 | | - return $resp; |
186 | | - } finally { |
187 | | - curl_close( $ch ); |
188 | | - } |
189 | | -} |
190 | | - |
191 | | -class Unit { |
192 | | - static $i = 0; |
193 | | - static $pass = true; |
194 | | - |
195 | | - public static function start() { |
196 | | - error_reporting( E_ALL ); |
197 | | - print "TAP version 13\n"; |
198 | | - } |
199 | | - |
200 | | - public static function test( $name, $actual, $expected ) { |
201 | | - $num = ++self::$i; |
202 | | - if ( $actual === $expected ) { |
203 | | - print "ok $num $name\n"; |
204 | | - } else { |
205 | | - self::$pass = false; |
206 | | - print "not ok $num $name\n ---\n actual: " |
207 | | - . json_encode( $actual, JSON_UNESCAPED_SLASHES ) . "\n expected: " |
208 | | - . json_encode( $expected, JSON_UNESCAPED_SLASHES ) . "\n"; |
209 | | - } |
210 | | - } |
211 | | - |
212 | | - public static function testHttp( $server, $path, array $expectHeaders, $expectBody = null ) { |
213 | | - try { |
214 | | - $resp = jq_req( "http://{$server}{$path}" ); |
215 | | - foreach ( $expectHeaders as $key => $val ) { |
216 | | - self::test( "GET $path > header $key", @$resp['headers'][$key], $val ); |
217 | | - } |
218 | | - } catch ( Exception $e ) { |
219 | | - self::test( "GET $path > error", $e->getMessage(), null ); |
220 | | - } |
221 | | - } |
222 | | - |
223 | | - public static function end() { |
224 | | - print '1..' . self::$i . "\n"; |
225 | | - if ( !self::$pass ) { |
226 | | - exit( 1 ); |
227 | | - } |
228 | | - } |
229 | | -} |
0 commit comments