PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 2.9.3
Event Tickets with Ticket Scanner v2.9.3
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 / ShortcodesAndCodeListTest.php
event-tickets-with-ticket-scanner / tests Last commit date
bin 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 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 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 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 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
ShortcodesAndCodeListTest.php
290 lines
1 <?php
2 /**
3 * Batch 56 — Shortcodes and code list display:
4 * - replacingShortcodeTicketScanner: scanner HTML boilerplate
5 * - replacingShortcodeTicketDetail: ticket detail page via shortcode
6 * - replacingShortcodeFeatureList: option features list
7 * - replacingShortcodeEventViews: event calendar/list view
8 * - getCodesTextAsShortList: code display table
9 * - getMyCodeText: user profile code display
10 */
11
12 class ShortcodesAndCodeListTest extends WP_UnitTestCase {
13
14 private $main;
15
16 public function set_up(): void {
17 parent::set_up();
18 $this->main = sasoEventtickets::Instance();
19 }
20
21 // ── replacingShortcodeTicketScanner ──────────────────────────
22
23 public function test_shortcode_ticket_scanner_returns_html(): void {
24 $result = $this->main->replacingShortcodeTicketScanner();
25 $this->assertIsString($result);
26 $this->assertNotEmpty($result);
27 }
28
29 public function test_shortcode_ticket_scanner_contains_div(): void {
30 $result = $this->main->replacingShortcodeTicketScanner();
31 $this->assertStringContainsString('<div', $result);
32 }
33
34 public function test_shortcode_ticket_scanner_with_attrs(): void {
35 $result = $this->main->replacingShortcodeTicketScanner(['foo' => 'bar']);
36 $this->assertIsString($result);
37 }
38
39 // ── replacingShortcodeTicketDetail ───────────────────────────
40
41 public function test_shortcode_ticket_detail_no_code_returns_message(): void {
42 $result = $this->main->replacingShortcodeTicketDetail();
43 $this->assertIsString($result);
44 $this->assertStringContainsString('<p>', $result);
45 $this->assertStringContainsString('ticket', strtolower($result));
46 }
47
48 public function test_shortcode_ticket_detail_with_attr_code(): void {
49 if (!class_exists('WC_Product_Simple')) {
50 $this->markTestSkipped('WooCommerce not available');
51 }
52
53 // Create a ticket code to test with
54 $product = new WC_Product_Simple();
55 $product->set_name('ShortcodeDetail Test ' . uniqid());
56 $product->set_regular_price('10.00');
57 $product->set_status('publish');
58 $product->save();
59 $pid = $product->get_id();
60
61 update_post_meta($pid, 'saso_eventtickets_is_ticket', 'yes');
62 update_post_meta($pid, 'saso_eventtickets_ticket_start_date', '2026-12-25');
63
64 $listId = $this->main->getDB()->insert('lists', [
65 'name' => 'Detail Test ' . uniqid(),
66 'aktiv' => 1,
67 'meta' => '{}',
68 ]);
69
70 $order = wc_create_order();
71 $order->add_product($product, 1);
72 $order->set_status('completed');
73 $order->save();
74
75 $items = $order->get_items();
76 $firstItemId = array_key_first($items);
77
78 $metaObj = $this->main->getCore()->getMetaObject();
79 $metaObj['woocommerce']['product_id'] = $pid;
80 $metaObj['woocommerce']['item_id'] = $firstItemId;
81 $metaObj['woocommerce']['order_id'] = $order->get_id();
82 $metaObj['wc_ticket']['idcode'] = 'SCDETAIL';
83 $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj);
84
85 $codeStr = 'SCDETAIL' . strtoupper(uniqid());
86 $this->main->getDB()->insert('codes', [
87 'list_id' => $listId,
88 'code' => $codeStr,
89 'aktiv' => 1,
90 'cvv' => '',
91 'order_id' => $order->get_id(),
92 'user_id' => 0,
93 'meta' => $metaJson,
94 ]);
95
96 $codeObj = $this->main->getCore()->retrieveCodeByCode($codeStr);
97 $metaObj2 = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
98 $ticketId = $this->main->getCore()->getTicketId($codeObj, $metaObj2);
99
100 // Call with the ticket id as code attribute
101 $result = $this->main->replacingShortcodeTicketDetail(['code' => $ticketId]);
102 $this->assertIsString($result);
103 }
104
105 // ── replacingShortcodeFeatureList ────────────────────────────
106
107 public function test_shortcode_feature_list_returns_html(): void {
108 $result = $this->main->replacingShortcodeFeatureList();
109 $this->assertIsString($result);
110 $this->assertNotEmpty($result);
111 }
112
113 public function test_shortcode_feature_list_contains_headings(): void {
114 $result = $this->main->replacingShortcodeFeatureList();
115 $this->assertStringContainsString('<h3>', $result);
116 }
117
118 public function test_shortcode_feature_list_contains_options(): void {
119 $result = $this->main->replacingShortcodeFeatureList();
120 $this->assertStringContainsString('<li>', $result);
121 }
122
123 // ── replacingShortcodeEventViews ────────────────────────────
124
125 public function test_shortcode_event_views_returns_string(): void {
126 if (!class_exists('WC_Product_Simple')) {
127 $this->markTestSkipped('WooCommerce not available');
128 }
129 $result = $this->main->replacingShortcodeEventViews();
130 $this->assertIsString($result);
131 }
132
133 public function test_shortcode_event_views_with_list_view(): void {
134 if (!class_exists('WC_Product_Simple')) {
135 $this->markTestSkipped('WooCommerce not available');
136 }
137 $result = $this->main->replacingShortcodeEventViews(['view' => 'list']);
138 $this->assertIsString($result);
139 }
140
141 public function test_shortcode_event_views_with_calendar_view(): void {
142 if (!class_exists('WC_Product_Simple')) {
143 $this->markTestSkipped('WooCommerce not available');
144 }
145 $result = $this->main->replacingShortcodeEventViews(['view' => 'calendar']);
146 $this->assertIsString($result);
147 }
148
149 public function test_shortcode_event_views_with_months(): void {
150 if (!class_exists('WC_Product_Simple')) {
151 $this->markTestSkipped('WooCommerce not available');
152 }
153 $result = $this->main->replacingShortcodeEventViews(['months_to_show' => '6']);
154 $this->assertIsString($result);
155 }
156
157 public function test_shortcode_event_views_returns_container_div(): void {
158 if (!class_exists('WC_Product_Simple')) {
159 $this->markTestSkipped('WooCommerce not available');
160 }
161
162 $result = $this->main->replacingShortcodeEventViews(['view' => 'list', 'months_to_show' => '3']);
163 $this->assertIsString($result);
164 // Shortcode returns a container div that loads content via AJAX
165 $this->assertStringContainsString('sasoEventTicketsValidator_eventsview', $result);
166 }
167
168 // ── getCodesTextAsShortList ──────────────────────────────────
169
170 public function test_getCodesTextAsShortList_empty_array(): void {
171 $result = $this->main->getCodesTextAsShortList([]);
172 $this->assertIsString($result);
173 $this->assertEmpty($result);
174 }
175
176 public function test_getCodesTextAsShortList_with_code(): void {
177 if (!class_exists('WC_Product_Simple')) {
178 $this->markTestSkipped('WooCommerce not available');
179 }
180
181 $pid = $this->createTicketProduct();
182 $data = $this->createCodeForProduct($pid);
183
184 $result = $this->main->getCodesTextAsShortList([$data['codeObj']]);
185 $this->assertIsString($result);
186 $this->assertStringContainsString('<table>', $result);
187 $this->assertStringContainsString('</table>', $result);
188 }
189
190 public function test_getCodesTextAsShortList_inactive_code_shows_label(): void {
191 if (!class_exists('WC_Product_Simple')) {
192 $this->markTestSkipped('WooCommerce not available');
193 }
194
195 $pid = $this->createTicketProduct();
196 $data = $this->createCodeForProduct($pid);
197
198 // Set code to inactive
199 $this->main->getDB()->update('codes', ['aktiv' => 0], ['id' => $data['codeObj']['id']]);
200 $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']);
201
202 $result = $this->main->getCodesTextAsShortList([$codeObj]);
203 $this->assertStringContainsString('<table>', $result);
204 }
205
206 public function test_getCodesTextAsShortList_fires_filter(): void {
207 $filtered = false;
208 add_filter($this->main->_add_filter_prefix . 'main_getCodesTextAsShortList', function ($ret) use (&$filtered) {
209 $filtered = true;
210 return $ret;
211 });
212
213 $this->main->getCodesTextAsShortList([]);
214 $this->assertTrue($filtered);
215 }
216
217 // ── getMyCodeText ───────────────────────────────────────────
218
219 public function test_getMyCodeText_no_user_returns_empty(): void {
220 $result = $this->main->getMyCodeText(0);
221 $this->assertIsString($result);
222 }
223
224 public function test_getMyCodeText_fires_filter(): void {
225 $filtered = false;
226 add_filter($this->main->_add_filter_prefix . 'main_getMyCodeText', function ($ret) use (&$filtered) {
227 $filtered = true;
228 return $ret;
229 });
230
231 $this->main->getMyCodeText(0);
232 $this->assertTrue($filtered);
233 }
234
235 public function test_getMyCodeText_with_codes(): void {
236 if (!class_exists('WC_Product_Simple')) {
237 $this->markTestSkipped('WooCommerce not available');
238 }
239
240 $pid = $this->createTicketProduct();
241 $data = $this->createCodeForProduct($pid);
242
243 $result = $this->main->getMyCodeText(0, [], null, '', [$data['codeObj']]);
244 $this->assertIsString($result);
245 $this->assertStringContainsString('<table>', $result);
246 }
247
248 // ── helpers ─────────────────────────────────────────────────
249
250 private function createTicketProduct(): int {
251 $product = new WC_Product_Simple();
252 $product->set_name('SC Test ' . uniqid());
253 $product->set_regular_price('10.00');
254 $product->set_status('publish');
255 $product->save();
256 $pid = $product->get_id();
257
258 update_post_meta($pid, 'saso_eventtickets_is_ticket', 'yes');
259 update_post_meta($pid, 'saso_eventtickets_ticket_start_date', '2026-12-25');
260
261 return $pid;
262 }
263
264 private function createCodeForProduct(int $pid): array {
265 $listId = $this->main->getDB()->insert('lists', [
266 'name' => 'SC List ' . uniqid(),
267 'aktiv' => 1,
268 'meta' => '{}',
269 ]);
270
271 $metaObj = $this->main->getCore()->getMetaObject();
272 $metaObj['woocommerce']['product_id'] = $pid;
273 $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj);
274
275 $codeStr = 'SCTEST' . strtoupper(uniqid());
276 $this->main->getDB()->insert('codes', [
277 'list_id' => $listId,
278 'code' => $codeStr,
279 'aktiv' => 1,
280 'cvv' => '',
281 'order_id' => 0,
282 'user_id' => 0,
283 'meta' => $metaJson,
284 ]);
285
286 $codeObj = $this->main->getCore()->retrieveCodeByCode($codeStr);
287 return ['code' => $codeStr, 'codeObj' => $codeObj, 'list_id' => $listId];
288 }
289 }
290