dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
myInvoices_integration_test.php
Go to the documentation of this file.
1<?php
5
6$base = dirname(__DIR__, 4);
7chdir($base);
8$_SERVER['REQUEST_URI'] =
9 '/dbxapp/?dbx_modul=myInvoices&dbx_run1=report';
10$_SERVER['HTTP_HOST'] = 'localhost';
11$_SERVER['HTTPS'] = 'on';
12$_SERVER['SCRIPT_NAME'] = '/dbxapp/index.php';
13$_SERVER['REQUEST_METHOD'] = 'GET';
14
15if (!defined('dbxSystem')) {
16 define('dbxSystem', 'dbxWebApp');
17}
18if (!defined('dbxRunAsAdmin')) {
19 define('dbxRunAsAdmin', 1);
20}
21
22require $base . '/dbx/vendor/autoload.php';
23require_once $base . '/dbx/include/dbxKernel.php';
24
25$fail = function (string $message, int $code): void {
26 fwrite(STDERR, "FAIL: $message\n");
27 exit($code);
28};
29
30dbx()->set_system_var('dbx_activ_modul', 'myInvoices');
31dbx()->set_system_var('dbx_master_modul', 'myInvoices');
32dbx()->set_system_var('dbx_activ_modul_id', 1);
33dbx()->set_system_var('dbx_activ_action', 'report');
34dbx()->set_modul_var('dbx_modul', 'myInvoices');
35dbx()->set_modul_var('dbx_run1', 'report');
36
37$fixtures = dbx()->get_include_obj(
38 'myInvoicesFixtures',
39 'myInvoices'
40);
41$installed = $fixtures->install(true);
42if ((int)($installed['ok'] ?? 0) !== 1) {
43 $fail(
44 'Installation fehlgeschlagen: '
45 . (string)($installed['message'] ?? ''),
46 1
47 );
48}
49
50$db = dbx()->get_system_obj('dbxDB');
51$invoiceDd = 'myInvoices|invoice';
52$itemDd = 'myInvoices|invoiceItem';
53
54$demo = $db->select1(
56 array('invoice_no' => 'DBX-DEMO-1001')
57);
58$demoId = (int)($demo['id'] ?? 0);
59if ($demoId <= 0) {
60 $fail('Demo-Rechnung fehlt.', 2);
61}
62foreach (array(
63 'create_date',
64 'create_uid',
65 'update_date',
66 'update_uid',
67 'owner',
68) as $systemField) {
69 if ((string)($demo[$systemField] ?? '') === '') {
70 $fail(
71 'Automatisches dbxDB-Systemfeld fehlt: ' . $systemField,
72 3
73 );
74 }
75}
76
77$items = $db->select(
78 $itemDd,
79 array('invoice_id' => $demoId),
80 '*',
81 'position_no',
82 'ASC'
83);
84if (!is_array($items) || count($items) !== 2) {
85 $fail('Demo-Positionen sind nicht vollständig.', 4);
86}
87
89foreach ($items as $item) {
90 $calculatedCents += (int)round(
91 (float)$item['quantity']
92 * (float)$item['unit_price']
93 * 100
94 );
95}
96if ($calculatedCents !== 4730
97 || (int)round((float)$demo['total_gross'] * 100) !== 4730
98) {
99 $fail('Snapshot und Positionssumme weichen ab.', 5);
100}
101
102$service = dbx()->get_include_obj(
103 'myInvoicesService',
104 'myInvoices'
105);
106dbx()->set_modul_var('invoice_id', $demoId);
108foreach (array(
109 'Positionen zu Rechnung DBX-DEMO-1001',
110 '39,80 EUR',
111 '7,50 EUR',
112 '47,30 EUR',
113 'Endsumme der Positionen',
114) as $expected) {
115 if (strpos($positionsHtml, $expected) === false) {
116 $fail(
117 'Positionsreport fehlt: ' . $expected
118 . ' | HTML: ' . substr(
119 preg_replace('/\s+/', ' ', $positionsHtml),
120 0,
121 500
122 ),
123 6
124 );
125 }
126}
127
129foreach (array(
130 'DBX-DEMO-1001',
131 'Endsumme der angezeigten Rechnungen',
132 '[modul=myInvoices]dbx_run1=positions&invoice_id=',
133 'dbxConfirm',
134 'dbx_token=',
135) as $expected) {
136 if (strpos($reportHtml, $expected) === false) {
137 $fail('Rechnungsreport fehlt: ' . $expected, 7);
138 }
139}
140
141$webApp = dbx()->get_system_obj('dbxWebApp');
142$deleteUrl = dbx()->action_url(
143 '?dbx_modul=myInvoices&dbx_run1=delete&rid=' . $demoId
144);
145$deleteRoute = $webApp->action_policy_for_url($deleteUrl);
146parse_str((string)parse_url($deleteUrl, PHP_URL_QUERY), $deleteParams);
147$deleteToken = (string)($deleteParams['dbx_token'] ?? '');
148
149if (!$deleteRoute
150 || (string)($deleteRoute['source'] ?? '') !== 'automatic'
151 || (string)($deleteRoute['action'] ?? '') !== 'dbxAction.delete'
152 || (string)($deleteRoute['bindings']['rid'] ?? '') !== (string)$demoId
153 || !dbx()->check_action_token(
154 (string)($deleteRoute['scope'] ?? ''),
156 )
157) {
158 $fail('Zentrale Action-Policy akzeptiert gültige Route nicht.', 8);
159}
160
161$tamperedRoute = $webApp->action_policy_for_url(
162 '?dbx_modul=myInvoices&dbx_run1=delete&rid=' . ($demoId + 1)
163);
166 (string)($tamperedRoute['scope'] ?? ''),
168 )
169) {
170 $fail('Zentrale Action-Policy bindet die Rechnungs-ID nicht.', 8);
171}
172
173$testNo = 'DBX-TEST-' . date('YmdHis') . '-' . random_int(1000, 9999);
174$inserted = $db->insert($invoiceDd, array(
175 'invoice_no' => $testNo,
176 'invoice_date' => '2026-07-20',
177 'customer' => 'Transaktionstest',
178 'status' => 'draft',
179 'total_gross' => '10.00',
180));
181$testId = (int)$db->_insert_id;
182if ($inserted !== 1 || $testId <= 0) {
183 $fail('Temporäre Rechnung konnte nicht angelegt werden.', 9);
184}
185$inserted = $db->insert($itemDd, array(
186 'invoice_id' => $testId,
187 'position_no' => 10,
188 'article_no' => 'TEST-ROLLBACK',
189 'description' => 'Rollback-Position',
190 'quantity' => '1.00',
191 'unit_price' => '10.00',
192));
193if ($inserted !== 1) {
194 $db->delete($invoiceDd, array('id' => $testId));
195 $fail('Temporäre Position konnte nicht angelegt werden.', 10);
196}
197
198if ($db->begin($invoiceDd) !== 1) {
199 $fail('Rollback-Testtransaktion konnte nicht starten.', 11);
200}
202 $itemDd,
203 array('invoice_id' => $testId)
204);
207 array('id' => -987654321)
208);
209if ($firstDelete !== 1 || $secondDelete !== 0) {
210 $db->rollback($invoiceDd);
211 $fail('Fehlerpfad der Löschtransaktion wurde nicht erreicht.', 12);
212}
213$db->rollback($invoiceDd);
214if ((int)$db->count(
216 array('id' => $testId)
217) !== 1
218 || (int)$db->count(
219 $itemDd,
220 array('invoice_id' => $testId)
221 ) !== 1
222) {
223 $fail('Rollback hat Kopf oder Position nicht wiederhergestellt.', 13);
224}
225
226dbx()->set_modul_var('rid', $testId);
228if ((int)$db->count(
230 array('id' => $testId)
231) !== 0
232 || (int)$db->count(
233 $itemDd,
234 array('invoice_id' => $testId)
235 ) !== 0
236 || strpos(
238 'Rechnung und Positionen wurden gelöscht'
239 ) === false
240) {
241 $fail('Gültige atomare Löschung ist fehlgeschlagen.', 14);
242}
243
244echo "OK myInvoices runtime, sums, central policy precondition and rollback\n";
parse_url($data)
Zerlegt URL-/Parameterdaten in einen Array.
Definition dbxApi.php:2416
check_action_token(string $scope='global', string $token='')
Prueft ein sessiongebundenes Aktions-Token.
Definition dbxApi.php:1206
$_SERVER['REQUEST_METHOD']
foreach( $iterator as $file) if(! $groups) $expected
exit
Definition index.php:146
if( $inserted !==1) if($db->begin($invoiceDd) !==1) $firstDelete
if(!is_array($items)||count($items) !==2) $calculatedCents
if(! $tamperedRoute||dbx() ->check_action_token((string)($tamperedRoute['scope'] ?? ''), $deleteToken)) $testNo
if( $demoId<=0) foreach(array('create_date', 'create_uid', 'update_date', 'update_uid', 'owner',) as $systemField) $items
if(! $deleteRoute||(string)($deleteRoute['source'] ?? '') !=='automatic'||(string)($deleteRoute['action'] ?? '') !=='dbxAction.delete'||(string)($deleteRoute['bindings']['rid'] ?? '') !==(string) $demoId||!dbx() ->check_action_token((string)($deleteRoute['scope'] ?? ''), $deleteToken)) $tamperedRoute
foreach(array('Positionen zu Rechnung DBX-DEMO-1001', '39, 80 EUR', '7, 50 EUR', '47, 30 EUR', 'Endsumme der Positionen',) as $expected) $reportHtml
DBX schema administration.