1 | #! /usr/bin/env php |
||
2 | <?php |
||
3 | |||
4 | /** |
||
5 | * Script to test the most important nginx rules |
||
6 | */ |
||
7 | function run(string $cmd): string |
||
8 | { |
||
9 | echo $cmd . PHP_EOL; |
||
10 | |||
11 | return shell_exec($cmd); |
||
1 ignored issue
–
show
Bug
Best Practice
introduced
by
![]() |
|||
12 | } |
||
13 | |||
14 | function test(bool $loggedIn, string $url): void |
||
15 | { |
||
16 | if ($loggedIn) { |
||
17 | $cookie = "--cookie 'PHPSESSID=foo'"; |
||
18 | $pattern = '<img src="assets/logo-artisans-de-la-transition.svg"'; |
||
19 | $message = 'logged in user should get raw Angular'; |
||
20 | } else { |
||
21 | $cookie = ''; |
||
22 | $pattern = '<natural-icon'; |
||
23 | $message = 'anonymous should get pre-rendered page by SSR'; |
||
24 | } |
||
25 | |||
26 | // Assert HTTP status code |
||
27 | $status = run("curl --insecure --silent --output /dev/null --write-out '%{http_code}' '$url' $cookie"); |
||
28 | if ($status !== '200') { |
||
29 | echo "FAILED STATUS CODE: $status: $message" . PHP_EOL; |
||
30 | exit(1); |
||
1 ignored issue
–
show
|
|||
31 | } |
||
32 | |||
33 | // Assert HTML content |
||
34 | $content = run("curl --insecure --silent '$url' $cookie"); |
||
35 | if (mb_strpos($content, $pattern) === false) { |
||
36 | echo "FAILED PATTERN: '$pattern': $message" . PHP_EOL; |
||
37 | exit(1); |
||
1 ignored issue
–
show
|
|||
38 | } |
||
39 | } |
||
40 | |||
41 | test(true, 'https://artisans.lan'); |
||
42 | test(true, 'https://artisans.lan/larevuedurable/numeros'); |
||
43 | test(true, 'https://artisans.lan/mon-compte'); |
||
44 | |||
45 | test(false, 'https://artisans.lan'); |
||
46 | test(false, 'https://artisans.lan/larevuedurable/numeros'); |
||
47 | test(false, 'https://artisans.lan/mon-compte'); |
||
48 | |||
49 | echo 'All tests OK' . PHP_EOL; |
||
50 |