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
AdminOrderInfoTest.php
161 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for AdminSettings WC order info methods: getCompanyName, getCustomerName, |
| 4 | * removeWoocommerceRstrPurchaseInfoFromCode. |
| 5 | * And Core methods: getOrderTicketId, getOrderTicketIDCode. |
| 6 | */ |
| 7 | |
| 8 | class AdminOrderInfoTest 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 createOrder(): WC_Order { |
| 22 | $order = wc_create_order(); |
| 23 | $order->set_billing_first_name('Max'); |
| 24 | $order->set_billing_last_name('Mustermann'); |
| 25 | $order->set_billing_company('TestFirma GmbH'); |
| 26 | $order->calculate_totals(); |
| 27 | $order->save(); |
| 28 | return $order; |
| 29 | } |
| 30 | |
| 31 | private function createOrderWithTickets(): array { |
| 32 | $listId = $this->main->getDB()->insert('lists', [ |
| 33 | 'name' => 'OrderInfo Test ' . uniqid(), |
| 34 | 'aktiv' => 1, |
| 35 | 'meta' => '{}', |
| 36 | ]); |
| 37 | |
| 38 | $product = new WC_Product_Simple(); |
| 39 | $product->set_name('OrderInfo Product ' . uniqid()); |
| 40 | $product->set_regular_price('15.00'); |
| 41 | $product->set_status('publish'); |
| 42 | $product->save(); |
| 43 | |
| 44 | update_post_meta($product->get_id(), 'saso_eventtickets_is_ticket', 'yes'); |
| 45 | update_post_meta($product->get_id(), 'saso_eventtickets_list', $listId); |
| 46 | |
| 47 | $order = wc_create_order(); |
| 48 | $order->set_billing_first_name('Max'); |
| 49 | $order->set_billing_last_name('Mustermann'); |
| 50 | $order->set_billing_company('TestFirma GmbH'); |
| 51 | $order->add_product($product, 1); |
| 52 | $order->calculate_totals(); |
| 53 | $order->set_status('completed'); |
| 54 | $order->save(); |
| 55 | |
| 56 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 57 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 58 | |
| 59 | return [ |
| 60 | 'order' => $order, |
| 61 | 'order_id' => $order->get_id(), |
| 62 | 'codes' => $codes, |
| 63 | 'list_id' => $listId, |
| 64 | 'product_id' => $product->get_id(), |
| 65 | ]; |
| 66 | } |
| 67 | |
| 68 | // ── getCompanyName ─────────────────────────────────────────── |
| 69 | |
| 70 | public function test_getCompanyName_returns_company(): void { |
| 71 | $order = $this->createOrder(); |
| 72 | $result = $this->main->getAdmin()->getCompanyName($order->get_id()); |
| 73 | $this->assertEquals('TestFirma GmbH', $result); |
| 74 | } |
| 75 | |
| 76 | public function test_getCompanyName_empty_for_invalid_order(): void { |
| 77 | $result = $this->main->getAdmin()->getCompanyName(0); |
| 78 | $this->assertEquals('', $result); |
| 79 | } |
| 80 | |
| 81 | public function test_getCompanyName_empty_for_nonexistent_order(): void { |
| 82 | $result = $this->main->getAdmin()->getCompanyName(999999); |
| 83 | $this->assertIsString($result); |
| 84 | } |
| 85 | |
| 86 | // ── getCustomerName ────────────────────────────────────────── |
| 87 | |
| 88 | public function test_getCustomerName_returns_full_name(): void { |
| 89 | $order = $this->createOrder(); |
| 90 | $result = $this->main->getAdmin()->getCustomerName($order->get_id()); |
| 91 | $this->assertStringContainsString('Max', $result); |
| 92 | $this->assertStringContainsString('Mustermann', $result); |
| 93 | } |
| 94 | |
| 95 | public function test_getCustomerName_invalid_order_returns_string(): void { |
| 96 | $result = $this->main->getAdmin()->getCustomerName(999999); |
| 97 | $this->assertIsString($result); |
| 98 | } |
| 99 | |
| 100 | public function test_getCustomerName_zero_returns_string(): void { |
| 101 | $result = $this->main->getAdmin()->getCustomerName(0); |
| 102 | $this->assertIsString($result); |
| 103 | } |
| 104 | |
| 105 | // ── getOrderTicketIDCode ───────────────────────────────────── |
| 106 | |
| 107 | public function test_getOrderTicketIDCode_returns_string(): void { |
| 108 | $order = $this->createOrder(); |
| 109 | $idcode = $this->main->getCore()->getOrderTicketIDCode($order); |
| 110 | $this->assertIsString($idcode); |
| 111 | $this->assertNotEmpty($idcode); |
| 112 | } |
| 113 | |
| 114 | public function test_getOrderTicketIDCode_is_deterministic(): void { |
| 115 | $order = $this->createOrder(); |
| 116 | $idcode1 = $this->main->getCore()->getOrderTicketIDCode($order); |
| 117 | $idcode2 = $this->main->getCore()->getOrderTicketIDCode($order); |
| 118 | $this->assertEquals($idcode1, $idcode2, 'Same order should produce same idcode'); |
| 119 | } |
| 120 | |
| 121 | // ── getOrderTicketId ───────────────────────────────────────── |
| 122 | |
| 123 | public function test_getOrderTicketId_contains_order_prefix(): void { |
| 124 | $order = $this->createOrder(); |
| 125 | $ticketId = $this->main->getCore()->getOrderTicketId($order); |
| 126 | $this->assertStringStartsWith('order-', $ticketId); |
| 127 | } |
| 128 | |
| 129 | public function test_getOrderTicketId_contains_order_id(): void { |
| 130 | $order = $this->createOrder(); |
| 131 | $ticketId = $this->main->getCore()->getOrderTicketId($order); |
| 132 | $this->assertStringContainsString((string) $order->get_id(), $ticketId); |
| 133 | } |
| 134 | |
| 135 | public function test_getOrderTicketId_custom_prefix(): void { |
| 136 | $order = $this->createOrder(); |
| 137 | $ticketId = $this->main->getCore()->getOrderTicketId($order, 'custom-'); |
| 138 | $this->assertStringStartsWith('custom-', $ticketId); |
| 139 | } |
| 140 | |
| 141 | // ── removeWoocommerceRstrPurchaseInfoFromCode ───────────────── |
| 142 | |
| 143 | public function test_removeWoocommerceRstrPurchaseInfoFromCode_missing_code_throws(): void { |
| 144 | $this->expectException(Exception::class); |
| 145 | $this->main->getAdmin()->removeWoocommerceRstrPurchaseInfoFromCode([]); |
| 146 | } |
| 147 | |
| 148 | public function test_removeWoocommerceRstrPurchaseInfoFromCode_clears_rstr(): void { |
| 149 | $data = $this->createOrderWithTickets(); |
| 150 | $code = $data['codes'][0]['code']; |
| 151 | |
| 152 | $result = $this->main->getAdmin()->removeWoocommerceRstrPurchaseInfoFromCode(['code' => $code]); |
| 153 | $this->assertIsArray($result); |
| 154 | |
| 155 | // Verify the wc_rp section is reset |
| 156 | $fresh = $this->main->getCore()->retrieveCodeByCode($code); |
| 157 | $freshMeta = $this->main->getCore()->encodeMetaValuesAndFillObject($fresh['meta'], $fresh); |
| 158 | $this->assertEquals(0, intval($freshMeta['wc_rp']['order_id'])); |
| 159 | } |
| 160 | } |
| 161 |