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
FullTicketFlowTest.php
266 lines
| 1 | <?php |
| 2 | /** |
| 3 | * End-to-end tests for the complete ticket lifecycle: |
| 4 | * Product → Order → Code generation → Query → Redeem → Verify |
| 5 | */ |
| 6 | |
| 7 | class FullTicketFlowTest extends WP_UnitTestCase { |
| 8 | |
| 9 | private $main; |
| 10 | |
| 11 | public function set_up(): void { |
| 12 | parent::set_up(); |
| 13 | $this->main = sasoEventtickets::Instance(); |
| 14 | |
| 15 | if (!class_exists('WC_Product_Simple')) { |
| 16 | $this->markTestSkipped('WooCommerce not available'); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Helper: create a ticket product. |
| 22 | */ |
| 23 | private function createTicketProduct(array $extraMeta = []): array { |
| 24 | $listId = $this->main->getDB()->insert('lists', [ |
| 25 | 'name' => 'Flow List ' . uniqid(), |
| 26 | 'aktiv' => 1, |
| 27 | 'meta' => '{}', |
| 28 | ]); |
| 29 | |
| 30 | $product = new WC_Product_Simple(); |
| 31 | $product->set_name('Flow Ticket ' . uniqid()); |
| 32 | $product->set_regular_price('25.00'); |
| 33 | $product->set_status('publish'); |
| 34 | $product->save(); |
| 35 | $pid = $product->get_id(); |
| 36 | |
| 37 | update_post_meta($pid, 'saso_eventtickets_is_ticket', 'yes'); |
| 38 | update_post_meta($pid, 'saso_eventtickets_list', $listId); |
| 39 | |
| 40 | foreach ($extraMeta as $key => $value) { |
| 41 | update_post_meta($pid, $key, $value); |
| 42 | } |
| 43 | |
| 44 | return ['product' => $product, 'product_id' => $pid, 'list_id' => $listId]; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Helper: create an order and generate codes. |
| 49 | */ |
| 50 | private function createOrderWithCodes(WC_Product $product, int $quantity = 1): WC_Order { |
| 51 | $order = wc_create_order(); |
| 52 | $order->add_product($product, $quantity); |
| 53 | $order->set_billing_first_name('Test'); |
| 54 | $order->set_billing_last_name('Customer'); |
| 55 | $order->set_billing_email('test@example.com'); |
| 56 | $order->calculate_totals(); |
| 57 | $order->set_status('completed'); |
| 58 | $order->save(); |
| 59 | |
| 60 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 61 | |
| 62 | return wc_get_order($order->get_id()); |
| 63 | } |
| 64 | |
| 65 | // ── Full lifecycle: create → generate → query → validate ───── |
| 66 | |
| 67 | public function test_full_lifecycle_single_ticket(): void { |
| 68 | $tp = $this->createTicketProduct([ |
| 69 | 'saso_eventtickets_ticket_start_date' => '2026-07-01', |
| 70 | 'saso_eventtickets_ticket_end_date' => '2026-12-31', |
| 71 | ]); |
| 72 | $order = $this->createOrderWithCodes($tp['product']); |
| 73 | |
| 74 | // 1. Verify codes were generated |
| 75 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 76 | $this->assertCount(1, $codes); |
| 77 | |
| 78 | // 2. Verify code is valid via frontend checkCode |
| 79 | $code = $codes[0]['code']; |
| 80 | $result = $this->main->getFrontend()->checkCode(['code' => $code]); |
| 81 | $this->assertEquals(1, $result['valid']); |
| 82 | |
| 83 | // 3. Verify code metadata has WooCommerce info |
| 84 | $codeObj = $this->main->getCore()->retrieveCodeByCode($code); |
| 85 | $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 86 | $this->assertEquals($order->get_id(), intval($metaObj['woocommerce']['order_id'])); |
| 87 | $this->assertEquals($tp['product_id'], intval($metaObj['woocommerce']['product_id'])); |
| 88 | $this->assertEquals(1, intval($metaObj['wc_ticket']['is_ticket'])); |
| 89 | |
| 90 | // 4. Verify order has tickets |
| 91 | $this->assertTrue($this->main->getWC()->getOrderManager()->hasTicketsInOrder($order)); |
| 92 | $this->assertTrue($this->main->getWC()->getOrderManager()->hasTicketsInOrderWithTicketnumber($order)); |
| 93 | |
| 94 | // 5. Verify getTicketsFromOrder returns correct data |
| 95 | $tickets = $this->main->getWC()->getOrderManager()->getTicketsFromOrder($order); |
| 96 | $this->assertCount(1, $tickets); |
| 97 | $ticket = reset($tickets); |
| 98 | $this->assertEquals(1, $ticket['quantity']); |
| 99 | $this->assertNotEmpty($ticket['codes']); |
| 100 | |
| 101 | // 6. Verify getCodesByProductId |
| 102 | $productCodes = $this->main->getAdmin()->getCodesByProductId($tp['product_id']); |
| 103 | $this->assertCount(1, $productCodes); |
| 104 | |
| 105 | // 7. Code is not used yet |
| 106 | $this->assertFalse($this->main->getFrontend()->isUsed($codeObj)); |
| 107 | |
| 108 | // 8. Verify QR code content |
| 109 | $qr = $this->main->getCore()->getQRCodeContent($codeObj); |
| 110 | $this->assertNotEmpty($qr); |
| 111 | } |
| 112 | |
| 113 | public function test_full_lifecycle_multiple_tickets(): void { |
| 114 | $tp = $this->createTicketProduct(); |
| 115 | $order = $this->createOrderWithCodes($tp['product'], 3); |
| 116 | |
| 117 | // 3 codes should be generated |
| 118 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 119 | $this->assertCount(3, $codes); |
| 120 | |
| 121 | // All codes should be unique |
| 122 | $codeStrings = array_column($codes, 'code'); |
| 123 | $this->assertCount(3, array_unique($codeStrings)); |
| 124 | |
| 125 | // All codes should be valid |
| 126 | foreach ($codeStrings as $codeStr) { |
| 127 | $result = $this->main->getFrontend()->checkCode(['code' => $codeStr]); |
| 128 | $this->assertEquals(1, $result['valid'], "Code $codeStr should be valid"); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | public function test_full_lifecycle_with_amount_per_item(): void { |
| 133 | $tp = $this->createTicketProduct([ |
| 134 | 'saso_eventtickets_ticket_amount_per_item' => 3, |
| 135 | ]); |
| 136 | $order = $this->createOrderWithCodes($tp['product'], 2); |
| 137 | |
| 138 | // 2 items × 3 tickets/item = 6 codes |
| 139 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 140 | $this->assertCount(6, $codes); |
| 141 | } |
| 142 | |
| 143 | // ── Order with mixed products ──────────────────────────────── |
| 144 | |
| 145 | public function test_order_with_mixed_ticket_and_non_ticket(): void { |
| 146 | $tp = $this->createTicketProduct(); |
| 147 | |
| 148 | $nonTicket = new WC_Product_Simple(); |
| 149 | $nonTicket->set_name('Regular Product'); |
| 150 | $nonTicket->set_regular_price('5.00'); |
| 151 | $nonTicket->set_status('publish'); |
| 152 | $nonTicket->save(); |
| 153 | |
| 154 | $order = wc_create_order(); |
| 155 | $order->add_product($nonTicket, 1); |
| 156 | $order->add_product($tp['product'], 2); |
| 157 | $order->calculate_totals(); |
| 158 | $order->set_status('completed'); |
| 159 | $order->save(); |
| 160 | |
| 161 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 162 | |
| 163 | $order = wc_get_order($order->get_id()); |
| 164 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 165 | $this->assertCount(2, $codes, 'Only ticket products should generate codes'); |
| 166 | |
| 167 | // getTicketsFromOrder should only include the ticket product |
| 168 | $tickets = $this->main->getWC()->getOrderManager()->getTicketsFromOrder($order); |
| 169 | $this->assertCount(1, $tickets); |
| 170 | } |
| 171 | |
| 172 | // ── addCodeFromListForOrder ─────────────────────────────────── |
| 173 | |
| 174 | public function test_addCodeFromListForOrder_generates_unique_code(): void { |
| 175 | $listId = $this->main->getDB()->insert('lists', [ |
| 176 | 'name' => 'AutoGen ' . uniqid(), |
| 177 | 'aktiv' => 1, |
| 178 | 'meta' => '{}', |
| 179 | ]); |
| 180 | |
| 181 | $order = wc_create_order(); |
| 182 | $order->save(); |
| 183 | |
| 184 | $code1 = $this->main->getAdmin()->addCodeFromListForOrder($listId, $order->get_id()); |
| 185 | $code2 = $this->main->getAdmin()->addCodeFromListForOrder($listId, $order->get_id()); |
| 186 | |
| 187 | $this->assertNotEmpty($code1); |
| 188 | $this->assertNotEmpty($code2); |
| 189 | $this->assertNotEquals($code1, $code2); |
| 190 | } |
| 191 | |
| 192 | public function test_addCodeFromListForOrder_invalid_list_throws(): void { |
| 193 | $this->expectException(Exception::class); |
| 194 | $this->main->getAdmin()->addCodeFromListForOrder(0, 1); |
| 195 | } |
| 196 | |
| 197 | // ── Customer name in order context ──────────────────────────── |
| 198 | |
| 199 | public function test_customer_name_available_after_code_generation(): void { |
| 200 | $tp = $this->createTicketProduct(); |
| 201 | $order = $this->createOrderWithCodes($tp['product']); |
| 202 | |
| 203 | $customerName = $this->main->getAdmin()->getCustomerName($order->get_id()); |
| 204 | $this->assertStringContainsString('Test', $customerName); |
| 205 | $this->assertStringContainsString('Customer', $customerName); |
| 206 | } |
| 207 | |
| 208 | // ── Frontend getOptions ─────────────────────────────────────── |
| 209 | |
| 210 | public function test_frontend_getOptions_returns_array(): void { |
| 211 | $options = $this->main->getFrontend()->getOptions(); |
| 212 | $this->assertIsArray($options); |
| 213 | } |
| 214 | |
| 215 | // ── Ticket date display in full flow ────────────────────────── |
| 216 | |
| 217 | public function test_ticket_date_displayed_correctly_for_generated_code(): void { |
| 218 | $tp = $this->createTicketProduct([ |
| 219 | 'saso_eventtickets_ticket_start_date' => '2026-08-15', |
| 220 | 'saso_eventtickets_ticket_start_time' => '19:00:00', |
| 221 | 'saso_eventtickets_ticket_end_date' => '2026-08-15', |
| 222 | 'saso_eventtickets_ticket_end_time' => '23:00:00', |
| 223 | ]); |
| 224 | $order = $this->createOrderWithCodes($tp['product']); |
| 225 | |
| 226 | $dateStr = $this->main->getTicketHandler()->displayTicketDateAsString($tp['product_id']); |
| 227 | $this->assertStringContainsString('2026', $dateStr); |
| 228 | $this->assertStringContainsString('19:00', $dateStr); |
| 229 | } |
| 230 | |
| 231 | // ── ICS generation for product with order ───────────────────── |
| 232 | |
| 233 | public function test_ics_generation_for_ticket_product(): void { |
| 234 | $tp = $this->createTicketProduct([ |
| 235 | 'saso_eventtickets_ticket_start_date' => '2026-09-01', |
| 236 | 'saso_eventtickets_ticket_start_time' => '10:00:00', |
| 237 | 'saso_eventtickets_ticket_end_date' => '2026-09-01', |
| 238 | 'saso_eventtickets_ticket_end_time' => '18:00:00', |
| 239 | ]); |
| 240 | |
| 241 | $ics = $this->main->getTicketHandler()->generateICSFile($tp['product']); |
| 242 | $this->assertStringContainsString('BEGIN:VCALENDAR', $ics); |
| 243 | $this->assertStringContainsString('DTSTART:', $ics); |
| 244 | $this->assertStringContainsString('SUMMARY:', $ics); |
| 245 | } |
| 246 | |
| 247 | // ── Remove all tickets from order ───────────────────────────── |
| 248 | |
| 249 | public function test_remove_all_tickets_clears_order_ticket_data(): void { |
| 250 | $tp = $this->createTicketProduct(); |
| 251 | $order = $this->createOrderWithCodes($tp['product'], 2); |
| 252 | |
| 253 | // Verify tickets exist |
| 254 | $this->assertTrue($this->main->getWC()->getOrderManager()->hasTicketsInOrderWithTicketnumber($order)); |
| 255 | |
| 256 | // Remove all tickets |
| 257 | $this->main->getWC()->getOrderManager()->removeAllTicketsFromOrder([ |
| 258 | 'order_id' => $order->get_id(), |
| 259 | ]); |
| 260 | |
| 261 | // Verify ticket numbers are cleared |
| 262 | $order = wc_get_order($order->get_id()); |
| 263 | $this->assertFalse($this->main->getWC()->getOrderManager()->hasTicketsInOrderWithTicketnumber($order)); |
| 264 | } |
| 265 | } |
| 266 |