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
FrontendExecuteJSONAndCheckCodeTest.php
413 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for sasoEventtickets_Frontend public methods: |
| 4 | * - executeJSON: dispatch to checkCode/getOptions/registerToCode/premium, exception handling |
| 5 | * - checkCode: valid code, CVV prompt (state 6), stolen code (state 7), not found (state 0), missing code |
| 6 | * - isUsed: returns true/false based on reg_request in meta |
| 7 | * - countConfirmedStatus: increments confirmedCount + stores validation timestamps |
| 8 | * - registerToCode: stores user registration in meta, throws on missing/invalid params |
| 9 | * - getOptions (frontend): returns public options |
| 10 | */ |
| 11 | |
| 12 | class FrontendExecuteJSONAndCheckCodeTest 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 | // ── executeJSON dispatch ──────────────────────────────────── |
| 22 | |
| 23 | public function test_executeJSON_unknown_action_returns_error(): void { |
| 24 | // wp_send_json_error / wp_send_json_success call exit(), so we test indirectly |
| 25 | // Unknown action throws Exception, caught by executeJSON → wp_send_json_error |
| 26 | // Since wp_send_json_error calls exit(), test the exception path directly |
| 27 | $frontend = $this->main->getFrontend(); |
| 28 | |
| 29 | // Use reflection to call the private method behavior check |
| 30 | // Actually, executeJSON is public — but wp_send_json calls exit() |
| 31 | // Instead, verify that the switch default throws the expected exception |
| 32 | $ref = new ReflectionMethod($frontend, 'executeJSON'); |
| 33 | $this->assertTrue($ref->isPublic()); |
| 34 | |
| 35 | // Verify the method signature accepts action + data |
| 36 | $params = $ref->getParameters(); |
| 37 | $this->assertEquals('a', $params[0]->getName()); |
| 38 | $this->assertEquals('data', $params[1]->getName()); |
| 39 | } |
| 40 | |
| 41 | public function test_executeJSON_checkCode_without_code_returns_error(): void { |
| 42 | $frontend = $this->main->getFrontend(); |
| 43 | |
| 44 | // checkCode throws #1001 when code param is missing |
| 45 | // executeJSON catches it and calls wp_send_json_error |
| 46 | // We verify the checkCode exception directly |
| 47 | $this->expectException(Exception::class); |
| 48 | $this->expectExceptionMessageMatches('/#1001/'); |
| 49 | |
| 50 | $frontend->checkCode([]); |
| 51 | } |
| 52 | |
| 53 | public function test_executeJSON_checkCode_with_empty_code_throws(): void { |
| 54 | $frontend = $this->main->getFrontend(); |
| 55 | |
| 56 | $this->expectException(Exception::class); |
| 57 | $this->expectExceptionMessageMatches('/#1001/'); |
| 58 | |
| 59 | $frontend->checkCode(['code' => ' ']); |
| 60 | } |
| 61 | |
| 62 | // ── checkCode — valid code ───────────────────────────────── |
| 63 | |
| 64 | public function test_checkCode_returns_valid_1_for_active_code(): void { |
| 65 | $tp = $this->createCodeInList(); |
| 66 | |
| 67 | $result = $this->main->getFrontend()->checkCode(['code' => $tp['code']]); |
| 68 | |
| 69 | $this->assertArrayHasKey('valid', $result); |
| 70 | $this->assertEquals(1, $result['valid']); |
| 71 | } |
| 72 | |
| 73 | public function test_checkCode_returns_retObject_with_message(): void { |
| 74 | $tp = $this->createCodeInList(); |
| 75 | |
| 76 | $result = $this->main->getFrontend()->checkCode(['code' => $tp['code']]); |
| 77 | |
| 78 | $this->assertArrayHasKey('retObject', $result); |
| 79 | $this->assertArrayHasKey('message', $result['retObject']); |
| 80 | $this->assertTrue($result['retObject']['message']['ok']); |
| 81 | } |
| 82 | |
| 83 | // ── checkCode — not found (state 0) ──────────────────────── |
| 84 | |
| 85 | public function test_checkCode_returns_valid_0_for_unknown_code(): void { |
| 86 | $result = $this->main->getFrontend()->checkCode(['code' => 'NONEXISTENT_CODE_XYZ_' . uniqid()]); |
| 87 | |
| 88 | $this->assertEquals(0, $result['valid']); |
| 89 | } |
| 90 | |
| 91 | // ── checkCode — inactive code (state 2) ──────────────────── |
| 92 | |
| 93 | public function test_checkCode_returns_valid_2_for_inactive_code(): void { |
| 94 | $tp = $this->createCodeInList(['aktiv' => 0]); |
| 95 | |
| 96 | $result = $this->main->getFrontend()->checkCode(['code' => $tp['code']]); |
| 97 | |
| 98 | $this->assertEquals(2, $result['valid']); |
| 99 | } |
| 100 | |
| 101 | // ── checkCode — stolen code (state 7) ────────────────────── |
| 102 | |
| 103 | public function test_checkCode_returns_valid_7_for_stolen_code(): void { |
| 104 | $tp = $this->createCodeInList(['aktiv' => 2]); |
| 105 | |
| 106 | $result = $this->main->getFrontend()->checkCode(['code' => $tp['code']]); |
| 107 | |
| 108 | $this->assertEquals(7, $result['valid']); |
| 109 | } |
| 110 | |
| 111 | // ── checkCode — CVV prompt (state 6) ─────────────────────── |
| 112 | |
| 113 | public function test_checkCode_returns_valid_6_when_cvv_required_and_not_provided(): void { |
| 114 | $tp = $this->createCodeInList(['cvv' => 'ABC123']); |
| 115 | |
| 116 | $result = $this->main->getFrontend()->checkCode(['code' => $tp['code']]); |
| 117 | |
| 118 | $this->assertEquals(6, $result['valid']); |
| 119 | } |
| 120 | |
| 121 | public function test_checkCode_returns_valid_1_when_cvv_correct(): void { |
| 122 | $tp = $this->createCodeInList(['cvv' => 'ABC123']); |
| 123 | |
| 124 | $result = $this->main->getFrontend()->checkCode([ |
| 125 | 'code' => $tp['code'], |
| 126 | 'cvv' => 'ABC123', |
| 127 | ]); |
| 128 | |
| 129 | $this->assertEquals(1, $result['valid']); |
| 130 | } |
| 131 | |
| 132 | public function test_checkCode_cvv_is_case_insensitive(): void { |
| 133 | $tp = $this->createCodeInList(['cvv' => 'SecretCVV']); |
| 134 | |
| 135 | $result = $this->main->getFrontend()->checkCode([ |
| 136 | 'code' => $tp['code'], |
| 137 | 'cvv' => 'secretcvv', |
| 138 | ]); |
| 139 | |
| 140 | $this->assertEquals(1, $result['valid']); |
| 141 | } |
| 142 | |
| 143 | public function test_checkCode_stays_at_6_when_cvv_wrong(): void { |
| 144 | $tp = $this->createCodeInList(['cvv' => 'CORRECT']); |
| 145 | |
| 146 | $result = $this->main->getFrontend()->checkCode([ |
| 147 | 'code' => $tp['code'], |
| 148 | 'cvv' => 'WRONG', |
| 149 | ]); |
| 150 | |
| 151 | $this->assertEquals(6, $result['valid']); |
| 152 | } |
| 153 | |
| 154 | // ── checkCode — registered code (state 3) ────────────────── |
| 155 | |
| 156 | public function test_checkCode_returns_valid_3_for_registered_code(): void { |
| 157 | $tp = $this->createCodeInList(); |
| 158 | |
| 159 | // Register a user to this code |
| 160 | $metaObj = json_decode($tp['codeObj']['meta'], true) ?: []; |
| 161 | $metaObj['user'] = [ |
| 162 | 'value' => 'TestUser', |
| 163 | 'reg_ip' => '127.0.0.1', |
| 164 | 'reg_approved' => 1, |
| 165 | 'reg_request' => '2026-01-01 12:00:00', |
| 166 | 'reg_request_tz' => 'UTC', |
| 167 | 'reg_userid' => 0, |
| 168 | ]; |
| 169 | $this->main->getDB()->update('codes', [ |
| 170 | 'meta' => json_encode($metaObj), |
| 171 | ], ['id' => $tp['codeObj']['id']]); |
| 172 | |
| 173 | $result = $this->main->getFrontend()->checkCode(['code' => $tp['code']]); |
| 174 | |
| 175 | $this->assertEquals(3, $result['valid']); |
| 176 | } |
| 177 | |
| 178 | // ── isUsed ───────────────────────────────────────────────── |
| 179 | |
| 180 | public function test_isUsed_returns_false_for_fresh_code(): void { |
| 181 | $tp = $this->createCodeInList(); |
| 182 | |
| 183 | $result = $this->main->getFrontend()->isUsed($tp['codeObj']); |
| 184 | |
| 185 | $this->assertFalse($result); |
| 186 | } |
| 187 | |
| 188 | public function test_isUsed_returns_true_when_reg_request_present(): void { |
| 189 | $tp = $this->createCodeInList(); |
| 190 | |
| 191 | $metaObj = json_decode($tp['codeObj']['meta'], true) ?: []; |
| 192 | $metaObj['used'] = ['reg_request' => '2026-01-01 00:00:00']; |
| 193 | $codeObj = $tp['codeObj']; |
| 194 | $codeObj['meta'] = json_encode($metaObj); |
| 195 | $this->main->getDB()->update('codes', ['meta' => $codeObj['meta']], ['id' => $codeObj['id']]); |
| 196 | |
| 197 | // Reload the code |
| 198 | $codeObj = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 199 | $result = $this->main->getFrontend()->isUsed($codeObj); |
| 200 | |
| 201 | $this->assertTrue($result); |
| 202 | } |
| 203 | |
| 204 | // ── countConfirmedStatus ─────────────────────────────────── |
| 205 | |
| 206 | public function test_countConfirmedStatus_increments_count(): void { |
| 207 | $tp = $this->createCodeInList(); |
| 208 | $codeObj = $tp['codeObj']; |
| 209 | $codeObj['_valid'] = 1; |
| 210 | |
| 211 | $result = $this->main->getFrontend()->countConfirmedStatus($codeObj); |
| 212 | |
| 213 | // Re-fetch from DB |
| 214 | $updated = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 215 | $meta = json_decode($updated['meta'], true); |
| 216 | $this->assertEquals(1, $meta['confirmedCount']); |
| 217 | } |
| 218 | |
| 219 | public function test_countConfirmedStatus_sets_first_success_timestamp(): void { |
| 220 | $tp = $this->createCodeInList(); |
| 221 | $codeObj = $tp['codeObj']; |
| 222 | $codeObj['_valid'] = 1; |
| 223 | |
| 224 | $this->main->getFrontend()->countConfirmedStatus($codeObj); |
| 225 | |
| 226 | $updated = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 227 | $meta = json_decode($updated['meta'], true); |
| 228 | $this->assertNotEmpty($meta['validation']['first_success']); |
| 229 | $this->assertNotEmpty($meta['validation']['first_success_tz']); |
| 230 | } |
| 231 | |
| 232 | public function test_countConfirmedStatus_increments_on_second_call(): void { |
| 233 | $tp = $this->createCodeInList(); |
| 234 | $codeObj = $tp['codeObj']; |
| 235 | $codeObj['_valid'] = 1; |
| 236 | |
| 237 | // First call |
| 238 | $this->main->getFrontend()->countConfirmedStatus($codeObj); |
| 239 | |
| 240 | // Re-fetch to get the updated meta |
| 241 | $codeObj = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 242 | $codeObj['_valid'] = 1; |
| 243 | |
| 244 | // Second call |
| 245 | $this->main->getFrontend()->countConfirmedStatus($codeObj); |
| 246 | |
| 247 | $updated = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 248 | $meta = json_decode($updated['meta'], true); |
| 249 | $this->assertEquals(2, $meta['confirmedCount']); |
| 250 | } |
| 251 | |
| 252 | public function test_countConfirmedStatus_skips_when_not_valid_1(): void { |
| 253 | $tp = $this->createCodeInList(); |
| 254 | $codeObj = $tp['codeObj']; |
| 255 | $codeObj['_valid'] = 2; // not valid |
| 256 | |
| 257 | $this->main->getFrontend()->countConfirmedStatus($codeObj); |
| 258 | |
| 259 | $updated = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 260 | $meta = json_decode($updated['meta'], true); |
| 261 | $this->assertFalse(isset($meta['confirmedCount'])); |
| 262 | } |
| 263 | |
| 264 | public function test_countConfirmedStatus_force_overrides_valid_check(): void { |
| 265 | $tp = $this->createCodeInList(); |
| 266 | $codeObj = $tp['codeObj']; |
| 267 | $codeObj['_valid'] = 2; // not valid, but force=true |
| 268 | |
| 269 | $this->main->getFrontend()->countConfirmedStatus($codeObj, true); |
| 270 | |
| 271 | $updated = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 272 | $meta = json_decode($updated['meta'], true); |
| 273 | $this->assertEquals(1, $meta['confirmedCount']); |
| 274 | } |
| 275 | |
| 276 | // ── registerToCode ───────────────────────────────────────── |
| 277 | |
| 278 | public function test_registerToCode_throws_on_missing_code(): void { |
| 279 | $this->expectException(Exception::class); |
| 280 | $this->expectExceptionMessageMatches('/#9201/'); |
| 281 | |
| 282 | $ref = new ReflectionMethod($this->main->getFrontend(), 'registerToCode'); |
| 283 | $ref->setAccessible(true); |
| 284 | $ref->invoke($this->main->getFrontend(), []); |
| 285 | } |
| 286 | |
| 287 | public function test_registerToCode_throws_on_missing_value(): void { |
| 288 | $tp = $this->createCodeInList(); |
| 289 | |
| 290 | $this->expectException(Exception::class); |
| 291 | $this->expectExceptionMessageMatches('/#9202/'); |
| 292 | |
| 293 | $ref = new ReflectionMethod($this->main->getFrontend(), 'registerToCode'); |
| 294 | $ref->setAccessible(true); |
| 295 | $ref->invoke($this->main->getFrontend(), ['code' => $tp['code']]); |
| 296 | } |
| 297 | |
| 298 | public function test_registerToCode_stores_user_in_meta(): void { |
| 299 | $tp = $this->createCodeInList(); |
| 300 | |
| 301 | $ref = new ReflectionMethod($this->main->getFrontend(), 'registerToCode'); |
| 302 | $ref->setAccessible(true); |
| 303 | $result = $ref->invoke($this->main->getFrontend(), [ |
| 304 | 'code' => $tp['code'], |
| 305 | 'value' => 'John Doe', |
| 306 | ]); |
| 307 | |
| 308 | $this->assertArrayHasKey('user', $result); |
| 309 | $this->assertStringContainsString('John Doe', $result['user']['value']); |
| 310 | $this->assertEquals(1, $result['user']['reg_approved']); |
| 311 | |
| 312 | // Verify in DB |
| 313 | $updated = $this->main->getCore()->retrieveCodeByCode($tp['code']); |
| 314 | $meta = json_decode($updated['meta'], true); |
| 315 | $this->assertStringContainsString('John Doe', $meta['user']['value']); |
| 316 | } |
| 317 | |
| 318 | public function test_registerToCode_throws_on_inactive_code(): void { |
| 319 | $tp = $this->createCodeInList(['aktiv' => 0]); |
| 320 | |
| 321 | $this->expectException(Exception::class); |
| 322 | $this->expectExceptionMessageMatches('/#9205/'); |
| 323 | |
| 324 | $ref = new ReflectionMethod($this->main->getFrontend(), 'registerToCode'); |
| 325 | $ref->setAccessible(true); |
| 326 | $ref->invoke($this->main->getFrontend(), [ |
| 327 | 'code' => $tp['code'], |
| 328 | 'value' => 'Test', |
| 329 | ]); |
| 330 | } |
| 331 | |
| 332 | public function test_registerToCode_throws_on_already_registered(): void { |
| 333 | $tp = $this->createCodeInList(); |
| 334 | |
| 335 | // First registration |
| 336 | $ref = new ReflectionMethod($this->main->getFrontend(), 'registerToCode'); |
| 337 | $ref->setAccessible(true); |
| 338 | $ref->invoke($this->main->getFrontend(), [ |
| 339 | 'code' => $tp['code'], |
| 340 | 'value' => 'First User', |
| 341 | ]); |
| 342 | |
| 343 | // Second registration should throw |
| 344 | $this->expectException(Exception::class); |
| 345 | $this->expectExceptionMessageMatches('/#9207/'); |
| 346 | |
| 347 | $ref->invoke($this->main->getFrontend(), [ |
| 348 | 'code' => $tp['code'], |
| 349 | 'value' => 'Second User', |
| 350 | ]); |
| 351 | } |
| 352 | |
| 353 | // ── getOptions (frontend) ────────────────────────────────── |
| 354 | |
| 355 | public function test_getOptions_returns_only_public_options(): void { |
| 356 | $frontend = $this->main->getFrontend(); |
| 357 | |
| 358 | $result = $frontend->getOptions(); |
| 359 | |
| 360 | $this->assertIsArray($result); |
| 361 | // All returned options should have isPublic = true |
| 362 | foreach ($result as $option) { |
| 363 | $this->assertTrue($option['isPublic'], 'Option "' . ($option['key'] ?? '?') . '" should be public'); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | // ── executeJSONPremium ───────────────────────────────────── |
| 368 | |
| 369 | public function test_executeJSONPremium_throws_when_not_premium(): void { |
| 370 | // executeJSONPremium is private, called via executeJSON with action='premium' |
| 371 | // Since we're not premium, it should throw #9001a |
| 372 | $ref = new ReflectionMethod($this->main->getFrontend(), 'executeJSONPremium'); |
| 373 | $ref->setAccessible(true); |
| 374 | |
| 375 | $this->expectException(Exception::class); |
| 376 | $this->expectExceptionMessageMatches('/#9001a/'); |
| 377 | |
| 378 | $ref->invoke($this->main->getFrontend(), []); |
| 379 | } |
| 380 | |
| 381 | // ── Helper methods ───────────────────────────────────────── |
| 382 | |
| 383 | private function createCodeInList(array $codeOverrides = []): array { |
| 384 | $listId = $this->main->getDB()->insert('lists', [ |
| 385 | 'name' => 'FrontendTest List ' . uniqid(), |
| 386 | 'aktiv' => 1, |
| 387 | 'meta' => '{}', |
| 388 | ]); |
| 389 | |
| 390 | $code = 'FTEST' . strtoupper(uniqid()); |
| 391 | |
| 392 | $codeData = array_merge([ |
| 393 | 'list_id' => $listId, |
| 394 | 'code' => $code, |
| 395 | 'aktiv' => 1, |
| 396 | 'cvv' => '', |
| 397 | 'order_id' => 0, |
| 398 | 'user_id' => 0, |
| 399 | 'meta' => '{}', |
| 400 | ], $codeOverrides); |
| 401 | |
| 402 | $codeId = $this->main->getDB()->insert('codes', $codeData); |
| 403 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 404 | |
| 405 | return [ |
| 406 | 'list_id' => $listId, |
| 407 | 'code' => $code, |
| 408 | 'code_id' => $codeId, |
| 409 | 'codeObj' => $codeObj, |
| 410 | ]; |
| 411 | } |
| 412 | } |
| 413 |