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
AuthtokenAccessTest.php
154 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for Authtoken methods: checkAccessForAuthtoken, |
| 4 | * isProductAllowedByAuthToken, getAuthtokenByCode, getAuthtokens. |
| 5 | */ |
| 6 | |
| 7 | class AuthtokenAccessTest extends WP_UnitTestCase { |
| 8 | |
| 9 | private $main; |
| 10 | |
| 11 | public function set_up(): void { |
| 12 | parent::set_up(); |
| 13 | $this->main = sasoEventtickets::Instance(); |
| 14 | } |
| 15 | |
| 16 | private function createActiveAuthtoken(): array { |
| 17 | $code = 'AUTH' . strtoupper(uniqid()); |
| 18 | $metaObj = $this->main->getCore()->getMetaObjectAuthtoken(); |
| 19 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 20 | |
| 21 | $id = $this->main->getDB()->insert('authtokens', [ |
| 22 | 'code' => $code, |
| 23 | 'name' => 'Test Token ' . uniqid(), |
| 24 | 'aktiv' => 1, |
| 25 | 'meta' => $metaJson, |
| 26 | ]); |
| 27 | |
| 28 | return ['id' => $id, 'code' => $code]; |
| 29 | } |
| 30 | |
| 31 | // ── checkAccessForAuthtoken ─────────────────────────────────── |
| 32 | |
| 33 | public function test_checkAccessForAuthtoken_true_for_valid(): void { |
| 34 | $token = $this->createActiveAuthtoken(); |
| 35 | $result = $this->main->getAuthtokenHandler()->checkAccessForAuthtoken($token['code']); |
| 36 | $this->assertTrue($result); |
| 37 | } |
| 38 | |
| 39 | public function test_checkAccessForAuthtoken_false_for_invalid(): void { |
| 40 | $result = $this->main->getAuthtokenHandler()->checkAccessForAuthtoken('NONEXISTENT_' . uniqid()); |
| 41 | $this->assertFalse($result); |
| 42 | } |
| 43 | |
| 44 | public function test_checkAccessForAuthtoken_false_for_empty(): void { |
| 45 | $result = $this->main->getAuthtokenHandler()->checkAccessForAuthtoken(''); |
| 46 | $this->assertFalse($result); |
| 47 | } |
| 48 | |
| 49 | public function test_checkAccessForAuthtoken_false_for_inactive(): void { |
| 50 | $code = 'INACT' . strtoupper(uniqid()); |
| 51 | $metaObj = $this->main->getCore()->getMetaObjectAuthtoken(); |
| 52 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 53 | |
| 54 | $this->main->getDB()->insert('authtokens', [ |
| 55 | 'code' => $code, |
| 56 | 'name' => 'Inactive Token', |
| 57 | 'aktiv' => 0, |
| 58 | 'meta' => $metaJson, |
| 59 | ]); |
| 60 | |
| 61 | $result = $this->main->getAuthtokenHandler()->checkAccessForAuthtoken($code); |
| 62 | $this->assertFalse($result); |
| 63 | } |
| 64 | |
| 65 | // ── getAuthtokenByCode ─────────────────────────────────────── |
| 66 | |
| 67 | public function test_getAuthtokenByCode_returns_array(): void { |
| 68 | $token = $this->createActiveAuthtoken(); |
| 69 | $result = $this->main->getAuthtokenHandler()->getAuthtokenByCode($token['code']); |
| 70 | $this->assertIsArray($result); |
| 71 | $this->assertEquals($token['code'], $result['code']); |
| 72 | } |
| 73 | |
| 74 | public function test_getAuthtokenByCode_throws_for_empty(): void { |
| 75 | $this->expectException(Exception::class); |
| 76 | $this->main->getAuthtokenHandler()->getAuthtokenByCode(''); |
| 77 | } |
| 78 | |
| 79 | public function test_getAuthtokenByCode_throws_for_nonexistent(): void { |
| 80 | $this->expectException(Exception::class); |
| 81 | $this->main->getAuthtokenHandler()->getAuthtokenByCode('NOTFOUND_' . uniqid()); |
| 82 | } |
| 83 | |
| 84 | // ── getAuthtokens ──────────────────────────────────────────── |
| 85 | |
| 86 | public function test_getAuthtokens_returns_array(): void { |
| 87 | $result = $this->main->getAuthtokenHandler()->getAuthtokens(); |
| 88 | $this->assertIsArray($result); |
| 89 | } |
| 90 | |
| 91 | public function test_getAuthtokens_contains_created_token(): void { |
| 92 | $token = $this->createActiveAuthtoken(); |
| 93 | $tokens = $this->main->getAuthtokenHandler()->getAuthtokens(); |
| 94 | |
| 95 | $found = false; |
| 96 | foreach ($tokens as $t) { |
| 97 | if ($t['code'] === $token['code']) { |
| 98 | $found = true; |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | $this->assertTrue($found, "Created authtoken not found in getAuthtokens()"); |
| 103 | } |
| 104 | |
| 105 | // ── isProductAllowedByAuthToken ────────────────────────────── |
| 106 | |
| 107 | public function test_isProductAllowedByAuthToken_true_no_restriction(): void { |
| 108 | $token = $this->createActiveAuthtoken(); |
| 109 | // No bound_to_products set → all products allowed |
| 110 | $result = $this->main->getAuthtokenHandler()->isProductAllowedByAuthToken($token['code'], [42]); |
| 111 | $this->assertTrue($result); |
| 112 | } |
| 113 | |
| 114 | public function test_isProductAllowedByAuthToken_true_empty_products(): void { |
| 115 | $token = $this->createActiveAuthtoken(); |
| 116 | $result = $this->main->getAuthtokenHandler()->isProductAllowedByAuthToken($token['code'], []); |
| 117 | $this->assertTrue($result); |
| 118 | } |
| 119 | |
| 120 | public function test_isProductAllowedByAuthToken_true_for_allowed_product(): void { |
| 121 | $code = 'PROD' . strtoupper(uniqid()); |
| 122 | $metaObj = $this->main->getCore()->getMetaObjectAuthtoken(); |
| 123 | $metaObj['ticketscanner']['bound_to_products'] = '42,100,200'; |
| 124 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 125 | |
| 126 | $this->main->getDB()->insert('authtokens', [ |
| 127 | 'code' => $code, |
| 128 | 'name' => 'Restricted Token', |
| 129 | 'aktiv' => 1, |
| 130 | 'meta' => $metaJson, |
| 131 | ]); |
| 132 | |
| 133 | $result = $this->main->getAuthtokenHandler()->isProductAllowedByAuthToken($code, [42]); |
| 134 | $this->assertTrue($result); |
| 135 | } |
| 136 | |
| 137 | public function test_isProductAllowedByAuthToken_false_for_disallowed_product(): void { |
| 138 | $code = 'DENY' . strtoupper(uniqid()); |
| 139 | $metaObj = $this->main->getCore()->getMetaObjectAuthtoken(); |
| 140 | $metaObj['ticketscanner']['bound_to_products'] = '42,100'; |
| 141 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 142 | |
| 143 | $this->main->getDB()->insert('authtokens', [ |
| 144 | 'code' => $code, |
| 145 | 'name' => 'Restricted Token', |
| 146 | 'aktiv' => 1, |
| 147 | 'meta' => $metaJson, |
| 148 | ]); |
| 149 | |
| 150 | $result = $this->main->getAuthtokenHandler()->isProductAllowedByAuthToken($code, [999]); |
| 151 | $this->assertFalse($result); |
| 152 | } |
| 153 | } |
| 154 |