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
CoreEncodeMetaTest.php
171 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tests for Core methods: encodeMetaValuesAndFillObject, |
| 4 | * encodeMetaValuesAndFillObjectAuthtoken. |
| 5 | */ |
| 6 | |
| 7 | class CoreEncodeMetaTest 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 | |
| 16 | private function createCodeInList(): array { |
| 17 | $listId = $this->main->getDB()->insert('lists', [ |
| 18 | 'name' => 'EncodeMeta Test ' . uniqid(), |
| 19 | 'aktiv' => 1, |
| 20 | 'meta' => '{}', |
| 21 | ]); |
| 22 | |
| 23 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 24 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 25 | |
| 26 | $code = 'ENC' . strtoupper(uniqid()); |
| 27 | $this->main->getDB()->insert('codes', [ |
| 28 | 'code' => $code, |
| 29 | 'code_display' => $code, |
| 30 | 'cvv' => '', |
| 31 | 'meta' => $metaJson, |
| 32 | 'aktiv' => 1, |
| 33 | 'redeemed' => 0, |
| 34 | 'list_id' => $listId, |
| 35 | 'order_id' => 0, |
| 36 | ]); |
| 37 | |
| 38 | return ['code' => $code, 'list_id' => $listId]; |
| 39 | } |
| 40 | |
| 41 | // ── encodeMetaValuesAndFillObject ──────────────────────────── |
| 42 | |
| 43 | public function test_encodeMetaValuesAndFillObject_returns_array(): void { |
| 44 | $data = $this->createCodeInList(); |
| 45 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 46 | |
| 47 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 48 | $this->assertIsArray($result); |
| 49 | } |
| 50 | |
| 51 | public function test_encodeMetaValuesAndFillObject_has_default_keys(): void { |
| 52 | $data = $this->createCodeInList(); |
| 53 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 54 | |
| 55 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 56 | $this->assertArrayHasKey('user', $result); |
| 57 | $this->assertArrayHasKey('used', $result); |
| 58 | $this->assertArrayHasKey('wc_ticket', $result); |
| 59 | $this->assertArrayHasKey('woocommerce', $result); |
| 60 | $this->assertArrayHasKey('confirmedCount', $result); |
| 61 | $this->assertArrayHasKey('validation', $result); |
| 62 | } |
| 63 | |
| 64 | public function test_encodeMetaValuesAndFillObject_resolves_empty_usernames(): void { |
| 65 | $data = $this->createCodeInList(); |
| 66 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 67 | |
| 68 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 69 | // No user registered, so _reg_username should be empty |
| 70 | $this->assertEquals('', $result['user']['_reg_username']); |
| 71 | $this->assertEquals('', $result['used']['_reg_username']); |
| 72 | $this->assertEquals('', $result['wc_ticket']['_username']); |
| 73 | } |
| 74 | |
| 75 | public function test_encodeMetaValuesAndFillObject_resolves_real_user(): void { |
| 76 | $userId = self::factory()->user->create([ |
| 77 | 'first_name' => 'TestFirst', |
| 78 | 'last_name' => 'TestLast', |
| 79 | 'user_login' => 'testencodeuser_' . uniqid(), |
| 80 | ]); |
| 81 | |
| 82 | $data = $this->createCodeInList(); |
| 83 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 84 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 85 | $metaObj['user']['reg_userid'] = $userId; |
| 86 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 87 | |
| 88 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($metaJson, $codeObj); |
| 89 | $this->assertStringContainsString('TestFirst', $result['user']['_reg_username']); |
| 90 | $this->assertStringContainsString('TestLast', $result['user']['_reg_username']); |
| 91 | } |
| 92 | |
| 93 | public function test_encodeMetaValuesAndFillObject_invalid_userid_shows_error(): void { |
| 94 | $data = $this->createCodeInList(); |
| 95 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 96 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 97 | $metaObj['user']['reg_userid'] = 999999; |
| 98 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 99 | |
| 100 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($metaJson, $codeObj); |
| 101 | $this->assertStringContainsString('NOT EXISTS', $result['user']['_reg_username']); |
| 102 | } |
| 103 | |
| 104 | public function test_encodeMetaValuesAndFillObject_without_codeObj(): void { |
| 105 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 106 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 107 | |
| 108 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($metaJson); |
| 109 | $this->assertIsArray($result); |
| 110 | $this->assertArrayHasKey('user', $result); |
| 111 | } |
| 112 | |
| 113 | public function test_encodeMetaValuesAndFillObject_fills_validation_from_used(): void { |
| 114 | $data = $this->createCodeInList(); |
| 115 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 116 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 117 | $metaObj['confirmedCount'] = 3; |
| 118 | $metaObj['used']['reg_request'] = '2026-01-15 10:00:00'; |
| 119 | $metaObj['used']['reg_request_tz'] = 'Europe/Berlin'; |
| 120 | $metaObj['used']['reg_ip'] = '10.0.0.1'; |
| 121 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 122 | |
| 123 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($metaJson, $codeObj); |
| 124 | $this->assertEquals('2026-01-15 10:00:00', $result['validation']['first_success']); |
| 125 | $this->assertEquals('Europe/Berlin', $result['validation']['first_success_tz']); |
| 126 | $this->assertEquals('10.0.0.1', $result['validation']['first_ip']); |
| 127 | } |
| 128 | |
| 129 | public function test_encodeMetaValuesAndFillObject_preserves_stored_values(): void { |
| 130 | $data = $this->createCodeInList(); |
| 131 | $codeObj = $this->main->getCore()->retrieveCodeByCode($data['code']); |
| 132 | $metaObj = $this->main->getCore()->getMetaObject(); |
| 133 | $metaObj['user']['value'] = 'stored_user@example.com'; |
| 134 | $metaObj['confirmedCount'] = 7; |
| 135 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 136 | |
| 137 | $result = $this->main->getCore()->encodeMetaValuesAndFillObject($metaJson, $codeObj); |
| 138 | $this->assertEquals('stored_user@example.com', $result['user']['value']); |
| 139 | $this->assertEquals(7, $result['confirmedCount']); |
| 140 | } |
| 141 | |
| 142 | // ── encodeMetaValuesAndFillObjectAuthtoken ─────────────────── |
| 143 | |
| 144 | public function test_encodeMetaValuesAndFillObjectAuthtoken_returns_array(): void { |
| 145 | $metaObj = $this->main->getCore()->getMetaObjectAuthtoken(); |
| 146 | $metaJson = $this->main->getCore()->json_encode_with_error_handling($metaObj); |
| 147 | |
| 148 | $result = $this->main->getCore()->encodeMetaValuesAndFillObjectAuthtoken($metaJson); |
| 149 | $this->assertIsArray($result); |
| 150 | } |
| 151 | |
| 152 | public function test_encodeMetaValuesAndFillObjectAuthtoken_fills_defaults(): void { |
| 153 | $result = $this->main->getCore()->encodeMetaValuesAndFillObjectAuthtoken('{}'); |
| 154 | $this->assertIsArray($result); |
| 155 | $this->assertArrayHasKey('desc', $result); |
| 156 | $this->assertArrayHasKey('ticketscanner', $result); |
| 157 | } |
| 158 | |
| 159 | public function test_encodeMetaValuesAndFillObjectAuthtoken_preserves_values(): void { |
| 160 | $meta = json_encode(['desc' => 'Test description', 'ticketscanner' => ['bound_to_products' => '42']]); |
| 161 | $result = $this->main->getCore()->encodeMetaValuesAndFillObjectAuthtoken($meta); |
| 162 | $this->assertEquals('Test description', $result['desc']); |
| 163 | $this->assertEquals('42', $result['ticketscanner']['bound_to_products']); |
| 164 | } |
| 165 | |
| 166 | public function test_encodeMetaValuesAndFillObjectAuthtoken_empty_string(): void { |
| 167 | $result = $this->main->getCore()->encodeMetaValuesAndFillObjectAuthtoken(''); |
| 168 | $this->assertIsArray($result); |
| 169 | } |
| 170 | } |
| 171 |