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
WCOrderDeleteTest.php
146 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for WC Order deletion and cleanup methods: |
| 4 | * deleteCodesEntryOnOrderItem, deleteRestrictionEntryOnOrderItem, |
| 5 | * woocommerce_pre_delete_order_refund. |
| 6 | */ |
| 7 | |
| 8 | class WCOrderDeleteTest 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 | if (!class_exists('WC_Product_Simple')) { |
| 17 | $this->markTestSkipped('WooCommerce not available'); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | private function createTicketOrder(): array { |
| 22 | $listId = $this->main->getDB()->insert('lists', [ |
| 23 | 'name' => 'DeleteTest List ' . uniqid(), |
| 24 | 'aktiv' => 1, |
| 25 | 'meta' => '{}', |
| 26 | ]); |
| 27 | |
| 28 | $product = new WC_Product_Simple(); |
| 29 | $product->set_name('DeleteTest Product ' . uniqid()); |
| 30 | $product->set_regular_price('10.00'); |
| 31 | $product->set_status('publish'); |
| 32 | $product->save(); |
| 33 | |
| 34 | update_post_meta($product->get_id(), 'saso_eventtickets_is_ticket', 'yes'); |
| 35 | update_post_meta($product->get_id(), 'saso_eventtickets_list', $listId); |
| 36 | |
| 37 | $order = wc_create_order(); |
| 38 | $order->add_product($product, 1); |
| 39 | $order->calculate_totals(); |
| 40 | $order->set_status('completed'); |
| 41 | $order->save(); |
| 42 | |
| 43 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 44 | |
| 45 | $items = $order->get_items(); |
| 46 | $item_id = 0; |
| 47 | foreach ($items as $id => $item) { |
| 48 | $item_id = $id; |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | return [ |
| 53 | 'order' => $order, |
| 54 | 'product' => $product, |
| 55 | 'list_id' => $listId, |
| 56 | 'item_id' => $item_id, |
| 57 | ]; |
| 58 | } |
| 59 | |
| 60 | // ── deleteCodesEntryOnOrderItem ────────────────────────────── |
| 61 | |
| 62 | public function test_deleteCodesEntryOnOrderItem_removes_ticket_meta(): void { |
| 63 | $data = $this->createTicketOrder(); |
| 64 | $om = $this->main->getWC()->getOrderManager(); |
| 65 | |
| 66 | // Verify meta exists before deletion |
| 67 | $isTicket = wc_get_order_item_meta($data['item_id'], '_saso_eventtickets_is_ticket', true); |
| 68 | $this->assertEquals(1, intval($isTicket)); |
| 69 | |
| 70 | // Delete codes entry |
| 71 | $om->deleteCodesEntryOnOrderItem($data['item_id']); |
| 72 | |
| 73 | // Verify meta is removed |
| 74 | $isTicketAfter = wc_get_order_item_meta($data['item_id'], '_saso_eventtickets_is_ticket', true); |
| 75 | $this->assertEmpty($isTicketAfter); |
| 76 | } |
| 77 | |
| 78 | public function test_deleteCodesEntryOnOrderItem_removes_codes_meta(): void { |
| 79 | $data = $this->createTicketOrder(); |
| 80 | $om = $this->main->getWC()->getOrderManager(); |
| 81 | |
| 82 | // Verify codes exist |
| 83 | $codes = wc_get_order_item_meta($data['item_id'], '_saso_eventtickets_product_code', true); |
| 84 | $this->assertNotEmpty($codes); |
| 85 | |
| 86 | // Delete |
| 87 | $om->deleteCodesEntryOnOrderItem($data['item_id']); |
| 88 | |
| 89 | // Verify removed |
| 90 | $codesAfter = wc_get_order_item_meta($data['item_id'], '_saso_eventtickets_product_code', true); |
| 91 | $this->assertEmpty($codesAfter); |
| 92 | } |
| 93 | |
| 94 | // ── deleteRestrictionEntryOnOrderItem ───────────────────────── |
| 95 | |
| 96 | public function test_deleteRestrictionEntryOnOrderItem_removes_restriction_meta(): void { |
| 97 | $data = $this->createTicketOrder(); |
| 98 | $om = $this->main->getWC()->getOrderManager(); |
| 99 | |
| 100 | // Add restriction meta first |
| 101 | wc_add_order_item_meta($data['item_id'], '_saso_eventticket_list_sale_restriction', 'TEST-CODE-123'); |
| 102 | |
| 103 | // Verify it exists |
| 104 | $restriction = wc_get_order_item_meta($data['item_id'], '_saso_eventticket_list_sale_restriction', true); |
| 105 | $this->assertEquals('TEST-CODE-123', $restriction); |
| 106 | |
| 107 | // Delete |
| 108 | $om->deleteRestrictionEntryOnOrderItem($data['item_id']); |
| 109 | |
| 110 | // Verify removed |
| 111 | $restrictionAfter = wc_get_order_item_meta($data['item_id'], '_saso_eventticket_list_sale_restriction', true); |
| 112 | $this->assertEmpty($restrictionAfter); |
| 113 | } |
| 114 | |
| 115 | // ── woocommerce_pre_delete_order_refund ─────────────────────── |
| 116 | |
| 117 | public function test_pre_delete_order_refund_captures_parent_id(): void { |
| 118 | $data = $this->createTicketOrder(); |
| 119 | $om = $this->main->getWC()->getOrderManager(); |
| 120 | |
| 121 | // Create a refund |
| 122 | $refund = wc_create_refund([ |
| 123 | 'order_id' => $data['order']->get_id(), |
| 124 | 'amount' => '10.00', |
| 125 | 'reason' => 'Test refund', |
| 126 | ]); |
| 127 | |
| 128 | // Call pre-delete hook |
| 129 | $result = $om->woocommerce_pre_delete_order_refund(true, $refund, true); |
| 130 | |
| 131 | // Should pass through the return value |
| 132 | $this->assertTrue($result); |
| 133 | |
| 134 | // Should have captured the parent ID (stored in refund_parent_id property) |
| 135 | $ref = new ReflectionProperty($om, 'refund_parent_id'); |
| 136 | $ref->setAccessible(true); |
| 137 | $this->assertEquals($data['order']->get_id(), $ref->getValue($om)); |
| 138 | } |
| 139 | |
| 140 | public function test_pre_delete_order_refund_null_refund(): void { |
| 141 | $om = $this->main->getWC()->getOrderManager(); |
| 142 | $result = $om->woocommerce_pre_delete_order_refund('passthrough', null, false); |
| 143 | $this->assertEquals('passthrough', $result); |
| 144 | } |
| 145 | } |
| 146 |