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 / TicketLabelAndDisplayTest.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
TicketLabelAndDisplayTest.php
321 lines
1 <?php
2 /**
3 * Batch 46 — Ticket label getters, date display, WPML fallback, order item lookup:
4 * - getLabelNamePerTicket / getLabelValuePerTicket / getLabelDaychooserPerTicket
5 * - getWPMLProductId: filter fallback
6 * - displayDayChooserDateAsString: daychooser date formatting
7 * - displayTicketDateAsString: ticket date range formatting
8 * - getMaxRedeemAmountOfTicket: max redeem from product meta
9 * - getOrderItem: order item lookup by metaObj item_id
10 */
11
12 class TicketLabelAndDisplayTest extends WP_UnitTestCase {
13
14 private $main;
15 private $ticket;
16
17 public function set_up(): void {
18 parent::set_up();
19 $this->main = sasoEventtickets::Instance();
20 $this->ticket = $this->main->getTicketHandler();
21 }
22
23 private function createTicketProduct(array $meta = []): int {
24 if (!class_exists('WC_Product_Simple')) {
25 $this->markTestSkipped('WooCommerce not available');
26 }
27
28 $product = new WC_Product_Simple();
29 $product->set_name('Label Test ' . uniqid());
30 $product->set_regular_price('10.00');
31 $product->set_status('publish');
32 $product->save();
33 $pid = $product->get_id();
34
35 foreach ($meta as $key => $value) {
36 update_post_meta($pid, $key, $value);
37 }
38
39 return $pid;
40 }
41
42 private function createCodeWithProduct(int $productId): array {
43 $listId = $this->main->getDB()->insert('lists', [
44 'name' => 'Display Test ' . uniqid(),
45 'aktiv' => 1,
46 'meta' => '{}',
47 ]);
48
49 $metaObj = $this->main->getCore()->getMetaObject();
50 $metaObj['woocommerce']['product_id'] = $productId;
51 $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj);
52
53 $code = 'DISPLAY' . strtoupper(uniqid());
54 $this->main->getDB()->insert('codes', [
55 'list_id' => $listId,
56 'code' => $code,
57 'aktiv' => 1,
58 'cvv' => '',
59 'order_id' => 0,
60 'user_id' => 0,
61 'meta' => $metaJson,
62 ]);
63
64 $codeObj = $this->main->getCore()->retrieveCodeByCode($code);
65 return ['list_id' => $listId, 'code' => $code, 'codeObj' => $codeObj];
66 }
67
68 // ── getLabelNamePerTicket ────────────────────────────────
69
70 public function test_getLabelNamePerTicket_returns_default(): void {
71 $pid = $this->createTicketProduct();
72 $result = $this->ticket->getLabelNamePerTicket($pid);
73 $this->assertStringContainsString('Name', $result);
74 $this->assertStringContainsString('{count}', $result);
75 }
76
77 public function test_getLabelNamePerTicket_returns_custom(): void {
78 $pid = $this->createTicketProduct([
79 'saso_eventtickets_request_name_per_ticket_label' => 'Bitte Name eingeben #{count}:',
80 ]);
81 $result = $this->ticket->getLabelNamePerTicket($pid);
82 $this->assertEquals('Bitte Name eingeben #{count}:', $result);
83 }
84
85 public function test_getLabelNamePerTicket_trims_whitespace(): void {
86 $pid = $this->createTicketProduct([
87 'saso_eventtickets_request_name_per_ticket_label' => ' Custom Label ',
88 ]);
89 $result = $this->ticket->getLabelNamePerTicket($pid);
90 $this->assertEquals('Custom Label', $result);
91 }
92
93 public function test_getLabelNamePerTicket_empty_returns_default(): void {
94 $pid = $this->createTicketProduct([
95 'saso_eventtickets_request_name_per_ticket_label' => '',
96 ]);
97 $result = $this->ticket->getLabelNamePerTicket($pid);
98 $this->assertStringContainsString('Name', $result);
99 }
100
101 // ── getLabelValuePerTicket ───────────────────────────────
102
103 public function test_getLabelValuePerTicket_returns_default(): void {
104 $pid = $this->createTicketProduct();
105 $result = $this->ticket->getLabelValuePerTicket($pid);
106 $this->assertStringContainsString('value', strtolower($result));
107 $this->assertStringContainsString('{count}', $result);
108 }
109
110 public function test_getLabelValuePerTicket_returns_custom(): void {
111 $pid = $this->createTicketProduct([
112 'saso_eventtickets_request_value_per_ticket_label' => 'Wert wählen #{count}:',
113 ]);
114 $result = $this->ticket->getLabelValuePerTicket($pid);
115 $this->assertEquals('Wert wählen #{count}:', $result);
116 }
117
118 // ── getLabelDaychooserPerTicket ──────────────────────────
119
120 public function test_getLabelDaychooserPerTicket_returns_default(): void {
121 $pid = $this->createTicketProduct();
122 $result = $this->ticket->getLabelDaychooserPerTicket($pid);
123 $this->assertStringContainsString('day', strtolower($result));
124 $this->assertStringContainsString('{count}', $result);
125 }
126
127 public function test_getLabelDaychooserPerTicket_returns_custom(): void {
128 $pid = $this->createTicketProduct([
129 'saso_eventtickets_request_daychooser_per_ticket_label' => 'Tag auswählen #{count}:',
130 ]);
131 $result = $this->ticket->getLabelDaychooserPerTicket($pid);
132 $this->assertEquals('Tag auswählen #{count}:', $result);
133 }
134
135 // ── getWPMLProductId ────────────────────────────────────
136
137 public function test_getWPMLProductId_returns_same_id_without_wpml(): void {
138 $pid = $this->createTicketProduct();
139 $result = $this->ticket->getWPMLProductId($pid);
140 $this->assertEquals($pid, $result);
141 }
142
143 public function test_getWPMLProductId_handles_zero(): void {
144 $result = $this->ticket->getWPMLProductId(0);
145 $this->assertEquals(0, $result);
146 }
147
148 public function test_getWPMLProductId_handles_null(): void {
149 $result = $this->ticket->getWPMLProductId(null);
150 $this->assertNull($result);
151 }
152
153 public function test_getWPMLProductId_fallback_on_bad_filter(): void {
154 // Simulate a broken WPML filter returning null
155 add_filter('wpml_object_id', '__return_null', 9999);
156 $pid = $this->createTicketProduct();
157 $result = $this->ticket->getWPMLProductId($pid);
158 // Should fallback to original product_id
159 $this->assertEquals($pid, $result);
160 remove_filter('wpml_object_id', '__return_null', 9999);
161 }
162
163 // ── displayDayChooserDateAsString ───────────────────────
164
165 public function test_displayDayChooserDateAsString_null_returns_empty(): void {
166 $result = $this->ticket->displayDayChooserDateAsString(null);
167 $this->assertEquals('', $result);
168 }
169
170 public function test_displayDayChooserDateAsString_non_daychooser_returns_empty(): void {
171 $pid = $this->createTicketProduct();
172 $data = $this->createCodeWithProduct($pid);
173 $result = $this->ticket->displayDayChooserDateAsString($data['codeObj']);
174 $this->assertEquals('', $result);
175 }
176
177 public function test_displayDayChooserDateAsString_with_daychooser_date(): void {
178 $pid = $this->createTicketProduct();
179 $data = $this->createCodeWithProduct($pid);
180 $codeObj = $data['codeObj'];
181
182 // Set daychooser meta
183 $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
184 $metaObj['wc_ticket']['is_daychooser'] = 1;
185 $metaObj['wc_ticket']['day_per_ticket'] = '2026-06-15';
186 $this->main->getCore()->saveMetaObject($codeObj, $metaObj);
187
188 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
189 $result = $this->ticket->displayDayChooserDateAsString($codeObj);
190 $this->assertNotEmpty($result);
191 // Should contain some form of the date
192 $this->assertStringContainsString('2026', $result);
193 }
194
195 // ── displayTicketDateAsString ────────────────────────────
196
197 public function test_displayTicketDateAsString_throws_for_zero(): void {
198 $this->expectException(Exception::class);
199 $this->expectExceptionMessageMatches('/#8021/');
200 $this->ticket->displayTicketDateAsString(0);
201 }
202
203 public function test_displayTicketDateAsString_throws_for_negative(): void {
204 $this->expectException(Exception::class);
205 $this->ticket->displayTicketDateAsString(-1);
206 }
207
208 public function test_displayTicketDateAsString_with_start_date(): void {
209 $pid = $this->createTicketProduct([
210 'saso_eventtickets_ticket_start_date' => '2026-12-25',
211 ]);
212 $result = $this->ticket->displayTicketDateAsString($pid, 'Y/m/d', 'H:i');
213 $this->assertStringContainsString('2026', $result);
214 }
215
216 public function test_displayTicketDateAsString_with_start_and_end(): void {
217 $pid = $this->createTicketProduct([
218 'saso_eventtickets_ticket_start_date' => '2026-12-25',
219 'saso_eventtickets_ticket_end_date' => '2026-12-26',
220 ]);
221 $result = $this->ticket->displayTicketDateAsString($pid, 'Y/m/d', 'H:i');
222 $this->assertStringContainsString('2026', $result);
223 $this->assertStringContainsString('-', $result); // separator
224 }
225
226 public function test_displayTicketDateAsString_no_explicit_dates_returns_today(): void {
227 $pid = $this->createTicketProduct();
228 $result = $this->ticket->displayTicketDateAsString($pid, 'Y/m/d', 'H:i');
229 // When no dates are set, calcDateStringAllowedRedeemFrom defaults to today
230 $this->assertStringContainsString(wp_date('Y'), $result);
231 }
232
233 // ── getMaxRedeemAmountOfTicket ───────────────────────────
234
235 public function test_getMaxRedeemAmountOfTicket_default_is_one(): void {
236 $pid = $this->createTicketProduct();
237 $data = $this->createCodeWithProduct($pid);
238 $result = $this->ticket->getMaxRedeemAmountOfTicket($data['codeObj']);
239 // Default (no meta set) returns 0 from intval(''), but method returns that
240 $this->assertIsInt($result);
241 }
242
243 public function test_getMaxRedeemAmountOfTicket_custom_value(): void {
244 $pid = $this->createTicketProduct([
245 'saso_eventtickets_ticket_max_redeem_amount' => 5,
246 ]);
247 $data = $this->createCodeWithProduct($pid);
248 $result = $this->ticket->getMaxRedeemAmountOfTicket($data['codeObj']);
249 $this->assertEquals(5, $result);
250 }
251
252 public function test_getMaxRedeemAmountOfTicket_no_product_returns_one(): void {
253 // Code without product_id in meta
254 $listId = $this->main->getDB()->insert('lists', [
255 'name' => 'NoProduct List ' . uniqid(),
256 'aktiv' => 1,
257 'meta' => '{}',
258 ]);
259 $metaObj = $this->main->getCore()->getMetaObject();
260 $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj);
261 $code = 'NOPROD' . strtoupper(uniqid());
262 $this->main->getDB()->insert('codes', [
263 'list_id' => $listId,
264 'code' => $code,
265 'aktiv' => 1,
266 'cvv' => '',
267 'order_id' => 0,
268 'user_id' => 0,
269 'meta' => $metaJson,
270 ]);
271 $codeObj = $this->main->getCore()->retrieveCodeByCode($code);
272 $result = $this->ticket->getMaxRedeemAmountOfTicket($codeObj);
273 $this->assertEquals(1, $result);
274 }
275
276 // ── getOrderItem ────────────────────────────────────────
277
278 public function test_getOrderItem_finds_matching_item(): void {
279 $pid = $this->createTicketProduct();
280 $product = wc_get_product($pid);
281 $order = wc_create_order();
282 $order->add_product($product, 1);
283 $order->save();
284
285 $items = $order->get_items();
286 $firstItemId = array_key_first($items);
287
288 $metaObj = $this->main->getCore()->getMetaObject();
289 $metaObj['woocommerce']['item_id'] = $firstItemId;
290
291 $result = $this->ticket->getOrderItem($order, $metaObj);
292 $this->assertNotNull($result);
293 $this->assertEquals($pid, $result->get_product_id());
294 }
295
296 public function test_getOrderItem_returns_null_for_wrong_item_id(): void {
297 $pid = $this->createTicketProduct();
298 $product = wc_get_product($pid);
299 $order = wc_create_order();
300 $order->add_product($product, 1);
301 $order->save();
302
303 $metaObj = $this->main->getCore()->getMetaObject();
304 $metaObj['woocommerce']['item_id'] = 999999;
305
306 $result = $this->ticket->getOrderItem($order, $metaObj);
307 $this->assertNull($result);
308 }
309
310 public function test_getOrderItem_returns_null_for_empty_order(): void {
311 $order = wc_create_order();
312 $order->save();
313
314 $metaObj = $this->main->getCore()->getMetaObject();
315 $metaObj['woocommerce']['item_id'] = 1;
316
317 $result = $this->ticket->getOrderItem($order, $metaObj);
318 $this->assertNull($result);
319 }
320 }
321