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 / CoreCodeOpsAndDBLogTest.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
CoreCodeOpsAndDBLogTest.php
255 lines
1 <?php
2 /**
3 * Batch 38 — Core code operations and DB logError:
4 * - saveMetaObject: writes meta JSON back to codes table
5 * - retrieveCodeById: lookup by ID, with/without list join
6 * - checkCodesSize / isCodeSizeExceeded: ticket limit enforcement
7 * - checkCodeExpired: premium expiration check (returns false in free)
8 * - isCodeIsRegistered: checks if ticket has registered user value
9 * - DB::logError: new convenience method for error logging
10 * - Base::increaseGlobalTicketCounter / getOverallTicketCounterValue
11 * - Base::getMaxValues / getMaxValue
12 */
13
14 class CoreCodeOpsAndDBLogTest 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 private function createCodeInList(): array {
24 $listId = $this->main->getDB()->insert('lists', [
25 'name' => 'CodeOps List ' . uniqid(),
26 'aktiv' => 1,
27 'meta' => '{}',
28 ]);
29 $metaObj = $this->main->getCore()->getMetaObject();
30 $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj);
31
32 $code = 'CODEOPS' . strtoupper(uniqid());
33 $this->main->getDB()->insert('codes', [
34 'list_id' => $listId,
35 'code' => $code,
36 'aktiv' => 1,
37 'cvv' => '',
38 'order_id' => 0,
39 'user_id' => 0,
40 'meta' => $metaJson,
41 ]);
42
43 $codeObj = $this->main->getCore()->retrieveCodeByCode($code);
44 return ['list_id' => $listId, 'code' => $code, 'codeObj' => $codeObj];
45 }
46
47 // ── saveMetaObject ────────────────────────────────────────
48
49 public function test_saveMetaObject_updates_meta(): void {
50 $data = $this->createCodeInList();
51 $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($data['codeObj']['meta'], $data['codeObj']);
52 $metaObj['confirmedCount'] = 42;
53
54 $updatedCodeObj = $this->main->getCore()->saveMetaObject($data['codeObj'], $metaObj);
55
56 // Reload from DB
57 $reloaded = $this->main->getCore()->retrieveCodeByCode($data['code']);
58 $reloadedMeta = $this->main->getCore()->encodeMetaValuesAndFillObject($reloaded['meta'], $reloaded);
59 $this->assertEquals(42, $reloadedMeta['confirmedCount']);
60 }
61
62 public function test_saveMetaObject_returns_updated_codeObj(): void {
63 $data = $this->createCodeInList();
64 $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($data['codeObj']['meta'], $data['codeObj']);
65
66 $result = $this->main->getCore()->saveMetaObject($data['codeObj'], $metaObj);
67 $this->assertIsArray($result);
68 $this->assertArrayHasKey('meta', $result);
69 $this->assertIsString($result['meta']); // JSON string
70 }
71
72 // ── retrieveCodeById ──────────────────────────────────────
73
74 public function test_retrieveCodeById_returns_code(): void {
75 $data = $this->createCodeInList();
76 $result = $this->main->getCore()->retrieveCodeById($data['codeObj']['id']);
77
78 $this->assertIsArray($result);
79 $this->assertEquals($data['code'], $result['code']);
80 }
81
82 public function test_retrieveCodeById_with_list_join(): void {
83 $data = $this->createCodeInList();
84 $result = $this->main->getCore()->retrieveCodeById($data['codeObj']['id'], true);
85
86 $this->assertIsArray($result);
87 $this->assertArrayHasKey('list_name', $result);
88 $this->assertNotEmpty($result['list_name']);
89 }
90
91 public function test_retrieveCodeById_throws_for_zero(): void {
92 $this->expectException(Exception::class);
93 $this->expectExceptionMessageMatches('/#220/');
94 $this->main->getCore()->retrieveCodeById(0);
95 }
96
97 public function test_retrieveCodeById_throws_for_nonexistent(): void {
98 $this->expectException(Exception::class);
99 $this->expectExceptionMessageMatches('/#221/');
100 $this->main->getCore()->retrieveCodeById(999999);
101 }
102
103 // ── checkCodesSize / isCodeSizeExceeded ───────────────────
104
105 public function test_isCodeSizeExceeded_returns_bool(): void {
106 $result = $this->main->getCore()->isCodeSizeExceeded();
107 $this->assertIsBool($result);
108 }
109
110 public function test_checkCodesSize_does_not_throw_below_limit(): void {
111 // In test environment with few codes, this should not throw
112 if ($this->main->getCore()->isCodeSizeExceeded()) {
113 $this->markTestSkipped('Code limit already exceeded');
114 }
115 $this->main->getCore()->checkCodesSize();
116 $this->assertTrue(true); // No exception = pass
117 }
118
119 // ── checkCodeExpired ──────────────────────────────────────
120
121 public function test_checkCodeExpired_returns_false_in_free_version(): void {
122 $data = $this->createCodeInList();
123 $result = $this->main->getCore()->checkCodeExpired($data['codeObj']);
124 $this->assertFalse($result);
125 }
126
127 // ── isCodeIsRegistered ────────────────────────────────────
128
129 public function test_isCodeIsRegistered_false_for_new_code(): void {
130 $data = $this->createCodeInList();
131 $result = $this->main->getCore()->isCodeIsRegistered($data['codeObj']);
132 $this->assertFalse($result);
133 }
134
135 public function test_isCodeIsRegistered_true_for_registered_code(): void {
136 $data = $this->createCodeInList();
137 $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($data['codeObj']['meta'], $data['codeObj']);
138 $metaObj['user']['value'] = 'John Doe';
139 $this->main->getCore()->saveMetaObject($data['codeObj'], $metaObj);
140
141 $reloaded = $this->main->getCore()->retrieveCodeByCode($data['code']);
142 $result = $this->main->getCore()->isCodeIsRegistered($reloaded);
143 $this->assertTrue($result);
144 }
145
146 // ── DB::logError ──────────────────────────────────────────
147
148 public function test_logError_inserts_into_errorlogs(): void {
149 global $wpdb;
150 $countBefore = (int) $wpdb->get_var(
151 "SELECT COUNT(*) FROM {$wpdb->prefix}saso_eventtickets_errorlogs"
152 );
153
154 $this->main->getDB()->logError('Test error from PHPUnit', 'CoreCodeOpsTest');
155
156 $countAfter = (int) $wpdb->get_var(
157 "SELECT COUNT(*) FROM {$wpdb->prefix}saso_eventtickets_errorlogs"
158 );
159 $this->assertEquals($countBefore + 1, $countAfter);
160 }
161
162 public function test_logError_stores_message(): void {
163 global $wpdb;
164 $msg = 'Unique error ' . uniqid();
165 $this->main->getDB()->logError($msg, 'TestCaller');
166
167 $row = $wpdb->get_row(
168 $wpdb->prepare(
169 "SELECT * FROM {$wpdb->prefix}saso_eventtickets_errorlogs WHERE msg = %s",
170 $msg
171 ),
172 ARRAY_A
173 );
174 $this->assertNotNull($row);
175 $this->assertEquals('TestCaller', $row['caller_name']);
176 }
177
178 public function test_logError_truncates_long_message(): void {
179 $longMsg = str_repeat('X', 500);
180 $this->main->getDB()->logError($longMsg, 'TruncTest');
181
182 global $wpdb;
183 $row = $wpdb->get_row(
184 "SELECT * FROM {$wpdb->prefix}saso_eventtickets_errorlogs WHERE caller_name = 'TruncTest' ORDER BY id DESC LIMIT 1",
185 ARRAY_A
186 );
187 $this->assertNotNull($row);
188 $this->assertLessThanOrEqual(250, strlen($row['exception_msg']));
189 }
190
191 // ── Base::increaseGlobalTicketCounter ─────────────────────
192
193 public function test_increaseGlobalTicketCounter_increases(): void {
194 $before = $this->main->getBase()->getOverallTicketCounterValue();
195 $this->main->getBase()->increaseGlobalTicketCounter(5);
196 $after = $this->main->getBase()->getOverallTicketCounterValue();
197
198 $this->assertEquals($before + 5, $after);
199 }
200
201 public function test_increaseGlobalTicketCounter_default_increment(): void {
202 $before = $this->main->getBase()->getOverallTicketCounterValue();
203 $this->main->getBase()->increaseGlobalTicketCounter();
204 $after = $this->main->getBase()->getOverallTicketCounterValue();
205
206 $this->assertEquals($before + 1, $after);
207 }
208
209 public function test_getOverallTicketCounterValue_returns_int(): void {
210 $result = $this->main->getBase()->getOverallTicketCounterValue();
211 $this->assertIsInt($result);
212 }
213
214 // ── Base::getMaxValues / getMaxValue ──────────────────────
215
216 public function test_getMaxValues_returns_array(): void {
217 $result = $this->main->getBase()->getMaxValues();
218 $this->assertIsArray($result);
219 }
220
221 public function test_getMaxValues_has_expected_keys(): void {
222 $result = $this->main->getBase()->getMaxValues();
223 $this->assertArrayHasKey('lists', $result);
224 $this->assertArrayHasKey('codes_total', $result);
225 }
226
227 public function test_getMaxValue_returns_known_key(): void {
228 $result = $this->main->getBase()->getMaxValue('lists');
229 $this->assertIsInt($result);
230 $this->assertGreaterThan(0, $result);
231 }
232
233 public function test_getMaxValue_returns_default_for_unknown(): void {
234 $result = $this->main->getBase()->getMaxValue('nonexistent_key', 99);
235 $this->assertEquals(99, $result);
236 }
237
238 // ── Base::_isMaxReachedForList ────────────────────────────
239
240 public function test_isMaxReachedForList_true_below_limit(): void {
241 $result = $this->main->getBase()->_isMaxReachedForList(0);
242 $this->assertTrue($result);
243 }
244
245 public function test_isMaxReachedForTickets_true_below_limit(): void {
246 $result = $this->main->getBase()->_isMaxReachedForTickets(0);
247 $this->assertTrue($result);
248 }
249
250 public function test_isMaxReachedForAuthtokens_true_below_limit(): void {
251 $result = $this->main->getBase()->_isMaxReachedForAuthtokens(0);
252 $this->assertTrue($result);
253 }
254 }
255