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
AdminWCCodeOpsTest.php
233 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for AdminSettings WooCommerce code operations: |
| 4 | * removeRedeemWoocommerceTicketForCode, removeWoocommerceTicketForCode, |
| 5 | * removeWoocommerceRstrPurchaseInfoFromCode, setWoocommerceTicketInfoForCode, |
| 6 | * addCodeFromListForOrder, addRetrictionCodeToOrder. |
| 7 | */ |
| 8 | |
| 9 | class AdminWCCodeOpsTest extends WP_UnitTestCase { |
| 10 | |
| 11 | private $main; |
| 12 | |
| 13 | public function set_up(): void { |
| 14 | parent::set_up(); |
| 15 | $this->main = sasoEventtickets::Instance(); |
| 16 | |
| 17 | if (!class_exists('WC_Product_Simple')) { |
| 18 | $this->markTestSkipped('WooCommerce not available'); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | private function createTicketProduct(): array { |
| 23 | $listId = $this->main->getDB()->insert('lists', [ |
| 24 | 'name' => 'WCOps List ' . uniqid(), |
| 25 | 'aktiv' => 1, |
| 26 | 'meta' => '{}', |
| 27 | ]); |
| 28 | |
| 29 | $product = new WC_Product_Simple(); |
| 30 | $product->set_name('WCOps Product ' . uniqid()); |
| 31 | $product->set_regular_price('20.00'); |
| 32 | $product->set_status('publish'); |
| 33 | $product->save(); |
| 34 | |
| 35 | update_post_meta($product->get_id(), 'saso_eventtickets_is_ticket', 'yes'); |
| 36 | update_post_meta($product->get_id(), 'saso_eventtickets_list', $listId); |
| 37 | |
| 38 | return ['product' => $product, 'product_id' => $product->get_id(), 'list_id' => $listId]; |
| 39 | } |
| 40 | |
| 41 | private function createOrderWithTickets(): array { |
| 42 | $tp = $this->createTicketProduct(); |
| 43 | |
| 44 | $order = wc_create_order(); |
| 45 | $order->add_product($tp['product'], 1); |
| 46 | $order->calculate_totals(); |
| 47 | $order->set_status('completed'); |
| 48 | $order->save(); |
| 49 | |
| 50 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 51 | |
| 52 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 53 | |
| 54 | return [ |
| 55 | 'order' => $order, |
| 56 | 'order_id' => $order->get_id(), |
| 57 | 'codes' => $codes, |
| 58 | 'list_id' => $tp['list_id'], |
| 59 | 'product_id' => $tp['product_id'], |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | // ── removeRedeemWoocommerceTicketForCode ───────────────────── |
| 64 | |
| 65 | public function test_removeRedeemWoocommerceTicketForCode_clears_redeem(): void { |
| 66 | $data = $this->createOrderWithTickets(); |
| 67 | $code = $data['codes'][0]['code']; |
| 68 | |
| 69 | // Set as redeemed first |
| 70 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 71 | $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 72 | $metaObj['wc_ticket']['redeemed_date'] = wp_date('Y-m-d H:i:s'); |
| 73 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 74 | $this->main->getDB()->update('codes', ['meta' => $metaJson, 'redeemed' => 1], ['id' => $codeObj['id']]); |
| 75 | |
| 76 | // Verify it's redeemed |
| 77 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 78 | $this->assertEquals(1, intval($codeObj['redeemed'])); |
| 79 | |
| 80 | // Remove redeem |
| 81 | $this->main->getAdmin()->removeRedeemWoocommerceTicketForCode(['code' => $code]); |
| 82 | |
| 83 | $updated = $this->main->getCore()->retrieveCodeByCode($code); |
| 84 | $updatedMeta = $this->main->getCore()->encodeMetaValuesAndFillObject($updated['meta'], $updated); |
| 85 | |
| 86 | $this->assertEquals(0, intval($updated['redeemed'])); |
| 87 | $this->assertEmpty($updatedMeta['wc_ticket']['redeemed_date']); |
| 88 | } |
| 89 | |
| 90 | public function test_removeRedeemWoocommerceTicketForCode_missing_code_throws(): void { |
| 91 | $this->expectException(Exception::class); |
| 92 | $this->main->getAdmin()->removeRedeemWoocommerceTicketForCode([]); |
| 93 | } |
| 94 | |
| 95 | // ── removeWoocommerceTicketForCode ─────────────────────────── |
| 96 | |
| 97 | public function test_removeWoocommerceTicketForCode_clears_ticket_info(): void { |
| 98 | $data = $this->createOrderWithTickets(); |
| 99 | $code = $data['codes'][0]['code']; |
| 100 | |
| 101 | $this->main->getAdmin()->removeWoocommerceTicketForCode(['code' => $code]); |
| 102 | |
| 103 | $updated = $this->main->getCore()->retrieveCodeByCode($code); |
| 104 | $updatedMeta = $this->main->getCore()->encodeMetaValuesAndFillObject($updated['meta'], $updated); |
| 105 | |
| 106 | $this->assertEquals(0, intval($updatedMeta['wc_ticket']['is_ticket'])); |
| 107 | } |
| 108 | |
| 109 | public function test_removeWoocommerceTicketForCode_missing_code_throws(): void { |
| 110 | $this->expectException(Exception::class); |
| 111 | $this->main->getAdmin()->removeWoocommerceTicketForCode([]); |
| 112 | } |
| 113 | |
| 114 | // ── setWoocommerceTicketInfoForCode ────────────────────────── |
| 115 | |
| 116 | public function test_setWoocommerceTicketInfoForCode_sets_name_and_value(): void { |
| 117 | $data = $this->createOrderWithTickets(); |
| 118 | $code = $data['codes'][0]['code']; |
| 119 | |
| 120 | $this->main->getAdmin()->setWoocommerceTicketInfoForCode( |
| 121 | $code, |
| 122 | 'VIP Pass', |
| 123 | 'John Doe' |
| 124 | ); |
| 125 | |
| 126 | $updated = $this->main->getCore()->retrieveCodeByCode($code); |
| 127 | $updatedMeta = $this->main->getCore()->encodeMetaValuesAndFillObject($updated['meta'], $updated); |
| 128 | |
| 129 | $this->assertEquals('VIP Pass', $updatedMeta['wc_ticket']['name_per_ticket']); |
| 130 | $this->assertEquals('John Doe', $updatedMeta['wc_ticket']['value_per_ticket']); |
| 131 | } |
| 132 | |
| 133 | public function test_setWoocommerceTicketInfoForCode_sets_daychooser(): void { |
| 134 | $data = $this->createOrderWithTickets(); |
| 135 | $code = $data['codes'][0]['code']; |
| 136 | |
| 137 | $this->main->getAdmin()->setWoocommerceTicketInfoForCode( |
| 138 | $code, |
| 139 | '', |
| 140 | '', |
| 141 | '2026-06-15' |
| 142 | ); |
| 143 | |
| 144 | $updated = $this->main->getCore()->retrieveCodeByCode($code); |
| 145 | $updatedMeta = $this->main->getCore()->encodeMetaValuesAndFillObject($updated['meta'], $updated); |
| 146 | |
| 147 | $this->assertEquals('2026-06-15', $updatedMeta['wc_ticket']['day_per_ticket']); |
| 148 | $this->assertEquals(1, intval($updatedMeta['wc_ticket']['is_daychooser'])); |
| 149 | } |
| 150 | |
| 151 | // ── addCodeFromListForOrder ────────────────────────────────── |
| 152 | |
| 153 | public function test_addCodeFromListForOrder_assigns_code(): void { |
| 154 | $listId = $this->main->getDB()->insert('lists', [ |
| 155 | 'name' => 'FromList ' . uniqid(), |
| 156 | 'aktiv' => 1, |
| 157 | 'meta' => '{}', |
| 158 | ]); |
| 159 | |
| 160 | // Pre-add a code to the list |
| 161 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 162 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 163 | $code = 'FROMLIST' . strtoupper(uniqid()); |
| 164 | $this->main->getDB()->insert('codes', [ |
| 165 | 'code' => $code, |
| 166 | 'code_display' => $code, |
| 167 | 'cvv' => '', |
| 168 | 'meta' => $metaJson, |
| 169 | 'aktiv' => 1, |
| 170 | 'redeemed' => 0, |
| 171 | 'list_id' => $listId, |
| 172 | 'order_id' => 0, |
| 173 | ]); |
| 174 | |
| 175 | $product = new WC_Product_Simple(); |
| 176 | $product->set_name('FromList Product'); |
| 177 | $product->set_regular_price('10.00'); |
| 178 | $product->set_status('publish'); |
| 179 | $product->save(); |
| 180 | |
| 181 | $order = wc_create_order(); |
| 182 | $itemId = $order->add_product($product, 1); |
| 183 | $order->calculate_totals(); |
| 184 | $order->set_status('completed'); |
| 185 | $order->save(); |
| 186 | |
| 187 | $result = $this->main->getAdmin()->addCodeFromListForOrder( |
| 188 | $listId, |
| 189 | $order->get_id(), |
| 190 | $product->get_id(), |
| 191 | $itemId |
| 192 | ); |
| 193 | |
| 194 | // Returns the code string directly |
| 195 | $this->assertIsString($result); |
| 196 | $this->assertNotEmpty($result); |
| 197 | |
| 198 | // The code should now be assigned to the order |
| 199 | $codeObj = $this->main->getCore()->retrieveCodeByCode($result); |
| 200 | $this->assertEquals($order->get_id(), intval($codeObj['order_id'])); |
| 201 | } |
| 202 | |
| 203 | public function test_addCodeFromListForOrder_no_available_codes_creates_new(): void { |
| 204 | $listId = $this->main->getDB()->insert('lists', [ |
| 205 | 'name' => 'EmptyList ' . uniqid(), |
| 206 | 'aktiv' => 1, |
| 207 | 'meta' => '{}', |
| 208 | ]); |
| 209 | |
| 210 | $product = new WC_Product_Simple(); |
| 211 | $product->set_name('EmptyList Product'); |
| 212 | $product->set_regular_price('10.00'); |
| 213 | $product->set_status('publish'); |
| 214 | $product->save(); |
| 215 | |
| 216 | $order = wc_create_order(); |
| 217 | $itemId = $order->add_product($product, 1); |
| 218 | $order->calculate_totals(); |
| 219 | $order->set_status('completed'); |
| 220 | $order->save(); |
| 221 | |
| 222 | $result = $this->main->getAdmin()->addCodeFromListForOrder( |
| 223 | $listId, |
| 224 | $order->get_id(), |
| 225 | $product->get_id(), |
| 226 | $itemId |
| 227 | ); |
| 228 | |
| 229 | $this->assertIsString($result); |
| 230 | $this->assertNotEmpty($result); |
| 231 | } |
| 232 | } |
| 233 |