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
FrontendValidationTest.php
243 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for frontend code validation (checkCode, isUsed, markAsUsed). |
| 4 | */ |
| 5 | |
| 6 | class FrontendValidationTest extends WP_UnitTestCase { |
| 7 | |
| 8 | private $main; |
| 9 | |
| 10 | public function set_up(): void { |
| 11 | parent::set_up(); |
| 12 | $this->main = sasoEventtickets::Instance(); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Helper: create a list with a code. |
| 17 | */ |
| 18 | private function createCodeInList(string $codeStr, bool $active = true): array { |
| 19 | $listId = $this->main->getDB()->insert('lists', [ |
| 20 | 'name' => 'FV List ' . uniqid(), |
| 21 | 'aktiv' => 1, |
| 22 | 'meta' => '{}', |
| 23 | ]); |
| 24 | |
| 25 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 26 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 27 | |
| 28 | $codeId = $this->main->getDB()->insert('codes', [ |
| 29 | 'code' => $codeStr, |
| 30 | 'code_display' => $codeStr, |
| 31 | 'cvv' => '', |
| 32 | 'meta' => $metaJson, |
| 33 | 'aktiv' => $active ? 1 : 0, |
| 34 | 'redeemed' => 0, |
| 35 | 'list_id' => $listId, |
| 36 | 'order_id' => 0, |
| 37 | ]); |
| 38 | |
| 39 | return ['list_id' => $listId, 'code_id' => $codeId, 'code' => $codeStr]; |
| 40 | } |
| 41 | |
| 42 | // ── isUsed ─────────────────────────────────────────────────── |
| 43 | |
| 44 | public function test_isUsed_returns_false_for_fresh_code(): void { |
| 45 | $data = $this->createCodeInList('FRESH' . uniqid()); |
| 46 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 47 | |
| 48 | $this->assertFalse($this->main->getFrontend()->isUsed($codeObj)); |
| 49 | } |
| 50 | |
| 51 | public function test_isUsed_returns_true_when_reg_request_set(): void { |
| 52 | $code = 'USED' . strtoupper(uniqid()); |
| 53 | $data = $this->createCodeInList($code); |
| 54 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 55 | |
| 56 | // Set the used marker in meta |
| 57 | $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 58 | $metaObj['used']['reg_request'] = wp_date('Y-m-d H:i:s'); |
| 59 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 60 | $this->main->getDB()->update('codes', ['meta' => $metaJson], ['id' => $codeObj['id']]); |
| 61 | |
| 62 | // Re-retrieve |
| 63 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 64 | $this->assertTrue($this->main->getFrontend()->isUsed($codeObj)); |
| 65 | } |
| 66 | |
| 67 | // ── checkCode ──────────────────────────────────────────────── |
| 68 | |
| 69 | public function test_checkCode_valid_code_returns_1(): void { |
| 70 | $code = 'CHECK' . strtoupper(uniqid()); |
| 71 | $this->createCodeInList($code); |
| 72 | |
| 73 | $result = $this->main->getFrontend()->checkCode(['code' => $code]); |
| 74 | $this->assertIsArray($result); |
| 75 | $this->assertArrayHasKey('valid', $result); |
| 76 | // valid=1 means found and active |
| 77 | $this->assertEquals(1, $result['valid']); |
| 78 | } |
| 79 | |
| 80 | public function test_checkCode_nonexistent_code_returns_0(): void { |
| 81 | $result = $this->main->getFrontend()->checkCode(['code' => 'NONEXIST_' . uniqid()]); |
| 82 | $this->assertEquals(0, $result['valid']); |
| 83 | } |
| 84 | |
| 85 | public function test_checkCode_inactive_code_returns_2(): void { |
| 86 | $code = 'INACTIVE' . strtoupper(uniqid()); |
| 87 | $this->createCodeInList($code, false); |
| 88 | |
| 89 | $result = $this->main->getFrontend()->checkCode(['code' => $code]); |
| 90 | $this->assertEquals(2, $result['valid']); |
| 91 | } |
| 92 | |
| 93 | public function test_checkCode_missing_code_throws(): void { |
| 94 | $this->expectException(Exception::class); |
| 95 | $this->main->getFrontend()->checkCode(['code' => '']); |
| 96 | } |
| 97 | |
| 98 | public function test_checkCode_no_code_parameter_throws(): void { |
| 99 | $this->expectException(Exception::class); |
| 100 | $this->main->getFrontend()->checkCode([]); |
| 101 | } |
| 102 | |
| 103 | // ── checkCode with CVV ─────────────────────────────────────── |
| 104 | |
| 105 | public function test_checkCode_with_cvv_no_cvv_provided_returns_6(): void { |
| 106 | $code = 'CVV' . strtoupper(uniqid()); |
| 107 | $listId = $this->main->getDB()->insert('lists', [ |
| 108 | 'name' => 'CVV List ' . uniqid(), |
| 109 | 'aktiv' => 1, |
| 110 | 'meta' => '{}', |
| 111 | ]); |
| 112 | |
| 113 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 114 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 115 | |
| 116 | $this->main->getDB()->insert('codes', [ |
| 117 | 'code' => $code, |
| 118 | 'code_display' => $code, |
| 119 | 'cvv' => 'SECRET', |
| 120 | 'meta' => $metaJson, |
| 121 | 'aktiv' => 1, |
| 122 | 'redeemed' => 0, |
| 123 | 'list_id' => $listId, |
| 124 | 'order_id' => 0, |
| 125 | ]); |
| 126 | |
| 127 | // Without CVV, should return 6 (ask for CVV) |
| 128 | $result = $this->main->getFrontend()->checkCode(['code' => $code]); |
| 129 | $this->assertEquals(6, $result['valid']); |
| 130 | } |
| 131 | |
| 132 | public function test_checkCode_with_correct_cvv_returns_1(): void { |
| 133 | $code = 'CVVOK' . strtoupper(uniqid()); |
| 134 | $listId = $this->main->getDB()->insert('lists', [ |
| 135 | 'name' => 'CVV OK List ' . uniqid(), |
| 136 | 'aktiv' => 1, |
| 137 | 'meta' => '{}', |
| 138 | ]); |
| 139 | |
| 140 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 141 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 142 | |
| 143 | $this->main->getDB()->insert('codes', [ |
| 144 | 'code' => $code, |
| 145 | 'code_display' => $code, |
| 146 | 'cvv' => 'SECRET', |
| 147 | 'meta' => $metaJson, |
| 148 | 'aktiv' => 1, |
| 149 | 'redeemed' => 0, |
| 150 | 'list_id' => $listId, |
| 151 | 'order_id' => 0, |
| 152 | ]); |
| 153 | |
| 154 | $result = $this->main->getFrontend()->checkCode(['code' => $code, 'cvv' => 'SECRET']); |
| 155 | $this->assertEquals(1, $result['valid']); |
| 156 | } |
| 157 | |
| 158 | public function test_checkCode_with_wrong_cvv_returns_6(): void { |
| 159 | $code = 'CVVBAD' . strtoupper(uniqid()); |
| 160 | $listId = $this->main->getDB()->insert('lists', [ |
| 161 | 'name' => 'CVV Bad List ' . uniqid(), |
| 162 | 'aktiv' => 1, |
| 163 | 'meta' => '{}', |
| 164 | ]); |
| 165 | |
| 166 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 167 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 168 | |
| 169 | $this->main->getDB()->insert('codes', [ |
| 170 | 'code' => $code, |
| 171 | 'code_display' => $code, |
| 172 | 'cvv' => 'SECRET', |
| 173 | 'meta' => $metaJson, |
| 174 | 'aktiv' => 1, |
| 175 | 'redeemed' => 0, |
| 176 | 'list_id' => $listId, |
| 177 | 'order_id' => 0, |
| 178 | ]); |
| 179 | |
| 180 | $result = $this->main->getFrontend()->checkCode(['code' => $code, 'cvv' => 'WRONG']); |
| 181 | $this->assertEquals(6, $result['valid']); |
| 182 | } |
| 183 | |
| 184 | // ── checkCode expired (premium-only feature) ──────────────── |
| 185 | |
| 186 | public function test_checkCodeExpired_returns_false_in_free_version(): void { |
| 187 | // checkCodeExpired only works with premium plugin |
| 188 | $code = 'EXP' . strtoupper(uniqid()); |
| 189 | $listId = $this->main->getDB()->insert('lists', [ |
| 190 | 'name' => 'Expired List ' . uniqid(), |
| 191 | 'aktiv' => 1, |
| 192 | 'meta' => '{}', |
| 193 | ]); |
| 194 | |
| 195 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 196 | $metaObj['expire_date'] = '2020-01-01'; |
| 197 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 198 | |
| 199 | $this->main->getDB()->insert('codes', [ |
| 200 | 'code' => $code, |
| 201 | 'code_display' => $code, |
| 202 | 'cvv' => '', |
| 203 | 'meta' => $metaJson, |
| 204 | 'aktiv' => 1, |
| 205 | 'redeemed' => 0, |
| 206 | 'list_id' => $listId, |
| 207 | 'order_id' => 0, |
| 208 | ]); |
| 209 | |
| 210 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 211 | // In free version, checkCodeExpired always returns false |
| 212 | $this->assertFalse($this->main->getCore()->checkCodeExpired($codeObj)); |
| 213 | } |
| 214 | |
| 215 | // ── checkCode stolen ───────────────────────────────────────── |
| 216 | |
| 217 | public function test_checkCode_stolen_code_returns_7(): void { |
| 218 | $code = 'STOLEN' . strtoupper(uniqid()); |
| 219 | $listId = $this->main->getDB()->insert('lists', [ |
| 220 | 'name' => 'Stolen List ' . uniqid(), |
| 221 | 'aktiv' => 1, |
| 222 | 'meta' => '{}', |
| 223 | ]); |
| 224 | |
| 225 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 226 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 227 | |
| 228 | $this->main->getDB()->insert('codes', [ |
| 229 | 'code' => $code, |
| 230 | 'code_display' => $code, |
| 231 | 'cvv' => '', |
| 232 | 'meta' => $metaJson, |
| 233 | 'aktiv' => 2, // 2 = stolen |
| 234 | 'redeemed' => 0, |
| 235 | 'list_id' => $listId, |
| 236 | 'order_id' => 0, |
| 237 | ]); |
| 238 | |
| 239 | $result = $this->main->getFrontend()->checkCode(['code' => $code]); |
| 240 | $this->assertEquals(7, $result['valid']); |
| 241 | } |
| 242 | } |
| 243 |