bin
3 months ago
fixtures
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
ContextWizardTest.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
OldPremiumGuardTest.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
OptionsHistoryTest.php
3 months ago
OptionsMigrationTest.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
SeatingExportTest.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
test-premium-compat.sh
3 months ago
OrderMetaKeyValueDisplayTest.php
423 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for WC Order meta key/value display transformation and restriction codes: |
| 4 | * - woocommerce_order_item_display_meta_key: transforms internal meta keys to labels |
| 5 | * - woocommerce_order_item_display_meta_value: transforms meta values for admin display |
| 6 | * - addRetrictionCodeToOrder: links restriction code to order |
| 7 | * - _editList format-warning-reset branch |
| 8 | * - changeOption: admin wrapper for option changes |
| 9 | */ |
| 10 | |
| 11 | class OrderMetaKeyValueDisplayTest extends WP_UnitTestCase { |
| 12 | |
| 13 | private $main; |
| 14 | |
| 15 | public function set_up(): void { |
| 16 | parent::set_up(); |
| 17 | $this->main = sasoEventtickets::Instance(); |
| 18 | |
| 19 | if (!class_exists('WC_Product_Simple')) { |
| 20 | $this->markTestSkipped('WooCommerce not available'); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | public function tear_down(): void { |
| 25 | // Reset admin screen context to prevent leaking into other tests |
| 26 | set_current_screen('front'); |
| 27 | parent::tear_down(); |
| 28 | } |
| 29 | |
| 30 | private function createOrderWithTicketItem(): array { |
| 31 | $listId = $this->main->getDB()->insert('lists', [ |
| 32 | 'name' => 'KeyVal List ' . uniqid(), |
| 33 | 'aktiv' => 1, |
| 34 | 'meta' => '{}', |
| 35 | ]); |
| 36 | |
| 37 | $product = new WC_Product_Simple(); |
| 38 | $product->set_name('KeyVal Ticket ' . uniqid()); |
| 39 | $product->set_regular_price('10.00'); |
| 40 | $product->set_status('publish'); |
| 41 | $product->save(); |
| 42 | $pid = $product->get_id(); |
| 43 | |
| 44 | update_post_meta($pid, 'saso_eventtickets_is_ticket', 'yes'); |
| 45 | update_post_meta($pid, 'saso_eventtickets_list', $listId); |
| 46 | |
| 47 | $order = wc_create_order(); |
| 48 | $order->add_product($product, 1); |
| 49 | $order->set_billing_first_name('KeyVal'); |
| 50 | $order->set_billing_last_name('Test'); |
| 51 | $order->set_billing_email('keyval@test.com'); |
| 52 | $order->calculate_totals(); |
| 53 | $order->set_status('completed'); |
| 54 | $order->save(); |
| 55 | $order = wc_get_order($order->get_id()); |
| 56 | |
| 57 | $items = $order->get_items(); |
| 58 | $item_id = key($items); |
| 59 | $item = current($items); |
| 60 | |
| 61 | return [ |
| 62 | 'order' => $order, |
| 63 | 'item_id' => $item_id, |
| 64 | 'item' => $item, |
| 65 | 'product_id' => $pid, |
| 66 | 'list_id' => $listId, |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | private function makeMeta(string $key, string $value = ''): object { |
| 71 | $meta = new stdClass(); |
| 72 | $meta->key = $key; |
| 73 | $meta->value = $value; |
| 74 | return $meta; |
| 75 | } |
| 76 | |
| 77 | // ── woocommerce_order_item_display_meta_key ────────────────── |
| 78 | |
| 79 | public function test_display_meta_key_transforms_ticket_codes(): void { |
| 80 | set_current_screen('edit-shop_order'); |
| 81 | |
| 82 | $data = $this->createOrderWithTicketItem(); |
| 83 | // Ensure is_ticket meta exists |
| 84 | wc_update_order_item_meta($data['item_id'], '_saso_eventtickets_is_ticket', 1); |
| 85 | |
| 86 | // Refresh order/item |
| 87 | $order = wc_get_order($data['order']->get_id()); |
| 88 | $items = $order->get_items(); |
| 89 | $item = current($items); |
| 90 | |
| 91 | $meta = $this->makeMeta('_saso_eventtickets_product_code'); |
| 92 | |
| 93 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 94 | '_saso_eventtickets_product_code', $meta, $item |
| 95 | ); |
| 96 | |
| 97 | $this->assertEquals('Ticket number(s)', $result); |
| 98 | } |
| 99 | |
| 100 | public function test_display_meta_key_transforms_public_ids(): void { |
| 101 | set_current_screen('edit-shop_order'); |
| 102 | $data = $this->createOrderWithTicketItem(); |
| 103 | $meta = $this->makeMeta('_saso_eventtickets_public_ticket_ids'); |
| 104 | |
| 105 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 106 | '_saso_eventtickets_public_ticket_ids', $meta, $data['item'] |
| 107 | ); |
| 108 | |
| 109 | $this->assertEquals('Public Ticket Id(s)', $result); |
| 110 | } |
| 111 | |
| 112 | public function test_display_meta_key_transforms_is_ticket(): void { |
| 113 | set_current_screen('edit-shop_order'); |
| 114 | $data = $this->createOrderWithTicketItem(); |
| 115 | $meta = $this->makeMeta('_saso_eventtickets_is_ticket'); |
| 116 | |
| 117 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 118 | '_saso_eventtickets_is_ticket', $meta, $data['item'] |
| 119 | ); |
| 120 | |
| 121 | $this->assertEquals('Is Ticket', $result); |
| 122 | } |
| 123 | |
| 124 | public function test_display_meta_key_transforms_list_id(): void { |
| 125 | set_current_screen('edit-shop_order'); |
| 126 | $data = $this->createOrderWithTicketItem(); |
| 127 | $meta = $this->makeMeta('_saso_eventticket_code_list'); |
| 128 | |
| 129 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 130 | '_saso_eventticket_code_list', $meta, $data['item'] |
| 131 | ); |
| 132 | |
| 133 | $this->assertEquals('List ID', $result); |
| 134 | } |
| 135 | |
| 136 | public function test_display_meta_key_transforms_daychooser(): void { |
| 137 | set_current_screen('edit-shop_order'); |
| 138 | $data = $this->createOrderWithTicketItem(); |
| 139 | $meta = $this->makeMeta('_saso_eventtickets_daychooser'); |
| 140 | |
| 141 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 142 | '_saso_eventtickets_daychooser', $meta, $data['item'] |
| 143 | ); |
| 144 | |
| 145 | $this->assertEquals('Day(s) per ticket', $result); |
| 146 | } |
| 147 | |
| 148 | public function test_display_meta_key_leaves_unknown_unchanged(): void { |
| 149 | set_current_screen('edit-shop_order'); |
| 150 | $data = $this->createOrderWithTicketItem(); |
| 151 | $meta = $this->makeMeta('some_random_meta'); |
| 152 | |
| 153 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 154 | 'some_random_meta', $meta, $data['item'] |
| 155 | ); |
| 156 | |
| 157 | $this->assertEquals('some_random_meta', $result); |
| 158 | } |
| 159 | |
| 160 | public function test_display_meta_key_is_filterable(): void { |
| 161 | set_current_screen('edit-shop_order'); |
| 162 | $data = $this->createOrderWithTicketItem(); |
| 163 | $meta = $this->makeMeta('_saso_eventtickets_is_ticket'); |
| 164 | |
| 165 | $filter = function ($key) { return 'Custom Label'; }; |
| 166 | add_filter('saso_eventtickets_woocommerce-hooks_woocommerce_order_item_display_meta_key', $filter); |
| 167 | |
| 168 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_key( |
| 169 | '_saso_eventtickets_is_ticket', $meta, $data['item'] |
| 170 | ); |
| 171 | $this->assertEquals('Custom Label', $result); |
| 172 | |
| 173 | remove_filter('saso_eventtickets_woocommerce-hooks_woocommerce_order_item_display_meta_key', $filter); |
| 174 | } |
| 175 | |
| 176 | // ── woocommerce_order_item_display_meta_value ──────────────── |
| 177 | |
| 178 | public function test_display_meta_value_wraps_codes_in_links(): void { |
| 179 | set_current_screen('edit-shop_order'); |
| 180 | $data = $this->createOrderWithTicketItem(); |
| 181 | $meta = $this->makeMeta('_saso_eventtickets_product_code', 'ABC123,DEF456'); |
| 182 | |
| 183 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 184 | 'ABC123,DEF456', $meta, $data['item'] |
| 185 | ); |
| 186 | |
| 187 | $this->assertStringContainsString('<a target="_blank"', $result); |
| 188 | $this->assertStringContainsString('ABC123', $result); |
| 189 | $this->assertStringContainsString('DEF456', $result); |
| 190 | } |
| 191 | |
| 192 | public function test_display_meta_value_formats_is_ticket_yes(): void { |
| 193 | set_current_screen('edit-shop_order'); |
| 194 | $data = $this->createOrderWithTicketItem(); |
| 195 | $meta = $this->makeMeta('_saso_eventtickets_is_ticket', '1'); |
| 196 | |
| 197 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 198 | '1', $meta, $data['item'] |
| 199 | ); |
| 200 | $this->assertEquals('Yes', $result); |
| 201 | } |
| 202 | |
| 203 | public function test_display_meta_value_formats_is_ticket_no(): void { |
| 204 | set_current_screen('edit-shop_order'); |
| 205 | $data = $this->createOrderWithTicketItem(); |
| 206 | $meta = $this->makeMeta('_saso_eventtickets_is_ticket', '0'); |
| 207 | |
| 208 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 209 | '0', $meta, $data['item'] |
| 210 | ); |
| 211 | $this->assertEquals('No', $result); |
| 212 | } |
| 213 | |
| 214 | public function test_display_meta_value_formats_empty_public_ids_as_dash(): void { |
| 215 | set_current_screen('edit-shop_order'); |
| 216 | $data = $this->createOrderWithTicketItem(); |
| 217 | $meta = $this->makeMeta('_saso_eventtickets_public_ticket_ids', ''); |
| 218 | |
| 219 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 220 | '', $meta, $data['item'] |
| 221 | ); |
| 222 | $this->assertEquals('-', $result); |
| 223 | } |
| 224 | |
| 225 | public function test_display_meta_value_formats_daychooser_dates(): void { |
| 226 | set_current_screen('edit-shop_order'); |
| 227 | $data = $this->createOrderWithTicketItem(); |
| 228 | $meta = $this->makeMeta('_saso_eventtickets_daychooser', '2026-08-15, 2026-08-16'); |
| 229 | |
| 230 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 231 | '2026-08-15, 2026-08-16', $meta, $data['item'] |
| 232 | ); |
| 233 | |
| 234 | $this->assertStringContainsString('2026-08-15', $result); |
| 235 | $this->assertStringContainsString('2026-08-16', $result); |
| 236 | } |
| 237 | |
| 238 | public function test_display_meta_value_formats_seat_labels(): void { |
| 239 | set_current_screen('edit-shop_order'); |
| 240 | $data = $this->createOrderWithTicketItem(); |
| 241 | $meta = $this->makeMeta('_saso_eventtickets_seat_labels', '["A1","A2","B3"]'); |
| 242 | |
| 243 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 244 | '["A1","A2","B3"]', $meta, $data['item'] |
| 245 | ); |
| 246 | |
| 247 | $this->assertStringContainsString('A1', $result); |
| 248 | $this->assertStringContainsString('B3', $result); |
| 249 | } |
| 250 | |
| 251 | public function test_display_meta_value_is_filterable(): void { |
| 252 | set_current_screen('edit-shop_order'); |
| 253 | $data = $this->createOrderWithTicketItem(); |
| 254 | $meta = $this->makeMeta('_saso_eventtickets_is_ticket', '1'); |
| 255 | |
| 256 | $filter = function ($val) { return 'Overridden'; }; |
| 257 | add_filter('saso_eventtickets_woocommerce-hooks_woocommerce_order_item_display_meta_value', $filter); |
| 258 | |
| 259 | $result = $this->main->getWC()->getOrderManager()->woocommerce_order_item_display_meta_value( |
| 260 | '1', $meta, $data['item'] |
| 261 | ); |
| 262 | $this->assertEquals('Overridden', $result); |
| 263 | |
| 264 | remove_filter('saso_eventtickets_woocommerce-hooks_woocommerce_order_item_display_meta_value', $filter); |
| 265 | } |
| 266 | |
| 267 | // ── addRetrictionCodeToOrder ────────────────────────────────── |
| 268 | |
| 269 | public function test_addRetrictionCodeToOrder_writes_wc_rp_meta(): void { |
| 270 | $data = $this->createOrderWithTicketItem(); |
| 271 | |
| 272 | // Create a code in the list |
| 273 | $code = 'RESTRICT_' . uniqid(); |
| 274 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 275 | $codeId = $this->main->getDB()->insert('codes', [ |
| 276 | 'code' => $code, |
| 277 | 'list_id' => $data['list_id'], |
| 278 | 'redeemed' => 0, |
| 279 | 'aktiv' => 1, |
| 280 | 'meta' => json_encode($metaObj), |
| 281 | ]); |
| 282 | |
| 283 | $this->main->getAdmin()->addRetrictionCodeToOrder( |
| 284 | $code, $data['list_id'], $data['order']->get_id(), $data['product_id'], $data['item_id'] |
| 285 | ); |
| 286 | |
| 287 | // Read back code and check meta |
| 288 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 289 | $meta = json_decode($codeObj['meta'], true); |
| 290 | |
| 291 | $this->assertArrayHasKey('wc_rp', $meta); |
| 292 | $this->assertEquals($data['order']->get_id(), $meta['wc_rp']['order_id']); |
| 293 | $this->assertEquals($data['product_id'], $meta['wc_rp']['product_id']); |
| 294 | $this->assertEquals($data['item_id'], $meta['wc_rp']['item_id']); |
| 295 | } |
| 296 | |
| 297 | public function test_addRetrictionCodeToOrder_skips_empty_code(): void { |
| 298 | $data = $this->createOrderWithTicketItem(); |
| 299 | |
| 300 | // Empty code should return without error |
| 301 | $result = $this->main->getAdmin()->addRetrictionCodeToOrder( |
| 302 | '', $data['list_id'], $data['order']->get_id() |
| 303 | ); |
| 304 | $this->assertNull($result); |
| 305 | } |
| 306 | |
| 307 | // ── _editList format-warning-reset ─────────────────────────── |
| 308 | |
| 309 | public function test_editList_clears_format_warnings_when_last_email_set(): void { |
| 310 | // Create list with format warnings |
| 311 | $warningMeta = json_encode([ |
| 312 | 'desc' => '', |
| 313 | 'redirect' => ['url' => ''], |
| 314 | 'formatter' => ['active' => 1, 'format' => ''], |
| 315 | 'webhooks' => ['webhookURLaddwcticketsold' => ''], |
| 316 | 'messages' => [ |
| 317 | 'format_limit_threshold_warning' => ['attempts' => 5, 'last_email' => '2026-02-20 10:00:00'], |
| 318 | 'format_end_warning' => ['attempts' => 3, 'last_email' => '2026-02-21 12:00:00'], |
| 319 | ], |
| 320 | ]); |
| 321 | $listId = $this->main->getDB()->insert('lists', [ |
| 322 | 'name' => 'Warning Reset Test ' . uniqid(), |
| 323 | 'aktiv' => 1, |
| 324 | 'meta' => $warningMeta, |
| 325 | ]); |
| 326 | |
| 327 | // Edit the list (this should clear warnings) |
| 328 | $listObj = $this->main->getAdmin()->getList(['id' => $listId]); |
| 329 | $this->main->getAdmin()->_editList([ |
| 330 | 'id' => $listId, |
| 331 | 'name' => $listObj['name'], |
| 332 | ]); |
| 333 | |
| 334 | // Read back and check warnings were cleared |
| 335 | $updatedList = $this->main->getAdmin()->getList(['id' => $listId]); |
| 336 | $meta = json_decode($updatedList['meta'], true); |
| 337 | |
| 338 | $this->assertEquals(0, $meta['messages']['format_limit_threshold_warning']['attempts']); |
| 339 | $this->assertEquals('', $meta['messages']['format_limit_threshold_warning']['last_email']); |
| 340 | $this->assertEquals(0, $meta['messages']['format_end_warning']['attempts']); |
| 341 | $this->assertEquals('', $meta['messages']['format_end_warning']['last_email']); |
| 342 | } |
| 343 | |
| 344 | public function test_editList_preserves_clean_warnings(): void { |
| 345 | // Create list WITHOUT format warnings |
| 346 | $cleanMeta = json_encode([ |
| 347 | 'desc' => '', |
| 348 | 'redirect' => ['url' => ''], |
| 349 | 'formatter' => ['active' => 1, 'format' => ''], |
| 350 | 'webhooks' => ['webhookURLaddwcticketsold' => ''], |
| 351 | 'messages' => [ |
| 352 | 'format_limit_threshold_warning' => ['attempts' => 0, 'last_email' => ''], |
| 353 | 'format_end_warning' => ['attempts' => 0, 'last_email' => ''], |
| 354 | ], |
| 355 | ]); |
| 356 | $listId = $this->main->getDB()->insert('lists', [ |
| 357 | 'name' => 'No Warning Test ' . uniqid(), |
| 358 | 'aktiv' => 1, |
| 359 | 'meta' => $cleanMeta, |
| 360 | ]); |
| 361 | |
| 362 | $listObj = $this->main->getAdmin()->getList(['id' => $listId]); |
| 363 | $this->main->getAdmin()->_editList([ |
| 364 | 'id' => $listId, |
| 365 | 'name' => $listObj['name'], |
| 366 | ]); |
| 367 | |
| 368 | // Warnings should still be at 0 |
| 369 | $updatedList = $this->main->getAdmin()->getList(['id' => $listId]); |
| 370 | $meta = json_decode($updatedList['meta'], true); |
| 371 | |
| 372 | $this->assertEquals(0, $meta['messages']['format_limit_threshold_warning']['attempts']); |
| 373 | $this->assertEquals(0, $meta['messages']['format_end_warning']['attempts']); |
| 374 | } |
| 375 | |
| 376 | // ── changeOption ───────────────────────────────────────────── |
| 377 | |
| 378 | public function test_changeOption_sets_checkbox_value(): void { |
| 379 | $this->main->getAdmin()->changeOption([ |
| 380 | 'key' => 'wcTicketDontAllowRedeemTicketBeforeStart', |
| 381 | 'value' => '1', |
| 382 | ]); |
| 383 | $this->main->getOptions()->initOptions(); |
| 384 | |
| 385 | $this->assertTrue( |
| 386 | $this->main->getOptions()->isOptionCheckboxActive('wcTicketDontAllowRedeemTicketBeforeStart') |
| 387 | ); |
| 388 | |
| 389 | // Reset |
| 390 | $this->main->getAdmin()->changeOption([ |
| 391 | 'key' => 'wcTicketDontAllowRedeemTicketBeforeStart', |
| 392 | 'value' => '0', |
| 393 | ]); |
| 394 | $this->main->getOptions()->initOptions(); |
| 395 | } |
| 396 | |
| 397 | public function test_changeOption_sets_text_value(): void { |
| 398 | $this->main->getAdmin()->changeOption([ |
| 399 | 'key' => 'displayDateFormat', |
| 400 | 'value' => 'd.m.Y', |
| 401 | ]); |
| 402 | $this->main->getOptions()->initOptions(); |
| 403 | |
| 404 | $this->assertEquals('d.m.Y', $this->main->getOptions()->getOptionValue('displayDateFormat')); |
| 405 | |
| 406 | // Reset |
| 407 | $this->main->getAdmin()->changeOption([ |
| 408 | 'key' => 'displayDateFormat', |
| 409 | 'value' => 'Y/m/d', |
| 410 | ]); |
| 411 | $this->main->getOptions()->initOptions(); |
| 412 | } |
| 413 | |
| 414 | public function test_changeOption_ignores_unknown_key(): void { |
| 415 | // Should not crash for unknown key |
| 416 | $this->main->getAdmin()->changeOption([ |
| 417 | 'key' => 'nonexistent_option_xyz', |
| 418 | 'value' => 'test', |
| 419 | ]); |
| 420 | $this->assertTrue(true); // No exception = pass |
| 421 | } |
| 422 | } |
| 423 |