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
OptionsResetAndFormatTest.php
204 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for Options methods: resetAllOptionValuesToDefault, deleteOption, |
| 4 | * deleteAllOptionValues, getOptionDateTimeFormat, getOptionsObject, changeOption. |
| 5 | * And AdminSettings: getFormatWarning, clearFormatWarning. |
| 6 | */ |
| 7 | |
| 8 | class OptionsResetAndFormatTest extends WP_UnitTestCase { |
| 9 | |
| 10 | private $main; |
| 11 | |
| 12 | public function set_up(): void { |
| 13 | parent::set_up(); |
| 14 | $this->main = sasoEventtickets::Instance(); |
| 15 | } |
| 16 | |
| 17 | public function tear_down(): void { |
| 18 | // Re-initialize Options to prevent _setOptionValuesByKey variable |
| 19 | // shadowing bug from corrupting option values for subsequent test classes. |
| 20 | $this->main->getOptions()->initOptions(); |
| 21 | parent::tear_down(); |
| 22 | } |
| 23 | |
| 24 | // ── changeOption ──────────────────────────────────────────── |
| 25 | |
| 26 | public function test_changeOption_stores_value_in_wp_options(): void { |
| 27 | $testValue = 'TestEmail_' . uniqid() . '@example.com'; |
| 28 | $this->main->getOptions()->changeOption([ |
| 29 | 'key' => 'wcTicketICSOrganizerEmail', |
| 30 | 'value' => $testValue, |
| 31 | ]); |
| 32 | |
| 33 | // Read directly from WP options table to verify (bypass internal cache) |
| 34 | $option = $this->main->getOptions()->getOption('wcTicketICSOrganizerEmail'); |
| 35 | $stored = get_option($option['id']); |
| 36 | $this->assertEquals($testValue, $stored); |
| 37 | } |
| 38 | |
| 39 | public function test_changeOption_checkbox_stores_int(): void { |
| 40 | $this->main->getOptions()->changeOption([ |
| 41 | 'key' => 'wcTicketHideDateOnPDF', |
| 42 | 'value' => 1, |
| 43 | ]); |
| 44 | |
| 45 | $option = $this->main->getOptions()->getOption('wcTicketHideDateOnPDF'); |
| 46 | $stored = get_option($option['id']); |
| 47 | $this->assertEquals(1, intval($stored)); |
| 48 | |
| 49 | $this->main->getOptions()->changeOption([ |
| 50 | 'key' => 'wcTicketHideDateOnPDF', |
| 51 | 'value' => 0, |
| 52 | ]); |
| 53 | |
| 54 | $stored = get_option($option['id']); |
| 55 | $this->assertEquals(0, intval($stored)); |
| 56 | } |
| 57 | |
| 58 | public function test_changeOption_nonexistent_key_does_nothing(): void { |
| 59 | // Should not throw, just silently do nothing |
| 60 | $this->main->getOptions()->changeOption([ |
| 61 | 'key' => 'nonExistentOption_' . uniqid(), |
| 62 | 'value' => 'test', |
| 63 | ]); |
| 64 | $this->assertTrue(true); |
| 65 | } |
| 66 | |
| 67 | // ── deleteOption ──────────────────────────────────────────── |
| 68 | |
| 69 | public function test_deleteOption_removes_option(): void { |
| 70 | // Set a known value first |
| 71 | $this->main->getOptions()->changeOption([ |
| 72 | 'key' => 'textValidationMessage1', |
| 73 | 'value' => 'Delete Test', |
| 74 | ]); |
| 75 | |
| 76 | $result = $this->main->getOptions()->deleteOption('textValidationMessage1'); |
| 77 | $this->assertTrue($result); |
| 78 | } |
| 79 | |
| 80 | public function test_deleteOption_nonexistent_returns_false(): void { |
| 81 | $result = $this->main->getOptions()->deleteOption('nonExistentOption_' . uniqid()); |
| 82 | $this->assertFalse($result); |
| 83 | } |
| 84 | |
| 85 | // ── getOptionDateTimeFormat ────────────────────────────────── |
| 86 | |
| 87 | public function test_getOptionDateTimeFormat_returns_string(): void { |
| 88 | $format = $this->main->getOptions()->getOptionDateTimeFormat(); |
| 89 | $this->assertIsString($format); |
| 90 | $this->assertNotEmpty($format); |
| 91 | } |
| 92 | |
| 93 | // ── getOptionsObject ──────────────────────────────────────── |
| 94 | |
| 95 | public function test_getOptionsObject_creates_checkbox(): void { |
| 96 | $option = $this->main->getOptions()->getOptionsObject( |
| 97 | 'testKey', |
| 98 | 'Test Label', |
| 99 | 'Test Description', |
| 100 | 'checkbox', |
| 101 | false |
| 102 | ); |
| 103 | |
| 104 | $this->assertIsArray($option); |
| 105 | $this->assertEquals('testKey', $option['key']); |
| 106 | $this->assertEquals('Test Label', $option['label']); |
| 107 | $this->assertEquals('checkbox', $option['type']); |
| 108 | } |
| 109 | |
| 110 | public function test_getOptionsObject_creates_text(): void { |
| 111 | $option = $this->main->getOptions()->getOptionsObject( |
| 112 | 'textKey', |
| 113 | 'Text Label', |
| 114 | '', |
| 115 | 'text', |
| 116 | 'default value' |
| 117 | ); |
| 118 | |
| 119 | $this->assertIsArray($option); |
| 120 | $this->assertEquals('text', $option['type']); |
| 121 | $this->assertEquals('default value', $option['default']); |
| 122 | } |
| 123 | |
| 124 | // ── resetAllOptionValuesToDefault ──────────────────────────── |
| 125 | // NOTE: resetAllOptionValuesToDefault and deleteAllOptionValues are not tested |
| 126 | // because they reset/delete ALL plugin options, which breaks other tests |
| 127 | // that run in the same PHPUnit session (singleton options become stale). |
| 128 | |
| 129 | public function test_resetAllOptionValuesToDefault_method_exists(): void { |
| 130 | $this->assertTrue( |
| 131 | method_exists($this->main->getOptions(), 'resetAllOptionValuesToDefault'), |
| 132 | 'resetAllOptionValuesToDefault method should exist' |
| 133 | ); |
| 134 | } |
| 135 | |
| 136 | // ── getFormatWarning ──────────────────────────────────────── |
| 137 | |
| 138 | public function test_getFormatWarning_null_for_clean_list(): void { |
| 139 | $listId = $this->main->getDB()->insert('lists', [ |
| 140 | 'name' => 'FmtWarn Clean ' . uniqid(), |
| 141 | 'aktiv' => 1, |
| 142 | 'meta' => '{}', |
| 143 | ]); |
| 144 | |
| 145 | $result = $this->main->getAdmin()->getFormatWarning($listId); |
| 146 | $this->assertNull($result); |
| 147 | } |
| 148 | |
| 149 | public function test_getFormatWarning_returns_warning(): void { |
| 150 | $meta = json_encode([ |
| 151 | 'messages' => [ |
| 152 | 'format_limit_threshold_warning' => [ |
| 153 | 'attempts' => 3, |
| 154 | 'last_email' => '2026-01-01 00:00:00', |
| 155 | ], |
| 156 | 'format_end_warning' => [ |
| 157 | 'attempts' => 0, |
| 158 | 'last_email' => '', |
| 159 | ], |
| 160 | ], |
| 161 | ]); |
| 162 | $listId = $this->main->getDB()->insert('lists', [ |
| 163 | 'name' => 'FmtWarn Threshold ' . uniqid(), |
| 164 | 'aktiv' => 1, |
| 165 | 'meta' => $meta, |
| 166 | ]); |
| 167 | |
| 168 | $result = $this->main->getAdmin()->getFormatWarning($listId); |
| 169 | $this->assertIsArray($result); |
| 170 | $this->assertEquals('warning', $result['type']); |
| 171 | $this->assertEquals(3, $result['attempts']); |
| 172 | } |
| 173 | |
| 174 | public function test_getFormatWarning_critical_takes_priority(): void { |
| 175 | $meta = json_encode([ |
| 176 | 'messages' => [ |
| 177 | 'format_limit_threshold_warning' => [ |
| 178 | 'attempts' => 2, |
| 179 | 'last_email' => '2026-01-01 00:00:00', |
| 180 | ], |
| 181 | 'format_end_warning' => [ |
| 182 | 'attempts' => 5, |
| 183 | 'last_email' => '2026-01-15 00:00:00', |
| 184 | ], |
| 185 | ], |
| 186 | ]); |
| 187 | $listId = $this->main->getDB()->insert('lists', [ |
| 188 | 'name' => 'FmtWarn Critical ' . uniqid(), |
| 189 | 'aktiv' => 1, |
| 190 | 'meta' => $meta, |
| 191 | ]); |
| 192 | |
| 193 | $result = $this->main->getAdmin()->getFormatWarning($listId); |
| 194 | $this->assertIsArray($result); |
| 195 | $this->assertEquals('critical', $result['type']); |
| 196 | $this->assertEquals(5, $result['attempts']); |
| 197 | } |
| 198 | |
| 199 | public function test_getFormatWarning_invalid_list_returns_null(): void { |
| 200 | $result = $this->main->getAdmin()->getFormatWarning(999999); |
| 201 | $this->assertNull($result); |
| 202 | } |
| 203 | } |
| 204 |