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
CoreMethodsTest.php
279 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for sasoEventtickets_Core pure/near-pure methods. |
| 4 | */ |
| 5 | |
| 6 | class CoreMethodsTest extends WP_UnitTestCase { |
| 7 | |
| 8 | private sasoEventtickets_Core $core; |
| 9 | |
| 10 | public function set_up(): void { |
| 11 | parent::set_up(); |
| 12 | $this->core = sasoEventtickets::Instance()->getCore(); |
| 13 | } |
| 14 | |
| 15 | // ── clearCode ────────────────────────────────────────────── |
| 16 | |
| 17 | public function test_clearCode_removes_spaces(): void { |
| 18 | $this->assertSame('ABC123', $this->core->clearCode('ABC 123')); |
| 19 | } |
| 20 | |
| 21 | public function test_clearCode_removes_colons(): void { |
| 22 | $this->assertSame('ABC123', $this->core->clearCode('ABC:123')); |
| 23 | } |
| 24 | |
| 25 | public function test_clearCode_removes_dashes(): void { |
| 26 | $this->assertSame('ABC123', $this->core->clearCode('ABC-123')); |
| 27 | } |
| 28 | |
| 29 | public function test_clearCode_strips_html_tags(): void { |
| 30 | $this->assertSame('ABC123', $this->core->clearCode('<b>ABC123</b>')); |
| 31 | } |
| 32 | |
| 33 | public function test_clearCode_trims_whitespace(): void { |
| 34 | $this->assertSame('ABC123', $this->core->clearCode(' ABC123 ')); |
| 35 | } |
| 36 | |
| 37 | public function test_clearCode_url_decodes(): void { |
| 38 | // urldecode runs AFTER str_replace, so %20 becomes space in output |
| 39 | $this->assertSame('ABC 123', $this->core->clearCode('ABC%20123')); |
| 40 | } |
| 41 | |
| 42 | public function test_clearCode_combined_sanitization(): void { |
| 43 | // Order: replace(- : space) → strip_tags → urldecode → trim |
| 44 | // ' <i>AB-C:D E%20F</i> ' → 'ABCDE%20F' (tags+dash+colon+space removed) |
| 45 | // → urldecode → 'ABCDE F' → trim → 'ABCDE F' |
| 46 | $this->assertSame('ABCDE F', $this->core->clearCode(' <i>AB-C:D E%20F</i> ')); |
| 47 | } |
| 48 | |
| 49 | public function test_clearCode_empty_string(): void { |
| 50 | $this->assertSame('', $this->core->clearCode('')); |
| 51 | } |
| 52 | |
| 53 | // ── decodeAndMergeMeta ───────────────────────────────────── |
| 54 | |
| 55 | public function test_decodeAndMergeMeta_null_returns_defaults(): void { |
| 56 | $defaults = ['a' => 1, 'b' => ['c' => 2]]; |
| 57 | $result = $this->core->decodeAndMergeMeta(null, $defaults); |
| 58 | $this->assertSame($defaults, $result); |
| 59 | } |
| 60 | |
| 61 | public function test_decodeAndMergeMeta_empty_string_returns_defaults(): void { |
| 62 | $defaults = ['a' => 1]; |
| 63 | $result = $this->core->decodeAndMergeMeta('', $defaults); |
| 64 | $this->assertSame($defaults, $result); |
| 65 | } |
| 66 | |
| 67 | public function test_decodeAndMergeMeta_invalid_json_returns_defaults(): void { |
| 68 | $defaults = ['a' => 1]; |
| 69 | $result = $this->core->decodeAndMergeMeta('{broken', $defaults); |
| 70 | $this->assertSame($defaults, $result); |
| 71 | } |
| 72 | |
| 73 | public function test_decodeAndMergeMeta_merges_values(): void { |
| 74 | $defaults = ['a' => 1, 'b' => 2, 'c' => 3]; |
| 75 | $json = '{"b": 99}'; |
| 76 | $result = $this->core->decodeAndMergeMeta($json, $defaults); |
| 77 | $this->assertSame(1, $result['a']); |
| 78 | $this->assertSame(99, $result['b']); |
| 79 | $this->assertSame(3, $result['c']); |
| 80 | } |
| 81 | |
| 82 | public function test_decodeAndMergeMeta_deep_merge(): void { |
| 83 | $defaults = ['outer' => ['inner1' => 'a', 'inner2' => 'b']]; |
| 84 | $json = '{"outer": {"inner1": "X"}}'; |
| 85 | $result = $this->core->decodeAndMergeMeta($json, $defaults); |
| 86 | $this->assertSame('X', $result['outer']['inner1']); |
| 87 | $this->assertSame('b', $result['outer']['inner2']); |
| 88 | } |
| 89 | |
| 90 | // ── getMetaObject ────────────────────────────────────────── |
| 91 | |
| 92 | public function test_getMetaObject_returns_array(): void { |
| 93 | $meta = $this->core->getMetaObject(); |
| 94 | $this->assertIsArray($meta); |
| 95 | } |
| 96 | |
| 97 | public function test_getMetaObject_has_required_keys(): void { |
| 98 | $meta = $this->core->getMetaObject(); |
| 99 | $requiredKeys = ['validation', 'user', 'used', 'confirmedCount', 'woocommerce', 'wc_rp', 'wc_ticket']; |
| 100 | foreach ($requiredKeys as $key) { |
| 101 | $this->assertArrayHasKey($key, $meta, "Missing key: $key"); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | public function test_getMetaObject_wc_ticket_has_stats_redeemed(): void { |
| 106 | $meta = $this->core->getMetaObject(); |
| 107 | $this->assertArrayHasKey('stats_redeemed', $meta['wc_ticket']); |
| 108 | $this->assertSame([], $meta['wc_ticket']['stats_redeemed']); |
| 109 | } |
| 110 | |
| 111 | public function test_getMetaObject_wc_ticket_has_required_fields(): void { |
| 112 | $meta = $this->core->getMetaObject(); |
| 113 | $fields = ['is_ticket', 'redeemed_date', 'idcode', 'name_per_ticket', 'value_per_ticket', 'day_per_ticket']; |
| 114 | foreach ($fields as $field) { |
| 115 | $this->assertArrayHasKey($field, $meta['wc_ticket'], "wc_ticket missing: $field"); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | public function test_getMetaObject_validation_has_required_fields(): void { |
| 120 | $meta = $this->core->getMetaObject(); |
| 121 | $fields = ['first_success', 'first_ip', 'last_success', 'last_ip']; |
| 122 | foreach ($fields as $field) { |
| 123 | $this->assertArrayHasKey($field, $meta['validation'], "validation missing: $field"); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | public function test_getMetaObject_woocommerce_has_order_and_product_id(): void { |
| 128 | $meta = $this->core->getMetaObject(); |
| 129 | $this->assertArrayHasKey('order_id', $meta['woocommerce']); |
| 130 | $this->assertArrayHasKey('product_id', $meta['woocommerce']); |
| 131 | $this->assertSame(0, $meta['woocommerce']['order_id']); |
| 132 | $this->assertSame(0, $meta['woocommerce']['product_id']); |
| 133 | } |
| 134 | |
| 135 | // ── getMetaObjectKeyList ─────────────────────────────────── |
| 136 | |
| 137 | public function test_getMetaObjectKeyList_flat_array(): void { |
| 138 | $meta = ['name' => 'test', 'value' => 42]; |
| 139 | $keys = $this->core->getMetaObjectKeyList($meta); |
| 140 | $this->assertSame(['META_NAME', 'META_VALUE'], $keys); |
| 141 | } |
| 142 | |
| 143 | public function test_getMetaObjectKeyList_nested_array(): void { |
| 144 | $meta = ['outer' => ['inner' => 'val']]; |
| 145 | $keys = $this->core->getMetaObjectKeyList($meta); |
| 146 | $this->assertSame(['META_OUTER_INNER'], $keys); |
| 147 | } |
| 148 | |
| 149 | public function test_getMetaObjectKeyList_custom_prefix(): void { |
| 150 | $meta = ['foo' => 'bar']; |
| 151 | $keys = $this->core->getMetaObjectKeyList($meta, 'TAG_'); |
| 152 | $this->assertSame(['TAG_FOO'], $keys); |
| 153 | } |
| 154 | |
| 155 | public function test_getMetaObjectKeyList_real_meta_contains_expected_keys(): void { |
| 156 | $meta = $this->core->getMetaObject(); |
| 157 | $keys = $this->core->getMetaObjectKeyList($meta); |
| 158 | $this->assertContains('META_VALIDATION_FIRST_SUCCESS', $keys); |
| 159 | $this->assertContains('META_WOOCOMMERCE_ORDER_ID', $keys); |
| 160 | $this->assertContains('META_WC_TICKET_REDEEMED_DATE', $keys); |
| 161 | $this->assertContains('META_WC_TICKET_IDCODE', $keys); |
| 162 | $this->assertContains('META_USER_REG_USERID', $keys); |
| 163 | } |
| 164 | |
| 165 | // ── getTicketId ──────────────────────────────────────────── |
| 166 | |
| 167 | public function test_getTicketId_correct_format(): void { |
| 168 | $codeObj = ['code' => 'abc123', 'order_id' => 42]; |
| 169 | $metaObj = ['wc_ticket' => ['idcode' => 'XYZ']]; |
| 170 | $result = $this->core->getTicketId($codeObj, $metaObj); |
| 171 | $this->assertSame('XYZ-42-abc123', $result); |
| 172 | } |
| 173 | |
| 174 | public function test_getTicketId_missing_code_returns_empty(): void { |
| 175 | $codeObj = ['order_id' => 42]; |
| 176 | $metaObj = ['wc_ticket' => ['idcode' => 'XYZ']]; |
| 177 | $result = $this->core->getTicketId($codeObj, $metaObj); |
| 178 | $this->assertSame('', $result); |
| 179 | } |
| 180 | |
| 181 | public function test_getTicketId_missing_idcode_returns_empty(): void { |
| 182 | $codeObj = ['code' => 'abc123', 'order_id' => 42]; |
| 183 | $metaObj = ['wc_ticket' => []]; |
| 184 | $result = $this->core->getTicketId($codeObj, $metaObj); |
| 185 | $this->assertSame('', $result); |
| 186 | } |
| 187 | |
| 188 | // ── json_encode_with_error_handling ──────────────────────── |
| 189 | |
| 190 | public function test_json_encode_simple_array(): void { |
| 191 | $result = $this->core->json_encode_with_error_handling(['a' => 1, 'b' => 'test']); |
| 192 | $decoded = json_decode($result, true); |
| 193 | $this->assertSame(1, $decoded['a']); |
| 194 | $this->assertSame('test', $decoded['b']); |
| 195 | } |
| 196 | |
| 197 | public function test_json_encode_empty_array(): void { |
| 198 | $result = $this->core->json_encode_with_error_handling([]); |
| 199 | $this->assertSame('[]', $result); |
| 200 | } |
| 201 | |
| 202 | public function test_json_encode_nested_structure(): void { |
| 203 | $data = ['level1' => ['level2' => ['value' => 42]]]; |
| 204 | $result = $this->core->json_encode_with_error_handling($data); |
| 205 | $decoded = json_decode($result, true); |
| 206 | $this->assertSame(42, $decoded['level1']['level2']['value']); |
| 207 | } |
| 208 | |
| 209 | public function test_json_encode_numeric_check(): void { |
| 210 | // JSON_NUMERIC_CHECK flag converts numeric strings to numbers |
| 211 | $result = $this->core->json_encode_with_error_handling(['num' => '42']); |
| 212 | $decoded = json_decode($result, true); |
| 213 | $this->assertSame(42, $decoded['num']); |
| 214 | } |
| 215 | |
| 216 | // ── alignArrays ─────────────────────────────────────────── |
| 217 | |
| 218 | public function test_alignArrays_adds_missing_keys(): void { |
| 219 | $template = ['a' => 1, 'b' => 2, 'c' => 3]; |
| 220 | $target = ['a' => 10]; |
| 221 | $this->core->alignArrays($template, $target); |
| 222 | $this->assertArrayHasKey('b', $target); |
| 223 | $this->assertArrayHasKey('c', $target); |
| 224 | $this->assertSame(10, $target['a']); // keeps existing value |
| 225 | } |
| 226 | |
| 227 | public function test_alignArrays_removes_extra_keys(): void { |
| 228 | $template = ['a' => 1]; |
| 229 | $target = ['a' => 10, 'b' => 20, 'c' => 30]; |
| 230 | $this->core->alignArrays($template, $target); |
| 231 | $this->assertArrayHasKey('a', $target); |
| 232 | $this->assertArrayNotHasKey('b', $target); |
| 233 | $this->assertArrayNotHasKey('c', $target); |
| 234 | } |
| 235 | |
| 236 | public function test_alignArrays_recursive(): void { |
| 237 | $template = ['outer' => ['a' => 1, 'b' => 2]]; |
| 238 | $target = ['outer' => ['a' => 10, 'extra' => 99]]; |
| 239 | $this->core->alignArrays($template, $target); |
| 240 | $this->assertArrayHasKey('b', $target['outer']); |
| 241 | $this->assertArrayNotHasKey('extra', $target['outer']); |
| 242 | $this->assertSame(10, $target['outer']['a']); |
| 243 | } |
| 244 | |
| 245 | public function test_alignArrays_missing_subarray_added_empty(): void { |
| 246 | $template = ['nested' => ['x' => 1]]; |
| 247 | $target = []; |
| 248 | $this->core->alignArrays($template, $target); |
| 249 | $this->assertArrayHasKey('nested', $target); |
| 250 | // nested is added as [] first, then recursion adds 'x' => null |
| 251 | $this->assertArrayHasKey('x', $target['nested']); |
| 252 | $this->assertNull($target['nested']['x']); |
| 253 | } |
| 254 | |
| 255 | // ── getMetaObjectList + getMetaObjectAuthtoken ───────────── |
| 256 | |
| 257 | public function test_getMetaObjectList_returns_array(): void { |
| 258 | $meta = $this->core->getMetaObjectList(); |
| 259 | $this->assertIsArray($meta); |
| 260 | } |
| 261 | |
| 262 | public function test_getMetaObjectAuthtoken_returns_array(): void { |
| 263 | $meta = $this->core->getMetaObjectAuthtoken(); |
| 264 | $this->assertIsArray($meta); |
| 265 | } |
| 266 | |
| 267 | public function test_getMetaObjectAuthtoken_has_ticketscanner_key(): void { |
| 268 | $meta = $this->core->getMetaObjectAuthtoken(); |
| 269 | $this->assertArrayHasKey('ticketscanner', $meta); |
| 270 | } |
| 271 | |
| 272 | // ── getDefaultMetaValueOfSubs ────────────────────────────── |
| 273 | |
| 274 | public function test_getDefaultMetaValueOfSubs_returns_array(): void { |
| 275 | $subs = $this->core->getDefaultMetaValueOfSubs(); |
| 276 | $this->assertIsArray($subs); |
| 277 | } |
| 278 | } |
| 279 |