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 / CoreParserAndQueryTest.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
CoreParserAndQueryTest.php
292 lines
1 <?php
2 /**
3 * Batch 35b — Core parser and query methods:
4 * - parser_search_loop: template loop parsing ({{LOOP...}})
5 * - getCodesByRegUserId: codes by registered user
6 * - getCodesByOrderId: codes by WC order ID
7 * - clearCode: strips hyphens, colons, spaces, urldecodes
8 * - retrieveCodeByCode: single code lookup, with/without list join
9 * - getListById: list lookup by ID
10 * - triggerWebhooks: webhook dispatch (without actual HTTP)
11 * - encodeMetaValuesAndFillObject: meta JSON decode + fill
12 */
13
14 class CoreParserAndQueryTest extends WP_UnitTestCase {
15
16 private $main;
17
18 public function set_up(): void {
19 parent::set_up();
20 $this->main = sasoEventtickets::Instance();
21 }
22
23 // ── parser_search_loop ─────────────────────────────────────
24
25 public function test_parser_search_loop_finds_loop(): void {
26 $text = '<div>{{LOOP ORDER.items AS item}}<p>{{item.name}}</p>{{LOOPEND}}</div>';
27
28 $result = $this->main->getCore()->parser_search_loop($text);
29
30 $this->assertIsArray($result);
31 $this->assertEquals('ORDER.items', $result['collection']);
32 $this->assertEquals('item', $result['item_var']);
33 $this->assertStringContainsString('item.name', $result['loop_part']);
34 }
35
36 public function test_parser_search_loop_returns_false_for_no_loop(): void {
37 $text = '<div>No loops here</div>';
38
39 $result = $this->main->getCore()->parser_search_loop($text);
40
41 $this->assertFalse($result);
42 }
43
44 public function test_parser_search_loop_returns_false_for_empty(): void {
45 $result = $this->main->getCore()->parser_search_loop('');
46
47 $this->assertFalse($result);
48 }
49
50 public function test_parser_search_loop_returns_positions(): void {
51 $text = 'Before{{LOOP items AS i}}content{{LOOPEND}}After';
52
53 $result = $this->main->getCore()->parser_search_loop($text);
54
55 $this->assertIsArray($result);
56 $this->assertArrayHasKey('pos_start', $result);
57 $this->assertArrayHasKey('pos_end', $result);
58 $this->assertGreaterThan(0, $result['pos_start']);
59 $this->assertGreaterThan($result['pos_start'], $result['pos_end']);
60 }
61
62 public function test_parser_search_loop_with_incomplete_loop_returns_false(): void {
63 // Has LOOP but no LOOPEND
64 $text = '{{LOOP items AS i}}content but no end';
65
66 $result = $this->main->getCore()->parser_search_loop($text);
67
68 $this->assertFalse($result);
69 }
70
71 // ── clearCode ──────────────────────────────────────────────
72
73 public function test_clearCode_removes_hyphens(): void {
74 $result = $this->main->getCore()->clearCode('ABC-DEF-GHI');
75 $this->assertEquals('ABCDEFGHI', $result);
76 }
77
78 public function test_clearCode_removes_colons(): void {
79 $result = $this->main->getCore()->clearCode('AB:CD:EF');
80 $this->assertEquals('ABCDEF', $result);
81 }
82
83 public function test_clearCode_removes_spaces(): void {
84 $result = $this->main->getCore()->clearCode('AB CD EF');
85 $this->assertEquals('ABCDEF', $result);
86 }
87
88 public function test_clearCode_trims_whitespace(): void {
89 $result = $this->main->getCore()->clearCode(' ABCDEF ');
90 $this->assertEquals('ABCDEF', $result);
91 }
92
93 public function test_clearCode_url_decodes(): void {
94 // urldecode runs AFTER space removal, so %20 decodes to space which remains
95 $result = $this->main->getCore()->clearCode('ABC%20DEF');
96 $this->assertEquals('ABC DEF', $result);
97 }
98
99 public function test_clearCode_strips_tags(): void {
100 $result = $this->main->getCore()->clearCode('<b>ABCDEF</b>');
101 $this->assertEquals('ABCDEF', $result);
102 }
103
104 public function test_clearCode_fires_filter(): void {
105 $filtered = false;
106 $callback = function ($code) use (&$filtered) {
107 $filtered = true;
108 return $code;
109 };
110 add_filter($this->main->_add_filter_prefix . 'core_clearCode', $callback);
111
112 $this->main->getCore()->clearCode('TESTCODE');
113
114 $this->assertTrue($filtered);
115 remove_filter($this->main->_add_filter_prefix . 'core_clearCode', $callback);
116 }
117
118 // ── getCodesByRegUserId ────────────────────────────────────
119
120 public function test_getCodesByRegUserId_returns_empty_for_zero(): void {
121 $result = $this->main->getCore()->getCodesByRegUserId(0);
122 $this->assertEmpty($result);
123 }
124
125 public function test_getCodesByRegUserId_returns_empty_for_negative(): void {
126 $result = $this->main->getCore()->getCodesByRegUserId(-5);
127 $this->assertEmpty($result);
128 }
129
130 public function test_getCodesByRegUserId_returns_codes_for_user(): void {
131 $userId = $this->factory->user->create(['role' => 'subscriber']);
132
133 $listId = $this->main->getDB()->insert('lists', [
134 'name' => 'UserQuery List ' . uniqid(),
135 'aktiv' => 1,
136 'meta' => '{}',
137 ]);
138 $code = 'USERQ' . strtoupper(uniqid());
139 $this->main->getDB()->insert('codes', [
140 'list_id' => $listId,
141 'code' => $code,
142 'aktiv' => 1,
143 'cvv' => '',
144 'order_id' => 0,
145 'user_id' => $userId,
146 'meta' => '{}',
147 ]);
148
149 $result = $this->main->getCore()->getCodesByRegUserId($userId);
150
151 $this->assertNotEmpty($result);
152 $this->assertEquals($code, $result[0]['code']);
153 }
154
155 // ── getCodesByOrderId ──────────────────────────────────────
156
157 public function test_getCodesByOrderId_returns_empty_for_zero(): void {
158 $result = $this->main->getCore()->getCodesByOrderId(0);
159 $this->assertEmpty($result);
160 }
161
162 public function test_getCodesByOrderId_returns_empty_for_nonexistent(): void {
163 $result = $this->main->getCore()->getCodesByOrderId(999999);
164 $this->assertEmpty($result);
165 }
166
167 // ── retrieveCodeByCode ─────────────────────────────────────
168
169 public function test_retrieveCodeByCode_finds_existing_code(): void {
170 $listId = $this->main->getDB()->insert('lists', [
171 'name' => 'RetrieveTest ' . uniqid(),
172 'aktiv' => 1,
173 'meta' => '{}',
174 ]);
175 $code = 'RTRVTEST' . strtoupper(uniqid());
176 $this->main->getDB()->insert('codes', [
177 'list_id' => $listId,
178 'code' => $code,
179 'aktiv' => 1,
180 'cvv' => '',
181 'order_id' => 0,
182 'user_id' => 0,
183 'meta' => '{}',
184 ]);
185
186 $result = $this->main->getCore()->retrieveCodeByCode($code);
187
188 $this->assertIsArray($result);
189 $this->assertEquals($code, $result['code']);
190 }
191
192 public function test_retrieveCodeByCode_with_list_join(): void {
193 $listName = 'JoinTest ' . uniqid();
194 $listId = $this->main->getDB()->insert('lists', [
195 'name' => $listName,
196 'aktiv' => 1,
197 'meta' => '{}',
198 ]);
199 $code = 'JOINTEST' . strtoupper(uniqid());
200 $this->main->getDB()->insert('codes', [
201 'list_id' => $listId,
202 'code' => $code,
203 'aktiv' => 1,
204 'cvv' => '',
205 'order_id' => 0,
206 'user_id' => 0,
207 'meta' => '{}',
208 ]);
209
210 $result = $this->main->getCore()->retrieveCodeByCode($code, true);
211
212 $this->assertIsArray($result);
213 $this->assertArrayHasKey('list_name', $result);
214 $this->assertEquals($listName, $result['list_name']);
215 }
216
217 public function test_retrieveCodeByCode_throws_for_empty(): void {
218 $this->expectException(Exception::class);
219 $this->expectExceptionMessageMatches('/#203/');
220
221 $this->main->getCore()->retrieveCodeByCode('');
222 }
223
224 public function test_retrieveCodeByCode_throws_for_not_found(): void {
225 $this->expectException(Exception::class);
226 $this->expectExceptionMessageMatches('/#204/');
227
228 $this->main->getCore()->retrieveCodeByCode('NONEXISTENT' . strtoupper(uniqid()));
229 }
230
231 // ── getListById ────────────────────────────────────────────
232
233 public function test_getListById_returns_list(): void {
234 $listName = 'GetByIdTest ' . uniqid();
235 $listId = $this->main->getDB()->insert('lists', [
236 'name' => $listName,
237 'aktiv' => 1,
238 'meta' => '{}',
239 ]);
240
241 $result = $this->main->getCore()->getListById($listId);
242
243 $this->assertIsArray($result);
244 $this->assertEquals($listName, $result['name']);
245 $this->assertEquals($listId, $result['id']);
246 }
247
248 public function test_getListById_throws_for_nonexistent(): void {
249 $this->expectException(Exception::class);
250 $this->expectExceptionMessageMatches('/#9232/');
251
252 $this->main->getCore()->getListById(999999);
253 }
254
255 // ── encodeMetaValuesAndFillObject ──────────────────────────
256
257 public function test_encodeMetaValues_decodes_json(): void {
258 $meta = json_encode(['confirmedCount' => 3, 'wc_ticket' => ['is_ticket' => 1]]);
259 $codeObj = ['id' => 1, 'code' => 'TEST', 'meta' => $meta];
260
261 $result = $this->main->getCore()->encodeMetaValuesAndFillObject($meta, $codeObj);
262
263 $this->assertIsArray($result);
264 $this->assertEquals(3, $result['confirmedCount']);
265 $this->assertEquals(1, $result['wc_ticket']['is_ticket']);
266 }
267
268 public function test_encodeMetaValues_handles_empty_meta(): void {
269 $codeObj = ['id' => 1, 'code' => 'TEST', 'meta' => '{}'];
270
271 $result = $this->main->getCore()->encodeMetaValuesAndFillObject('{}', $codeObj);
272
273 $this->assertIsArray($result);
274 }
275
276 public function test_encodeMetaValues_returns_wc_ticket_struct(): void {
277 // The method decodes meta JSON and ensures wc_ticket structure exists
278 $meta = json_encode([
279 'wc_ticket' => ['is_ticket' => 1, '_public_ticket_id' => 'ABC123'],
280 'woocommerce' => ['order_id' => 42, 'product_id' => 99],
281 ]);
282 $codeObj = ['id' => 1, 'code' => 'TEST123', 'meta' => $meta, 'aktiv' => 1];
283
284 $result = $this->main->getCore()->encodeMetaValuesAndFillObject($meta, $codeObj);
285
286 $this->assertIsArray($result);
287 $this->assertArrayHasKey('wc_ticket', $result);
288 $this->assertEquals(1, $result['wc_ticket']['is_ticket']);
289 $this->assertEquals('ABC123', $result['wc_ticket']['_public_ticket_id']);
290 }
291 }
292