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
TicketLabelsAndStaticsTest.php
216 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for Ticket label methods: get_expiration, getLabelNamePerTicket, |
| 4 | * getLabelValuePerTicket, getLabelDaychooserPerTicket, getRedeemAmountText. |
| 5 | * And static helpers: getMediaData, issetRPara. |
| 6 | */ |
| 7 | |
| 8 | class TicketLabelsAndStaticsTest 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 | |
| 17 | // ── get_expiration ─────────────────────────────────────────── |
| 18 | |
| 19 | public function test_get_expiration_returns_array(): void { |
| 20 | $result = $this->main->getTicketHandler()->get_expiration(); |
| 21 | $this->assertIsArray($result); |
| 22 | } |
| 23 | |
| 24 | public function test_get_expiration_has_expected_keys(): void { |
| 25 | $result = $this->main->getTicketHandler()->get_expiration(); |
| 26 | $this->assertArrayHasKey('subscription_type', $result); |
| 27 | $this->assertArrayHasKey('grace_period_days', $result); |
| 28 | $this->assertArrayHasKey('expiration_date', $result); |
| 29 | } |
| 30 | |
| 31 | public function test_get_expiration_default_subscription_type(): void { |
| 32 | $result = $this->main->getTicketHandler()->get_expiration(); |
| 33 | $this->assertEquals('abo', $result['subscription_type']); |
| 34 | } |
| 35 | |
| 36 | // ── getLabelNamePerTicket ───────────────────────────────────── |
| 37 | |
| 38 | public function test_getLabelNamePerTicket_returns_string(): void { |
| 39 | if (!class_exists('WC_Product_Simple')) { |
| 40 | $this->markTestSkipped('WooCommerce not available'); |
| 41 | } |
| 42 | |
| 43 | $product = new WC_Product_Simple(); |
| 44 | $product->set_name('Label Test'); |
| 45 | $product->set_regular_price('10.00'); |
| 46 | $product->set_status('publish'); |
| 47 | $product->save(); |
| 48 | |
| 49 | $label = $this->main->getTicketHandler()->getLabelNamePerTicket($product->get_id()); |
| 50 | $this->assertIsString($label); |
| 51 | $this->assertNotEmpty($label); |
| 52 | } |
| 53 | |
| 54 | public function test_getLabelNamePerTicket_custom_label(): void { |
| 55 | if (!class_exists('WC_Product_Simple')) { |
| 56 | $this->markTestSkipped('WooCommerce not available'); |
| 57 | } |
| 58 | |
| 59 | $product = new WC_Product_Simple(); |
| 60 | $product->set_name('Custom Label Test'); |
| 61 | $product->set_regular_price('10.00'); |
| 62 | $product->set_status('publish'); |
| 63 | $product->save(); |
| 64 | |
| 65 | update_post_meta($product->get_id(), 'saso_eventtickets_request_name_per_ticket_label', 'Custom Name:'); |
| 66 | $label = $this->main->getTicketHandler()->getLabelNamePerTicket($product->get_id()); |
| 67 | $this->assertEquals('Custom Name:', $label); |
| 68 | } |
| 69 | |
| 70 | // ── getLabelValuePerTicket ──────────────────────────────────── |
| 71 | |
| 72 | public function test_getLabelValuePerTicket_returns_string(): void { |
| 73 | if (!class_exists('WC_Product_Simple')) { |
| 74 | $this->markTestSkipped('WooCommerce not available'); |
| 75 | } |
| 76 | |
| 77 | $product = new WC_Product_Simple(); |
| 78 | $product->set_name('Value Label Test'); |
| 79 | $product->set_regular_price('10.00'); |
| 80 | $product->set_status('publish'); |
| 81 | $product->save(); |
| 82 | |
| 83 | $label = $this->main->getTicketHandler()->getLabelValuePerTicket($product->get_id()); |
| 84 | $this->assertIsString($label); |
| 85 | $this->assertNotEmpty($label); |
| 86 | } |
| 87 | |
| 88 | // ── getLabelDaychooserPerTicket ─────────────────────────────── |
| 89 | |
| 90 | public function test_getLabelDaychooserPerTicket_returns_string(): void { |
| 91 | if (!class_exists('WC_Product_Simple')) { |
| 92 | $this->markTestSkipped('WooCommerce not available'); |
| 93 | } |
| 94 | |
| 95 | $product = new WC_Product_Simple(); |
| 96 | $product->set_name('Day Label Test'); |
| 97 | $product->set_regular_price('10.00'); |
| 98 | $product->set_status('publish'); |
| 99 | $product->save(); |
| 100 | |
| 101 | $label = $this->main->getTicketHandler()->getLabelDaychooserPerTicket($product->get_id()); |
| 102 | $this->assertIsString($label); |
| 103 | $this->assertNotEmpty($label); |
| 104 | } |
| 105 | |
| 106 | // ── getRedeemAmountText ────────────────────────────────────── |
| 107 | |
| 108 | public function test_getRedeemAmountText_empty_for_single_redeem(): void { |
| 109 | if (!class_exists('WC_Product_Simple')) { |
| 110 | $this->markTestSkipped('WooCommerce not available'); |
| 111 | } |
| 112 | |
| 113 | $listId = $this->main->getDB()->insert('lists', [ |
| 114 | 'name' => 'Redeem Text Test ' . uniqid(), |
| 115 | 'aktiv' => 1, |
| 116 | 'meta' => '{}', |
| 117 | ]); |
| 118 | |
| 119 | $product = new WC_Product_Simple(); |
| 120 | $product->set_name('Redeem Text Product'); |
| 121 | $product->set_regular_price('10.00'); |
| 122 | $product->set_status('publish'); |
| 123 | $product->save(); |
| 124 | |
| 125 | update_post_meta($product->get_id(), 'saso_eventtickets_is_ticket', 'yes'); |
| 126 | update_post_meta($product->get_id(), 'saso_eventtickets_list', $listId); |
| 127 | // Default max redeem is 1 or unset |
| 128 | |
| 129 | $order = wc_create_order(); |
| 130 | $order->add_product($product, 1); |
| 131 | $order->calculate_totals(); |
| 132 | $order->set_status('completed'); |
| 133 | $order->save(); |
| 134 | |
| 135 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 136 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 137 | $codeObj = $this->main->getCore()->retrieveCodeByCode($codes[0]['code']); |
| 138 | $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 139 | |
| 140 | $text = $this->main->getTicketHandler()->getRedeemAmountText($codeObj, $metaObj); |
| 141 | // Max redeem = 1 (default) → empty string |
| 142 | $this->assertEquals('', $text); |
| 143 | } |
| 144 | |
| 145 | public function test_getRedeemAmountText_shows_text_for_multi_redeem(): void { |
| 146 | if (!class_exists('WC_Product_Simple')) { |
| 147 | $this->markTestSkipped('WooCommerce not available'); |
| 148 | } |
| 149 | |
| 150 | $listId = $this->main->getDB()->insert('lists', [ |
| 151 | 'name' => 'Multi Redeem Text ' . uniqid(), |
| 152 | 'aktiv' => 1, |
| 153 | 'meta' => '{}', |
| 154 | ]); |
| 155 | |
| 156 | $product = new WC_Product_Simple(); |
| 157 | $product->set_name('Multi Redeem Product'); |
| 158 | $product->set_regular_price('10.00'); |
| 159 | $product->set_status('publish'); |
| 160 | $product->save(); |
| 161 | |
| 162 | update_post_meta($product->get_id(), 'saso_eventtickets_is_ticket', 'yes'); |
| 163 | update_post_meta($product->get_id(), 'saso_eventtickets_list', $listId); |
| 164 | update_post_meta($product->get_id(), 'saso_eventtickets_ticket_max_redeem_amount', 5); |
| 165 | |
| 166 | $order = wc_create_order(); |
| 167 | $order->add_product($product, 1); |
| 168 | $order->calculate_totals(); |
| 169 | $order->set_status('completed'); |
| 170 | $order->save(); |
| 171 | |
| 172 | $this->main->getWC()->getOrderManager()->add_serialcode_to_order($order->get_id()); |
| 173 | $codes = $this->main->getCore()->getCodesByOrderId($order->get_id()); |
| 174 | $codeObj = $this->main->getCore()->retrieveCodeByCode($codes[0]['code']); |
| 175 | $metaObj = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 176 | |
| 177 | $text = $this->main->getTicketHandler()->getRedeemAmountText($codeObj, $metaObj); |
| 178 | $this->assertIsString($text); |
| 179 | // Max redeem = 5, so text should include "5" |
| 180 | $this->assertStringContainsString('5', $text); |
| 181 | } |
| 182 | |
| 183 | // ── getMediaData ───────────────────────────────────────────── |
| 184 | |
| 185 | public function test_getMediaData_returns_array(): void { |
| 186 | $result = SASO_EVENTTICKETS::getMediaData(0); |
| 187 | $this->assertIsArray($result); |
| 188 | $this->assertArrayHasKey('title', $result); |
| 189 | $this->assertArrayHasKey('url', $result); |
| 190 | $this->assertArrayHasKey('suffix', $result); |
| 191 | } |
| 192 | |
| 193 | public function test_getMediaData_nonexistent_returns_empty_values(): void { |
| 194 | $result = SASO_EVENTTICKETS::getMediaData(999999); |
| 195 | $this->assertIsArray($result); |
| 196 | $this->assertEmpty($result['title']); |
| 197 | } |
| 198 | |
| 199 | // ── issetRPara ─────────────────────────────────────────────── |
| 200 | |
| 201 | public function test_issetRPara_returns_false_for_nonexistent(): void { |
| 202 | $result = SASO_EVENTTICKETS::issetRPara('nonexistent_param_' . uniqid()); |
| 203 | $this->assertFalse($result); |
| 204 | } |
| 205 | |
| 206 | public function test_issetRPara_returns_true_for_get_param(): void { |
| 207 | $_GET['test_isset_param'] = 'value'; |
| 208 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
| 209 | |
| 210 | $result = SASO_EVENTTICKETS::issetRPara('test_isset_param'); |
| 211 | $this->assertTrue($result); |
| 212 | |
| 213 | unset($_GET['test_isset_param']); |
| 214 | } |
| 215 | } |
| 216 |