PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 2.9.4
Event Tickets with Ticket Scanner v2.9.4
3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.4 trunk 2.6.0 2.7.0 2.7.1 2.7.10 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3
event-tickets-with-ticket-scanner / tests / CoreMetaTest.php
event-tickets-with-ticket-scanner / tests Last commit date
bin 3 months ago fixtures 3 months ago AdminCodeCleanupAndPDFTest.php 3 months ago AdminCodesByProductTest.php 3 months ago AdminCustomerNameTest.php 3 months ago AdminErrorLogTest.php 3 months ago AdminFormatWarningTest.php 3 months ago AdminListAndCodeOpsTest.php 3 months ago AdminListQueryTest.php 3 months ago AdminMetaAndErrorTest.php 3 months ago AdminOptionsAndMigrationTest.php 3 months ago AdminOrderInfoTest.php 3 months ago AdminRedeemAmountTest.php 3 months ago AdminRestrictionAndRstrTest.php 3 months ago AdminSettingsAndDatepickerTest.php 3 months ago AdminSettingsCodeTest.php 3 months ago AdminTicketInfoTest.php 3 months ago AdminTimezoneAndMiscTest.php 3 months ago AdminWCCodeOpsTest.php 3 months ago AuthtokenAccessTest.php 3 months ago AuthtokenCRUDTest.php 3 months ago AuthtokenEditAndRemoveTest.php 3 months ago AuthtokenTest.php 3 months ago BaseLimitsTest.php 3 months ago CartCodeRestrictionAndAssignTest.php 3 months ago CartMetaAndBeforeCartTest.php 3 months ago CartValidationTest.php 3 months ago ContextWizardTest.php 3 months ago CoreAlignAndSearchTest.php 3 months ago CoreCodeOpsAndDBLogTest.php 3 months ago CoreDecodeAndReplaceTest.php 3 months ago CoreEncodeMetaTest.php 3 months ago CoreExpiredAndRegisteredTest.php 3 months ago CoreMetaAndUrlTest.php 3 months ago CoreMetaObjectStructureTest.php 3 months ago CoreMetaTest.php 3 months ago CoreMethodsTest.php 3 months ago CoreOrderAndIPTest.php 3 months ago CoreParserAndQueryTest.php 3 months ago CoreParserURLAndMergePDFTest.php 3 months ago CoreReplaceAndExpireTest.php 3 months ago CoreTicketIdAndExpirationTest.php 3 months ago CoreTicketIdAndUrlTest.php 3 months ago CoreTicketURLComponentsTest.php 3 months ago CountRedeemsTodayTest.php 3 months ago CronjobTest.php 3 months ago DBOperationsTest.php 3 months ago DBSanitizeAndQueryTest.php 3 months ago DBSanitizeTest.php 3 months ago DBTablesAndUpdateTest.php 3 months ago DatabaseTest.php 3 months ago DateCalcAndCorrectProductTest.php 3 months ago DaychooserTest.php 3 months ago EmailHandlerTest.php 3 months ago EmailOrderMetaAndAttachmentsTest.php 3 months ago ErrorLogAndSanitizeTest.php 3 months ago EventTimeWindowTest.php 3 months ago FrontendCheckCodeTest.php 3 months ago FrontendCountConfirmedTest.php 3 months ago FrontendExecuteJSONAndCheckCodeTest.php 3 months ago FrontendIsUsedAndOptionsTest.php 3 months ago FrontendMarkUsedTest.php 3 months ago FrontendValidationTest.php 3 months ago FullTicketFlowTest.php 3 months ago HelpersTest.php 3 months ago ListManagementTest.php 3 months ago MaxRedeemPerDayTest.php 3 months ago MessengerAndRESTEndpointsTest.php 3 months ago MessengerTypeCheckTest.php 3 months ago OldPremiumGuardTest.php 3 months ago OneTimeUseTest.php 3 months ago OptionsChangeAndLoadTest.php 3 months ago OptionsDeleteAndResetTest.php 3 months ago OptionsExportImportTest.php 3 months ago OptionsFormatsTest.php 3 months ago OptionsHistoryTest.php 3 months ago OptionsMigrationTest.php 3 months ago OptionsResetAndFormatTest.php 3 months ago OptionsTest.php 3 months ago OrderDeleteAndRefundDeleteTest.php 3 months ago OrderMetaKeyValueDisplayTest.php 3 months ago OrderStatusHandlerTest.php 3 months ago OrderTicketGenerationTest.php 3 months ago OrderTicketQueryTest.php 3 months ago PDFAndQRConfigTest.php 3 months ago PDFMergeAndPWAServiceWorkerTest.php 3 months ago PDFSettersTest.php 3 months ago PDFSettingsTest.php 3 months ago PDFUtilsTest.php 3 months ago PWAManifestAndSessionTest.php 3 months ago PartialRefundAndCodeCleanupTest.php 3 months ago PluginInitAndShortcodeTest.php 3 months ago ProductSettingsTest.php 3 months ago QRCodeAndDesignerTest.php 3 months ago QRPDFAndBadgePDFTest.php 3 months ago RESTRoutesAndPingTest.php 3 months ago RefundTest.php 3 months ago RestApiTest.php 3 months ago RestApiTicketTest.php 3 months ago ScannerBoilerplateAndFormatWarningsTest.php 3 months ago SeatingBlockTest.php 3 months ago SeatingCoordinatorTest.php 3 months ago SeatingExportTest.php 3 months ago SeatingMetaTest.php 3 months ago SeatingPlanCRUDTest.php 3 months ago SeatingPlanTest.php 3 months ago SeatingSeatCRUDTest.php 3 months ago SetupWizardTest.php 3 months ago ShortcodeAndCartCheckTest.php 3 months ago ShortcodeAndCodesDisplayTest.php 3 months ago ShortcodesAndCodeListTest.php 3 months ago StaticDateAndTimeTest.php 3 months ago StaticHelpersAndMessengerTest.php 3 months ago StaticUtilMethodsTest.php 3 months ago TicketBadgeTemplateTest.php 3 months ago TicketCalcDateTest.php 3 months ago TicketDesignerAndBadgeTest.php 3 months ago TicketDesignerTemplateTest.php 3 months ago TicketDesignerTest.php 3 months ago TicketDisplayTest.php 3 months ago TicketExpirationAndICSTest.php 3 months ago TicketLabelAndDisplayTest.php 3 months ago TicketLabelsAndStaticsTest.php 3 months ago TicketQRSettersTest.php 3 months ago TicketRedeemTest.php 3 months ago TicketRoutingTest.php 3 months ago TicketScannerMethodsTest.php 3 months ago TicketSettersAndOrderTest.php 3 months ago TicketUtilAndICSTest.php 3 months ago TicketUtilMethodsTest.php 3 months ago TicketWPMLAndSubscriptionTest.php 3 months ago TimezoneRedeemBlockingTest.php 3 months ago UrlParsingTest.php 3 months ago VariationTicketTest.php 3 months ago WCBaseMetaConstantsTest.php 3 months ago WCCheckoutCartFlowTest.php 3 months ago WCEmailAttachmentTest.php 3 months ago WCFrontendAjaxAndDatepickerTest.php 3 months ago WCFrontendCartHandlerTest.php 3 months ago WCFrontendCartHandlersTest.php 3 months ago WCFrontendCartTest.php 3 months ago WCFrontendCartValidationTest.php 3 months ago WCFrontendHandlersTest.php 3 months ago WCFrontendLabelsTest.php 3 months ago WCFrontendMethodsTest.php 3 months ago WCOrderDeleteTest.php 3 months ago WCOrderDisplayMetaTest.php 3 months ago WCOrderHasTicketsTest.php 3 months ago WCOrderHooksTest.php 3 months ago WCOrderItemMetaDisplayTest.php 3 months ago WCOrderItemOpsTest.php 3 months ago WCOrderLifecycleTest.php 3 months ago WCOrderMethodsTest.php 3 months ago WCOrderTicketDetectionTest.php 3 months ago WCOrderTicketNumberTest.php 3 months ago WCProductAndVariationTest.php 3 months ago WCProductColumnsTest.php 3 months ago WCProductConfigAndColumnsTest.php 3 months ago WCProductIsTicketAndListsTest.php 3 months ago WCProductMetaSaveTest.php 3 months ago WCProductMethodsTest.php 3 months ago WCProductTabsAndSideBoxTest.php 3 months ago WCProductTicketTest.php 3 months ago WebhooksAndMigrationTest.php 3 months ago bootstrap.php 3 months ago composer.json 3 months ago phpunit.xml 3 months ago test-premium-compat.sh 3 months ago
CoreMetaTest.php
289 lines
1 <?php
2 /**
3 * Tests for Core metadata methods (saveMetaObject, QR content, alignArrays, ticket URLs, etc.).
4 */
5
6 class CoreMetaTest extends WP_UnitTestCase {
7
8 private $main;
9
10 public function set_up(): void {
11 parent::set_up();
12 $this->main = sasoEventtickets::Instance();
13 }
14
15 /**
16 * Helper: create a code with meta.
17 */
18 private function createCodeWithMeta(array $metaOverrides = []): array {
19 $listId = $this->main->getDB()->insert('lists', [
20 'name' => 'CoreMeta List ' . uniqid(),
21 'aktiv' => 1,
22 'meta' => '{}',
23 ]);
24
25 $metaObj = $this->main->getCore()->getMetaObject();
26 foreach ($metaOverrides as $key => $value) {
27 // Support nested keys like 'wc_ticket.is_ticket'
28 $parts = explode('.', $key);
29 $ref = &$metaObj;
30 foreach ($parts as $part) {
31 $ref = &$ref[$part];
32 }
33 $ref = $value;
34 }
35 $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj);
36
37 $code = 'CM' . strtoupper(uniqid());
38 $codeId = $this->main->getDB()->insert('codes', [
39 'code' => $code,
40 'code_display' => $code,
41 'cvv' => '',
42 'meta' => $metaJson,
43 'aktiv' => 1,
44 'redeemed' => 0,
45 'list_id' => $listId,
46 'order_id' => 0,
47 ]);
48
49 return [
50 'code' => $code,
51 'code_id' => $codeId,
52 'list_id' => $listId,
53 'meta_obj' => $metaObj,
54 ];
55 }
56
57 // ── saveMetaObject ────────────────────────────────────────────
58
59 public function test_saveMetaObject_persists_to_db(): void {
60 $main = sasoEventtickets::Instance();
61 $listId = $main->getDB()->insert('lists', [
62 'name' => 'SaveMeta List ' . uniqid(),
63 'aktiv' => 1,
64 'meta' => '{}',
65 ]);
66 $code = strtoupper(substr(md5(uniqid()), 0, 20));
67 $main->getDB()->insert('codes', [
68 'code' => $code,
69 'list_id' => $listId,
70 'meta' => $main->getCore()->json_encode_with_error_handling($main->getCore()->getMetaObject()),
71 ]);
72 $codeObj = $main->getCore()->retrieveCodeByCode($code);
73 $metaObj = $main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
74 $metaObj['confirmedCount'] = 77;
75
76 $result = $main->getCore()->saveMetaObject($codeObj, $metaObj);
77
78 $fresh = $main->getCore()->retrieveCodeByCode($code);
79 $freshMeta = $main->getCore()->encodeMetaValuesAndFillObject($fresh['meta'], $fresh);
80 $this->assertEquals(77, $freshMeta['confirmedCount']);
81 }
82
83 // ── decodeAndMergeMeta ────────────────────────────────────────
84
85 public function test_decodeAndMergeMeta_merges_values(): void {
86 $default = ['a' => 1, 'b' => 2, 'c' => ['d' => 3]];
87 $json = json_encode(['b' => 99, 'c' => ['d' => 88]]);
88
89 $result = $this->main->getCore()->decodeAndMergeMeta($json, $default);
90 $this->assertEquals(1, $result['a']);
91 $this->assertEquals(99, $result['b']);
92 $this->assertEquals(88, $result['c']['d']);
93 }
94
95 public function test_decodeAndMergeMeta_empty_json_returns_default(): void {
96 $default = ['a' => 1, 'b' => 2];
97
98 $result = $this->main->getCore()->decodeAndMergeMeta('', $default);
99 $this->assertEquals($default, $result);
100 }
101
102 public function test_decodeAndMergeMeta_null_json_returns_default(): void {
103 $default = ['x' => 'y'];
104
105 $result = $this->main->getCore()->decodeAndMergeMeta(null, $default);
106 $this->assertEquals($default, $result);
107 }
108
109 public function test_decodeAndMergeMeta_invalid_json_returns_default(): void {
110 $default = ['a' => 1];
111
112 $result = $this->main->getCore()->decodeAndMergeMeta('{invalid', $default);
113 $this->assertEquals($default, $result);
114 }
115
116 // ── alignArrays ──────────────────────────────────────────────
117
118 public function test_alignArrays_adds_missing_keys(): void {
119 $template = ['a' => 1, 'b' => 2, 'c' => 3];
120 $target = ['a' => 10];
121
122 $this->main->getCore()->alignArrays($template, $target);
123 $this->assertArrayHasKey('b', $target);
124 $this->assertArrayHasKey('c', $target);
125 $this->assertEquals(10, $target['a']); // original value preserved
126 $this->assertNull($target['b']); // added as null
127 }
128
129 public function test_alignArrays_removes_extra_keys(): void {
130 $template = ['a' => 1];
131 $target = ['a' => 10, 'b' => 20, 'c' => 30];
132
133 $this->main->getCore()->alignArrays($template, $target);
134 $this->assertArrayHasKey('a', $target);
135 $this->assertArrayNotHasKey('b', $target);
136 $this->assertArrayNotHasKey('c', $target);
137 }
138
139 public function test_alignArrays_recursive_subarrays(): void {
140 $template = ['nested' => ['x' => 1, 'y' => 2]];
141 $target = ['nested' => ['x' => 99]];
142
143 $this->main->getCore()->alignArrays($template, $target);
144 $this->assertEquals(99, $target['nested']['x']);
145 $this->assertNull($target['nested']['y']);
146 }
147
148 public function test_alignArrays_empty_template(): void {
149 $template = [];
150 $target = ['a' => 1, 'b' => 2];
151
152 $this->main->getCore()->alignArrays($template, $target);
153 $this->assertEmpty($target);
154 }
155
156 // ── isCodeIsRegistered ────────────────────────────────────────
157
158 public function test_isCodeIsRegistered_false_for_fresh_code(): void {
159 $data = $this->createCodeWithMeta();
160 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
161
162 $this->assertFalse($this->main->getCore()->isCodeIsRegistered($codeObj));
163 }
164
165 public function test_isCodeIsRegistered_true_when_user_value_set(): void {
166 $data = $this->createCodeWithMeta(['user.value' => 'Max Mustermann']);
167 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
168
169 $this->assertTrue($this->main->getCore()->isCodeIsRegistered($codeObj));
170 }
171
172 // ── getTicketId ───────────────────────────────────────────────
173
174 public function test_getTicketId_formats_correctly(): void {
175 $data = $this->createCodeWithMeta(['wc_ticket.idcode' => 'TK']);
176 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
177 $codeObj['order_id'] = 42;
178 $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
179
180 $ticketId = $this->main->getCore()->getTicketId($codeObj, $metaObj);
181 $this->assertEquals('TK-42-' . $data['code'], $ticketId);
182 }
183
184 public function test_getTicketId_empty_when_missing_fields(): void {
185 $codeObj = ['code' => 'X', 'order_id' => 0]; // no idcode in meta
186 $metaObj = $this->main->getCore()->getMetaObject();
187
188 $ticketId = $this->main->getCore()->getTicketId($codeObj, $metaObj);
189 // idcode is empty by default, so result depends on implementation
190 $this->assertIsString($ticketId);
191 }
192
193 // ── getTicketURL ──────────────────────────────────────────────
194
195 public function test_getTicketURL_contains_ticket_id(): void {
196 $data = $this->createCodeWithMeta(['wc_ticket.idcode' => 'EVT']);
197 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
198 $codeObj['order_id'] = 100;
199 $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
200
201 $url = $this->main->getCore()->getTicketURL($codeObj, $metaObj);
202 $this->assertStringContainsString('EVT-100-' . $data['code'], $url);
203 }
204
205 // ── getTicketScannerURL ───────────────────────────────────────
206
207 public function test_getTicketScannerURL_contains_scanner_path(): void {
208 $url = $this->main->getCore()->getTicketScannerURL('TK-1-ABC');
209 $this->assertStringContainsString('scanner/', $url);
210 $this->assertStringContainsString('code=', $url);
211 $this->assertStringContainsString('TK-1-ABC', $url);
212 }
213
214 // ── getQRCodeContent ──────────────────────────────────────────
215
216 public function test_getQRCodeContent_returns_ticket_id_by_default(): void {
217 $data = $this->createCodeWithMeta(['wc_ticket.idcode' => 'QR']);
218 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
219 $codeObj['order_id'] = 55;
220
221 $qr = $this->main->getCore()->getQRCodeContent($codeObj);
222 $this->assertStringContainsString('QR-55-' . $data['code'], $qr);
223 }
224
225 public function test_getQRCodeContent_with_scanner_url_option(): void {
226 $data = $this->createCodeWithMeta(['wc_ticket.idcode' => 'SC']);
227 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
228 $codeObj['order_id'] = 77;
229
230 // Enable scanner URL option
231 $this->main->getOptions()->changeOption([
232 'key' => 'ticketQRUseURLToTicketScanner',
233 'value' => 1,
234 ]);
235
236 $qr = $this->main->getCore()->getQRCodeContent($codeObj);
237 $this->assertStringContainsString('scanner/', $qr);
238
239 // Reset
240 $this->main->getOptions()->changeOption([
241 'key' => 'ticketQRUseURLToTicketScanner',
242 'value' => 0,
243 ]);
244 }
245
246 // ── checkCodesSize / isCodeSizeExceeded ───────────────────────
247
248 public function test_isCodeSizeExceeded_returns_bool(): void {
249 $result = $this->main->getCore()->isCodeSizeExceeded();
250 $this->assertIsBool($result);
251 }
252
253 public function test_checkCodesSize_does_not_throw_under_limit(): void {
254 // With few codes, should not throw
255 $this->main->getCore()->checkCodesSize();
256 $this->assertTrue(true); // no exception
257 }
258
259 // ── getRealIpAddr ─────────────────────────────────────────────
260
261 public function test_getRealIpAddr_returns_string(): void {
262 $_SERVER['REMOTE_ADDR'] = '192.168.1.1';
263 $ip = $this->main->getCore()->getRealIpAddr();
264 $this->assertIsString($ip);
265 $this->assertEquals('192.168.1.1', $ip);
266 }
267
268 public function test_getRealIpAddr_prefers_client_ip(): void {
269 $_SERVER['HTTP_CLIENT_IP'] = '10.0.0.1';
270 $_SERVER['REMOTE_ADDR'] = '192.168.1.1';
271
272 $ip = $this->main->getCore()->getRealIpAddr();
273 $this->assertEquals('10.0.0.1', $ip);
274
275 unset($_SERVER['HTTP_CLIENT_IP']);
276 }
277
278 public function test_getRealIpAddr_uses_forwarded_for(): void {
279 unset($_SERVER['HTTP_CLIENT_IP']);
280 $_SERVER['HTTP_X_FORWARDED_FOR'] = '172.16.0.1';
281 $_SERVER['REMOTE_ADDR'] = '192.168.1.1';
282
283 $ip = $this->main->getCore()->getRealIpAddr();
284 $this->assertEquals('172.16.0.1', $ip);
285
286 unset($_SERVER['HTTP_X_FORWARDED_FOR']);
287 }
288 }
289