dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxMissingResources_test.php
Go to the documentation of this file.
1<?php
2
4 public array $system = array();
5 public array $logged = array();
6
7 public function get_system_var(string $key, $default = '', string $rules = '') {
8 return $this->system[$key] ?? $default;
9 }
10
11 public function get_base_dir(): string {
12 return rtrim(str_replace('\\', '/', dirname(__DIR__, 3)), '/') . '/';
13 }
14
15 public function log_missing($missing = ''): int {
16 $this->logged[] = (string)$missing;
17 return count($this->logged);
18 }
19
20 public function debug(...$values): void {
21 }
22}
23
24$GLOBALS['dbxMissingResourcesTestApi'] = new dbxMissingResourcesTestApi();
26 return $GLOBALS['dbxMissingResourcesTestApi'];
27}
28
29require_once dirname(__DIR__) . '/dbxWebApp.class.php';
30
31$api = $GLOBALS['dbxMissingResourcesTestApi'];
33
34$fail = static function (string $message, int $code): void {
35 fwrite(STDERR, "FAIL: $message\n");
36 exit($code);
37};
38
40 'js', 'mjs', 'css', 'map', 'json', 'wasm',
41 'png', 'jpg', 'svg', 'webp', 'avif', 'ico',
42 'woff', 'woff2', 'ttf', 'pdf', 'zip', 'mp3', 'mp4',
43);
44foreach ($resourceExtensions as $extension) {
45 if ($web->get_is_resorce($extension) !== 1) {
46 $fail("Ressourcenerweiterung .$extension wird nicht erkannt.", 1);
47 }
48}
49
50foreach (array('', 'html', 'htm', 'php', 'dbx') as $extension) {
51 if ($web->get_is_resorce($extension) !== 0) {
52 $fail("Seiten-/Programmerweiterung .$extension wird faelschlich als Ressource erkannt.", 2);
53 }
54}
55
56$_SERVER['REQUEST_METHOD'] = 'GET';
57$_SERVER['HTTP_HOST'] = 'dbxapp.de';
58$_SERVER['HTTP_REFERER'] = 'https://www.dbxapp.de/home?preview=1';
59$api->system['dbx_permalink'] = 'assets/__dbx-missing-resource-test__.svg';
60http_response_code(200);
61ob_start();
62$handled = $web->check_missing();
63$body = ob_get_clean();
64if (!$handled || http_response_code() !== 404 || $body !== ''
65 || $api->logged !== array('assets/__dbx-missing-resource-test__.svg')) {
66 $fail('Fehlendes SVG wird nicht leer mit HTTP 404 protokolliert.', 3);
67}
68
69unset($_SERVER['HTTP_REFERER']);
70$api->system['dbx_permalink'] = 'api/openapi.json';
71http_response_code(200);
72if (!$web->check_missing() || http_response_code() !== 404 || count($api->logged) !== 1) {
73 $fail('Direkte Bot-/Scanner-Anfrage ohne interne Herkunft wird protokolliert.', 4);
74}
75
76$_SERVER['HTTP_REFERER'] = 'https://scanner.example/probe';
77$api->system['dbx_permalink'] = 'api/swagger.json';
78http_response_code(200);
79if (!$web->check_missing() || http_response_code() !== 404 || count($api->logged) !== 1) {
80 $fail('Externe Ressourcenanfrage wird als interner Seitenfehler protokolliert.', 5);
81}
82
83$api->system['dbx_permalink'] = 'assets/__dbx-missing-resource-test__%2Ewoff2';
84$_SERVER['HTTP_REFERER'] = 'https://dbxapp.de/home';
85http_response_code(200);
86$handled = $web->check_missing();
87if (!$handled || http_response_code() !== 404 || count($api->logged) !== 2) {
88 $fail('URL-kodierte Ressourcenerweiterung wird nicht erkannt.', 6);
89}
90
91$_SERVER['REQUEST_METHOD'] = 'HEAD';
92$api->system['dbx_permalink'] = 'assets/__dbx-missing-resource-test__.js';
93http_response_code(200);
94ob_start();
95$handled = $web->check_missing();
96$body = ob_get_clean();
97if (!$handled || http_response_code() !== 404 || $body !== '' || count($api->logged) !== 3) {
98 $fail('HEAD fuer eine fehlende Ressource ist nicht konsistent.', 7);
99}
100
101$resourceFileMethod = new ReflectionMethod(dbxWebApp::class, 'get_resource_file');
102$appleIconFile = (string)$resourceFileMethod->invoke($web, 'apple-touch-icon.png');
103if ($appleIconFile === '' || realpath($appleIconFile) !== realpath(dirname(__DIR__, 3) . '/favicon.png')) {
104 $fail('Der Standardpfad apple-touch-icon.png wird nicht auf das vorhandene Favicon aufgeloest.', 8);
105}
106
107$defaultTemplate = (string)file_get_contents(dirname(__DIR__, 2) . '/design/dbxapp/htm/default.htm');
108if (!str_contains($defaultTemplate, 'rel="apple-touch-icon"')) {
109 $fail('Das dbxapp-Design deklariert kein Apple-Touch-Icon.', 9);
110}
111
112$_SERVER['REQUEST_METHOD'] = 'GET';
113foreach (array('shop/produkt', 'hilfe/seite.html', 'sitemap.xml', 'robots.txt') as $route) {
114 $api->system['dbx_permalink'] = $route;
115 http_response_code(200);
116 if ($web->check_missing() || http_response_code() !== 200) {
117 $fail("Normale/dynamische Route $route wird faelschlich als Ressource behandelt.", 10);
118 }
119}
120if (count($api->logged) !== 3) {
121 $fail('Normale Seiten oder Systemrouten wurden protokolliert.', 11);
122}
123
124echo "OK dbxMissing resources\n";
get_system_var(string $key, $default='', string $rules='')
Bereitet den aktuellen HTTP-Request fuer dbXapp vor.
$_SERVER['REQUEST_METHOD']
if(! $handled||http_response_code() !==404|| $body !==''||count($api->logged) !==3) $resourceFileMethod
$api system['dbx_permalink']
if($appleIconFile===''||realpath($appleIconFile) !==realpath(dirname(__DIR__, 3) . '/favicon.png')) $defaultTemplate
$GLOBALS['dbxMissingResourcesTestApi']
if($out !==$expected) $missing
exit
Definition index.php:146