dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxApi_missing_log_test.php
Go to the documentation of this file.
1<?php
2
3require_once dirname(__DIR__) . '/dbxApi.php';
4
6 public array $rows = array();
7 public bool $transaction = false;
8 public int $begins = 0;
9 public int $commits = 0;
10 public int $rollbacks = 0;
11 private int $insertId = 0;
12
13 public function begin(string $dd): int {
14 if ($dd !== 'dbxMissing' || $this->transaction) return 0;
15 $this->transaction = true;
16 $this->begins++;
17 return 1;
18 }
19
20 public function rollback(string $dd): int {
21 $this->transaction = false;
22 $this->rollbacks++;
23 return 1;
24 }
25
26 public function commit(string $dd): int {
27 if (!$this->transaction) return 0;
28 $this->transaction = false;
29 $this->commits++;
30 return 1;
31 }
32
33 public function select1(string $dd, array $where, string $fields, int $verifyAccess) {
34 foreach ($this->rows as $row) {
35 if ($row['missing'] === $where['missing']) {
36 return array('id' => $row['id'], 'count' => $row['count']);
37 }
38 }
39 return array();
40 }
41
42 public function update(string $dd, array $values, $id, ...$options): int {
43 if (!$this->transaction) return 0;
44 foreach ($this->rows as &$row) {
45 if ((int)$row['id'] === (int)$id) {
46 $row = array_merge($row, $values);
47 unset($row);
48 return 1;
49 }
50 }
51 unset($row);
52 return 0;
53 }
54
55 public function insert(string $dd, array $values, ...$options): int {
56 if (!$this->transaction) return 0;
57 $this->insertId++;
58 $values['id'] = $this->insertId;
59 $this->rows[] = $values;
60 return 1;
61 }
62
63 public function get_insert_id(): int {
64 return $this->insertId;
65 }
66}
67
70 public array $errors = array();
71
72 public function __construct() {
73 $this->testDb = new dbxMissingLogTestDb();
74 }
75
76 public function get_system_obj(string $class, string $use = ''): ?object {
77 return $class === 'dbxDB' ? $this->testDb : null;
78 }
79
80 public function user($key = 'id') {
81 return 0;
82 }
83
84 public function write_php_error_log(string $type, string $message, string $file = '', int $line = 0): void {
85 $this->errors[] = $type . ': ' . $message;
86 }
87}
88
89$fail = static function (string $message, int $code): void {
90 fwrite(STDERR, "FAIL: $message\n");
91 exit($code);
92};
93
95$_SERVER['HTTP_REFERER'] = 'https://localhost/dbxapp/home/tutorial?token=secret#bereich';
96
97$firstId = $api->log_missing('assets/missing.svg');
98$secondId = $api->log_missing('assets/missing.svg');
99
100if ($firstId !== 1 || $secondId !== 1 || count($api->testDb->rows) !== 1
101 || (int)$api->testDb->rows[0]['count'] !== 2) {
102 $fail('Wiederholte Ressourcenfehler werden nicht in einer Zeile gezaehlt.', 1);
103}
104
105if (($api->testDb->rows[0]['request'] ?? '') !== 'https://localhost/dbxapp/home/tutorial') {
106 $fail('Aufrufende Seite wird nicht ohne sensible Querydaten gespeichert.', 2);
107}
108
109if ($api->testDb->begins !== 2 || $api->testDb->commits !== 2
110 || $api->testDb->rollbacks !== 0 || $api->testDb->transaction) {
111 $fail('dbxMissing-Schreibvorgaenge sind nicht sauber transaktional.', 3);
112}
113
114if ($api->log_missing('') !== 0 || $api->testDb->begins !== 2 || $api->errors !== array()) {
115 $fail('Leere Eintraege werden nicht sauber ignoriert.', 4);
116}
117
118echo "OK dbxApi missing log\n";
Zentrale Laufzeit-API von dbXapp.
Definition dbxApi.php:39
get_system_obj(string $class, string $use='')
Laedt ein Systemobjekt aus dbx/include und bevorzugt den myX-Override.
write_php_error_log(string $type, string $message, string $file='', int $line=0)
select1(string $dd, array $where, string $fields, int $verifyAccess)
insert(string $dd, array $values,... $options)
update(string $dd, array $values, $id,... $options)
$_SERVER['REQUEST_METHOD']
if( $firstId !==1||$secondId !==1||count( $api->testDb->rows) !==1||(int) $api->testDb->rows[0][ 'count'] !==2) if(($api->testDb->rows[0]['request'] ?? '') !=='https://localhost/dbxapp/home/tutorial') if( $api->testDb->begins !==2||$api->testDb->commits !==2||$api->testDb->rollbacks !==0||$api->testDb->transaction) if( $api->log_missing('') !==0||$api->testDb->begins !==2||$api->errors !==array())
$existingDb rows['dbx|dbxUser'][]
exit
Definition index.php:146