bin
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
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
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
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
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
ShortcodeAndCartCheckTest.php
186 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for shortcode rendering and cart validation gate: |
| 4 | * - renderTicketDetailForShortcode: shortcode HTML output |
| 5 | * - woocommerce_check_cart_items: conditional validation skip |
| 6 | * - containsProductsWithRestrictions: cart restriction check |
| 7 | */ |
| 8 | |
| 9 | class ShortcodeAndCartCheckTest 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 | |
| 18 | public function tear_down(): void { |
| 19 | // Reset containsProductsWithRestrictions cache to avoid leaking to other test classes |
| 20 | if (class_exists('WC_Product_Simple')) { |
| 21 | $ref = new ReflectionProperty($this->main->getWC()->getFrontendManager(), '_containsProductsWithRestrictions'); |
| 22 | $ref->setAccessible(true); |
| 23 | $ref->setValue($this->main->getWC()->getFrontendManager(), null); |
| 24 | |
| 25 | WC()->cart->empty_cart(); |
| 26 | wc_clear_notices(); |
| 27 | } |
| 28 | parent::tear_down(); |
| 29 | } |
| 30 | |
| 31 | // ── renderTicketDetailForShortcode ──────────────────────────── |
| 32 | |
| 33 | public function test_renderTicketDetailForShortcode_returns_html_string(): void { |
| 34 | $html = $this->main->getTicketHandler()->renderTicketDetailForShortcode(); |
| 35 | $this->assertIsString($html); |
| 36 | $this->assertStringContainsString('ticket_content', $html); |
| 37 | } |
| 38 | |
| 39 | public function test_renderTicketDetailForShortcode_contains_error_on_invalid_request(): void { |
| 40 | // Without a valid ticket URI set, should show error |
| 41 | $html = $this->main->getTicketHandler()->renderTicketDetailForShortcode(); |
| 42 | $this->assertStringContainsString('ticket_content', $html); |
| 43 | // Should contain the closing div at minimum |
| 44 | $this->assertStringContainsString('</div>', $html); |
| 45 | } |
| 46 | |
| 47 | public function test_renderTicketDetailForShortcode_catches_exceptions(): void { |
| 48 | // Set an invalid request URI that will trigger an exception |
| 49 | $ticket = $this->main->getTicketHandler(); |
| 50 | |
| 51 | $ref = new ReflectionProperty($ticket, 'request_uri'); |
| 52 | $ref->setAccessible(true); |
| 53 | $oldUri = $ref->getValue($ticket); |
| 54 | |
| 55 | // Set a URI that looks like a ticket path but has no valid code |
| 56 | $ref->setValue($ticket, '/ticket/invalid-nonexistent-id'); |
| 57 | |
| 58 | $html = $ticket->renderTicketDetailForShortcode(); |
| 59 | |
| 60 | // Should contain error message (caught exception) or the content div |
| 61 | $this->assertStringContainsString('ticket_content', $html); |
| 62 | |
| 63 | // Restore |
| 64 | $ref->setValue($ticket, $oldUri); |
| 65 | } |
| 66 | |
| 67 | // ── containsProductsWithRestrictions ────────────────────────── |
| 68 | |
| 69 | public function test_containsProductsWithRestrictions_false_for_empty_cart(): void { |
| 70 | if (!class_exists('WC_Product_Simple')) { |
| 71 | $this->markTestSkipped('WooCommerce not available'); |
| 72 | } |
| 73 | |
| 74 | WC()->cart->empty_cart(); |
| 75 | |
| 76 | // Reset cached value |
| 77 | $ref = new ReflectionProperty($this->main->getWC()->getFrontendManager(), '_containsProductsWithRestrictions'); |
| 78 | $ref->setAccessible(true); |
| 79 | $ref->setValue($this->main->getWC()->getFrontendManager(), null); |
| 80 | |
| 81 | $result = $this->main->getWC()->getFrontendManager()->containsProductsWithRestrictions(); |
| 82 | $this->assertFalse($result); |
| 83 | |
| 84 | WC()->cart->empty_cart(); |
| 85 | } |
| 86 | |
| 87 | public function test_containsProductsWithRestrictions_false_for_regular_product(): void { |
| 88 | if (!class_exists('WC_Product_Simple')) { |
| 89 | $this->markTestSkipped('WooCommerce not available'); |
| 90 | } |
| 91 | |
| 92 | $product = new WC_Product_Simple(); |
| 93 | $product->set_name('NoRestriction ' . uniqid()); |
| 94 | $product->set_regular_price('5.00'); |
| 95 | $product->set_status('publish'); |
| 96 | $product->save(); |
| 97 | |
| 98 | WC()->cart->empty_cart(); |
| 99 | WC()->cart->add_to_cart($product->get_id()); |
| 100 | |
| 101 | $ref = new ReflectionProperty($this->main->getWC()->getFrontendManager(), '_containsProductsWithRestrictions'); |
| 102 | $ref->setAccessible(true); |
| 103 | $ref->setValue($this->main->getWC()->getFrontendManager(), null); |
| 104 | |
| 105 | $result = $this->main->getWC()->getFrontendManager()->containsProductsWithRestrictions(); |
| 106 | $this->assertFalse($result); |
| 107 | |
| 108 | WC()->cart->empty_cart(); |
| 109 | } |
| 110 | |
| 111 | public function test_containsProductsWithRestrictions_true_for_restricted_product(): void { |
| 112 | if (!class_exists('WC_Product_Simple')) { |
| 113 | $this->markTestSkipped('WooCommerce not available'); |
| 114 | } |
| 115 | |
| 116 | // Create a restriction list |
| 117 | $restrictListId = $this->main->getDB()->insert('lists', [ |
| 118 | 'name' => 'Restriction List ' . uniqid(), |
| 119 | 'aktiv' => 1, |
| 120 | 'meta' => '{}', |
| 121 | ]); |
| 122 | |
| 123 | $product = new WC_Product_Simple(); |
| 124 | $product->set_name('Restricted ' . uniqid()); |
| 125 | $product->set_regular_price('10.00'); |
| 126 | $product->set_status('publish'); |
| 127 | $product->save(); |
| 128 | |
| 129 | // Set restriction meta (must match META_KEY_CODELIST_RESTRICTION constant) |
| 130 | update_post_meta($product->get_id(), 'saso_eventtickets_list_sale_restriction', $restrictListId); |
| 131 | |
| 132 | WC()->cart->empty_cart(); |
| 133 | WC()->cart->add_to_cart($product->get_id()); |
| 134 | |
| 135 | $ref = new ReflectionProperty($this->main->getWC()->getFrontendManager(), '_containsProductsWithRestrictions'); |
| 136 | $ref->setAccessible(true); |
| 137 | $ref->setValue($this->main->getWC()->getFrontendManager(), null); |
| 138 | |
| 139 | $result = $this->main->getWC()->getFrontendManager()->containsProductsWithRestrictions(); |
| 140 | $this->assertTrue($result); |
| 141 | |
| 142 | WC()->cart->empty_cart(); |
| 143 | } |
| 144 | |
| 145 | // ── woocommerce_check_cart_items ───────────────────────────── |
| 146 | |
| 147 | public function test_check_cart_items_runs_warnings_when_option_disabled(): void { |
| 148 | if (!class_exists('WC_Product_Simple')) { |
| 149 | $this->markTestSkipped('WooCommerce not available'); |
| 150 | } |
| 151 | |
| 152 | // Ensure the "show on checkout only" option is disabled |
| 153 | update_option('sasoEventticketswcTicketShowInputFieldsOnCheckoutPage', '0'); |
| 154 | $this->main->getOptions()->initOptions(); |
| 155 | |
| 156 | WC()->cart->empty_cart(); |
| 157 | |
| 158 | // Should run without error (no items = no warnings) |
| 159 | $this->main->getWC()->getFrontendManager()->woocommerce_check_cart_items(); |
| 160 | $this->assertTrue(true); // No exception = pass |
| 161 | |
| 162 | WC()->cart->empty_cart(); |
| 163 | } |
| 164 | |
| 165 | public function test_check_cart_items_skips_warnings_when_checkout_option_active(): void { |
| 166 | if (!class_exists('WC_Product_Simple')) { |
| 167 | $this->markTestSkipped('WooCommerce not available'); |
| 168 | } |
| 169 | |
| 170 | // Enable the "show input fields on checkout page" option |
| 171 | update_option('sasoEventticketswcTicketShowInputFieldsOnCheckoutPage', '1'); |
| 172 | $this->main->getOptions()->initOptions(); |
| 173 | |
| 174 | WC()->cart->empty_cart(); |
| 175 | |
| 176 | // Should return early (skip check_cart_item_and_add_warnings) |
| 177 | $this->main->getWC()->getFrontendManager()->woocommerce_check_cart_items(); |
| 178 | $this->assertTrue(true); // No exception = pass |
| 179 | |
| 180 | // Reset |
| 181 | update_option('sasoEventticketswcTicketShowInputFieldsOnCheckoutPage', '0'); |
| 182 | $this->main->getOptions()->initOptions(); |
| 183 | WC()->cart->empty_cart(); |
| 184 | } |
| 185 | } |
| 186 |