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
AuthtokenTest.php
179 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Integration tests for the Authtoken system (scanner access control). |
| 4 | */ |
| 5 | |
| 6 | class AuthtokenTest extends WP_UnitTestCase { |
| 7 | |
| 8 | private sasoEventtickets_Authtoken $auth; |
| 9 | |
| 10 | public function set_up(): void { |
| 11 | parent::set_up(); |
| 12 | $this->auth = sasoEventtickets::Instance()->getAuthtokenHandler(); |
| 13 | } |
| 14 | |
| 15 | // ── addAuthtoken ─────────────────────────────────────────── |
| 16 | |
| 17 | public function test_addAuthtoken_returns_id(): void { |
| 18 | $id = $this->auth->addAuthtoken(['name' => 'PHPUnit Token ' . uniqid()]); |
| 19 | $this->assertGreaterThan(0, $id); |
| 20 | } |
| 21 | |
| 22 | public function test_addAuthtoken_throws_without_name(): void { |
| 23 | $this->expectException(Exception::class); |
| 24 | $this->auth->addAuthtoken([]); |
| 25 | } |
| 26 | |
| 27 | public function test_addAuthtoken_throws_with_empty_name(): void { |
| 28 | $this->expectException(Exception::class); |
| 29 | $this->auth->addAuthtoken(['name' => '']); |
| 30 | } |
| 31 | |
| 32 | // ── getAuthtokens ────────────────────────────────────────── |
| 33 | |
| 34 | public function test_getAuthtokens_returns_array(): void { |
| 35 | $this->auth->addAuthtoken(['name' => 'List Test ' . uniqid()]); |
| 36 | $tokens = $this->auth->getAuthtokens(); |
| 37 | $this->assertIsArray($tokens); |
| 38 | $this->assertNotEmpty($tokens); |
| 39 | } |
| 40 | |
| 41 | // ── getAuthtokenByCode ───────────────────────────────────── |
| 42 | |
| 43 | public function test_getAuthtokenByCode_finds_token(): void { |
| 44 | $id = $this->auth->addAuthtoken(['name' => 'ByCode Test ' . uniqid()]); |
| 45 | |
| 46 | // Get all to find the code |
| 47 | $tokens = $this->auth->getAuthtokens(); |
| 48 | $code = null; |
| 49 | foreach ($tokens as $t) { |
| 50 | if ((int)$t['id'] === $id) { |
| 51 | $code = $t['code']; |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | $this->assertNotNull($code); |
| 56 | |
| 57 | $found = $this->auth->getAuthtokenByCode($code); |
| 58 | $this->assertEquals($id, $found['id']); |
| 59 | } |
| 60 | |
| 61 | public function test_getAuthtokenByCode_throws_for_invalid(): void { |
| 62 | $this->expectException(Exception::class); |
| 63 | $this->auth->getAuthtokenByCode('nonexistent_code_xyz_' . uniqid()); |
| 64 | } |
| 65 | |
| 66 | public function test_getAuthtokenByCode_throws_for_empty(): void { |
| 67 | $this->expectException(Exception::class); |
| 68 | $this->auth->getAuthtokenByCode(''); |
| 69 | } |
| 70 | |
| 71 | // ── checkAccessForAuthtoken ──────────────────────────────── |
| 72 | |
| 73 | public function test_checkAccess_valid_token(): void { |
| 74 | $id = $this->auth->addAuthtoken(['name' => 'Access Test ' . uniqid()]); |
| 75 | $tokens = $this->auth->getAuthtokens(); |
| 76 | $code = null; |
| 77 | foreach ($tokens as $t) { |
| 78 | if ((int)$t['id'] === $id) { |
| 79 | $code = $t['code']; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | $this->assertTrue($this->auth->checkAccessForAuthtoken($code)); |
| 85 | } |
| 86 | |
| 87 | public function test_checkAccess_invalid_token_returns_false(): void { |
| 88 | $this->assertFalse($this->auth->checkAccessForAuthtoken('invalid_code_' . uniqid())); |
| 89 | } |
| 90 | |
| 91 | public function test_checkAccess_empty_returns_false(): void { |
| 92 | $this->assertFalse($this->auth->checkAccessForAuthtoken('')); |
| 93 | } |
| 94 | |
| 95 | // ── editAuthtoken ────────────────────────────────────────── |
| 96 | |
| 97 | public function test_editAuthtoken_changes_name(): void { |
| 98 | $id = $this->auth->addAuthtoken(['name' => 'Before Edit']); |
| 99 | $newName = 'After Edit ' . uniqid(); |
| 100 | $this->auth->editAuthtoken(['id' => $id, 'name' => $newName]); |
| 101 | |
| 102 | $token = $this->auth->getAuthtoken(['id' => $id]); |
| 103 | $this->assertSame($newName, $token['name']); |
| 104 | } |
| 105 | |
| 106 | public function test_editAuthtoken_deactivate(): void { |
| 107 | $id = $this->auth->addAuthtoken(['name' => 'Deactivate Test ' . uniqid()]); |
| 108 | |
| 109 | // Deactivate |
| 110 | $this->auth->editAuthtoken(['id' => $id, 'aktiv' => 0]); |
| 111 | |
| 112 | // getAuthtokenByCode should fail (only finds aktiv=1) |
| 113 | $tokens = $this->auth->getAuthtokens(); |
| 114 | $found = null; |
| 115 | foreach ($tokens as $t) { |
| 116 | if ((int)$t['id'] === $id) { |
| 117 | $found = $t; |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | $this->assertNotNull($found); |
| 122 | $this->assertEquals(0, $found['aktiv']); |
| 123 | } |
| 124 | |
| 125 | public function test_editAuthtoken_throws_without_id(): void { |
| 126 | $this->expectException(Exception::class); |
| 127 | $this->auth->editAuthtoken(['name' => 'No ID']); |
| 128 | } |
| 129 | |
| 130 | // ── removeAuthtoken ──────────────────────────────────────── |
| 131 | |
| 132 | public function test_removeAuthtoken_deletes(): void { |
| 133 | $id = $this->auth->addAuthtoken(['name' => 'Remove Test ' . uniqid()]); |
| 134 | |
| 135 | $this->auth->removeAuthtoken(['id' => $id]); |
| 136 | |
| 137 | // Should not be in list anymore |
| 138 | $tokens = $this->auth->getAuthtokens(); |
| 139 | $ids = array_column($tokens, 'id'); |
| 140 | $this->assertNotContains($id, $ids); |
| 141 | } |
| 142 | |
| 143 | public function test_removeAuthtoken_throws_without_id(): void { |
| 144 | $this->expectException(Exception::class); |
| 145 | $this->auth->removeAuthtoken([]); |
| 146 | } |
| 147 | |
| 148 | // ── isProductAllowedByAuthToken ──────────────────────────── |
| 149 | |
| 150 | public function test_isProductAllowed_no_restriction_allows_all(): void { |
| 151 | $id = $this->auth->addAuthtoken(['name' => 'No Restrict ' . uniqid()]); |
| 152 | $tokens = $this->auth->getAuthtokens(); |
| 153 | $code = null; |
| 154 | foreach ($tokens as $t) { |
| 155 | if ((int)$t['id'] === $id) { |
| 156 | $code = $t['code']; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // No bound_to_products set → should allow any product |
| 162 | $this->assertTrue($this->auth->isProductAllowedByAuthToken($code, [123, 456])); |
| 163 | } |
| 164 | |
| 165 | public function test_isProductAllowed_empty_product_ids_allows(): void { |
| 166 | $id = $this->auth->addAuthtoken(['name' => 'Empty IDs ' . uniqid()]); |
| 167 | $tokens = $this->auth->getAuthtokens(); |
| 168 | $code = null; |
| 169 | foreach ($tokens as $t) { |
| 170 | if ((int)$t['id'] === $id) { |
| 171 | $code = $t['code']; |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | $this->assertTrue($this->auth->isProductAllowedByAuthToken($code, [])); |
| 177 | } |
| 178 | } |
| 179 |