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
DatabaseTest.php
251 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Integration tests for the database layer (codes, lists CRUD). |
| 4 | */ |
| 5 | |
| 6 | class DatabaseTest extends WP_UnitTestCase { |
| 7 | |
| 8 | private $db; |
| 9 | private sasoEventtickets_Core $core; |
| 10 | |
| 11 | public function set_up(): void { |
| 12 | parent::set_up(); |
| 13 | $main = sasoEventtickets::Instance(); |
| 14 | $this->db = $main->getDB(); |
| 15 | $this->core = $main->getCore(); |
| 16 | } |
| 17 | |
| 18 | // ── Table names ──────────────────────────────────────────── |
| 19 | |
| 20 | public function test_getTabelle_codes(): void { |
| 21 | global $wpdb; |
| 22 | $expected = $wpdb->prefix . 'saso_eventtickets_codes'; |
| 23 | $this->assertSame($expected, $this->db->getTabelle('codes')); |
| 24 | } |
| 25 | |
| 26 | public function test_getTabelle_lists(): void { |
| 27 | global $wpdb; |
| 28 | $expected = $wpdb->prefix . 'saso_eventtickets_lists'; |
| 29 | $this->assertSame($expected, $this->db->getTabelle('lists')); |
| 30 | } |
| 31 | |
| 32 | public function test_getTabelle_authtokens(): void { |
| 33 | global $wpdb; |
| 34 | $expected = $wpdb->prefix . 'saso_eventtickets_authtokens'; |
| 35 | $this->assertSame($expected, $this->db->getTabelle('authtokens')); |
| 36 | } |
| 37 | |
| 38 | public function test_getTables_returns_all_tables(): void { |
| 39 | $tables = $this->db->getTables(); |
| 40 | $this->assertIsArray($tables); |
| 41 | // getTables() returns indexed array of table short names |
| 42 | $this->assertContains('codes', $tables); |
| 43 | $this->assertContains('lists', $tables); |
| 44 | $this->assertContains('authtokens', $tables); |
| 45 | $this->assertContains('seatingplans', $tables); |
| 46 | $this->assertContains('seats', $tables); |
| 47 | } |
| 48 | |
| 49 | // ── Lists CRUD ───────────────────────────────────────────── |
| 50 | |
| 51 | public function test_insert_and_retrieve_list(): void { |
| 52 | $listName = 'PHPUnit Test List ' . uniqid(); |
| 53 | $id = $this->db->insert('lists', [ |
| 54 | 'name' => $listName, |
| 55 | 'aktiv' => 1, |
| 56 | 'meta' => '{}', |
| 57 | ]); |
| 58 | $this->assertGreaterThan(0, $id); |
| 59 | |
| 60 | $list = $this->core->getListById($id); |
| 61 | $this->assertSame($listName, $list['name']); |
| 62 | $this->assertEquals(1, $list['aktiv']); |
| 63 | } |
| 64 | |
| 65 | public function test_update_list(): void { |
| 66 | $id = $this->db->insert('lists', [ |
| 67 | 'name' => 'Before Update ' . uniqid(), |
| 68 | 'aktiv' => 1, |
| 69 | 'meta' => '{}', |
| 70 | ]); |
| 71 | $newName = 'After Update ' . uniqid(); |
| 72 | $this->db->update('lists', ['name' => $newName], ['id' => $id]); |
| 73 | |
| 74 | $list = $this->core->getListById($id); |
| 75 | $this->assertSame($newName, $list['name']); |
| 76 | } |
| 77 | |
| 78 | // ── Codes CRUD ───────────────────────────────────────────── |
| 79 | |
| 80 | public function test_insert_and_retrieve_code(): void { |
| 81 | // First create a list |
| 82 | $listId = $this->db->insert('lists', [ |
| 83 | 'name' => 'Code Test List ' . uniqid(), |
| 84 | 'aktiv' => 1, |
| 85 | 'meta' => '{}', |
| 86 | ]); |
| 87 | |
| 88 | $code = 'PHPUNIT' . strtoupper(uniqid()); |
| 89 | $metaObj = $this->core->getMetaObject(); |
| 90 | $metaJson = $this->core->json_encode_with_error_handling($metaObj); |
| 91 | |
| 92 | $codeId = $this->db->insert('codes', [ |
| 93 | 'code' => $code, |
| 94 | 'code_display' => $code, |
| 95 | 'cvv' => '1234', |
| 96 | 'meta' => $metaJson, |
| 97 | 'aktiv' => 1, |
| 98 | 'redeemed' => 0, |
| 99 | 'list_id' => $listId, |
| 100 | 'order_id' => 0, |
| 101 | ]); |
| 102 | $this->assertGreaterThan(0, $codeId); |
| 103 | |
| 104 | // Retrieve by code |
| 105 | $retrieved = $this->core->retrieveCodeByCode($code); |
| 106 | $this->assertSame($code, $retrieved['code']); |
| 107 | $this->assertEquals($listId, $retrieved['list_id']); |
| 108 | $this->assertEquals(0, $retrieved['redeemed']); |
| 109 | } |
| 110 | |
| 111 | public function test_retrieve_code_by_id(): void { |
| 112 | $listId = $this->db->insert('lists', [ |
| 113 | 'name' => 'ById Test ' . uniqid(), |
| 114 | 'aktiv' => 1, |
| 115 | 'meta' => '{}', |
| 116 | ]); |
| 117 | |
| 118 | $code = 'BYID' . strtoupper(uniqid()); |
| 119 | $codeId = $this->db->insert('codes', [ |
| 120 | 'code' => $code, |
| 121 | 'code_display' => $code, |
| 122 | 'cvv' => '5678', |
| 123 | 'meta' => '{}', |
| 124 | 'aktiv' => 1, |
| 125 | 'redeemed' => 0, |
| 126 | 'list_id' => $listId, |
| 127 | 'order_id' => 0, |
| 128 | ]); |
| 129 | |
| 130 | $retrieved = $this->core->retrieveCodeById($codeId); |
| 131 | $this->assertSame($code, $retrieved['code']); |
| 132 | } |
| 133 | |
| 134 | public function test_getCodesSize_increments(): void { |
| 135 | $sizeBefore = $this->db->getCodesSize(); |
| 136 | |
| 137 | $listId = $this->db->insert('lists', [ |
| 138 | 'name' => 'Size Test ' . uniqid(), |
| 139 | 'aktiv' => 1, |
| 140 | 'meta' => '{}', |
| 141 | ]); |
| 142 | |
| 143 | $this->db->insert('codes', [ |
| 144 | 'code' => 'SIZE' . strtoupper(uniqid()), |
| 145 | 'code_display' => '', |
| 146 | 'cvv' => '', |
| 147 | 'meta' => '{}', |
| 148 | 'aktiv' => 1, |
| 149 | 'redeemed' => 0, |
| 150 | 'list_id' => $listId, |
| 151 | 'order_id' => 0, |
| 152 | ]); |
| 153 | |
| 154 | $sizeAfter = $this->db->getCodesSize(); |
| 155 | $this->assertEquals($sizeBefore + 1, $sizeAfter); |
| 156 | } |
| 157 | |
| 158 | public function test_getCodesByOrderId_returns_matching(): void { |
| 159 | $listId = $this->db->insert('lists', [ |
| 160 | 'name' => 'Order Test ' . uniqid(), |
| 161 | 'aktiv' => 1, |
| 162 | 'meta' => '{}', |
| 163 | ]); |
| 164 | |
| 165 | $orderId = 99999; |
| 166 | $code1 = 'ORD1' . strtoupper(uniqid()); |
| 167 | $code2 = 'ORD2' . strtoupper(uniqid()); |
| 168 | |
| 169 | $this->db->insert('codes', [ |
| 170 | 'code' => $code1, |
| 171 | 'code_display' => $code1, |
| 172 | 'cvv' => '', |
| 173 | 'meta' => '{}', |
| 174 | 'aktiv' => 1, |
| 175 | 'redeemed' => 0, |
| 176 | 'list_id' => $listId, |
| 177 | 'order_id' => $orderId, |
| 178 | ]); |
| 179 | $this->db->insert('codes', [ |
| 180 | 'code' => $code2, |
| 181 | 'code_display' => $code2, |
| 182 | 'cvv' => '', |
| 183 | 'meta' => '{}', |
| 184 | 'aktiv' => 1, |
| 185 | 'redeemed' => 0, |
| 186 | 'list_id' => $listId, |
| 187 | 'order_id' => $orderId, |
| 188 | ]); |
| 189 | |
| 190 | $codes = $this->core->getCodesByOrderId($orderId); |
| 191 | $this->assertCount(2, $codes); |
| 192 | $foundCodes = array_column($codes, 'code'); |
| 193 | $this->assertContains($code1, $foundCodes); |
| 194 | $this->assertContains($code2, $foundCodes); |
| 195 | } |
| 196 | |
| 197 | public function test_update_code_redeemed_flag(): void { |
| 198 | $listId = $this->db->insert('lists', [ |
| 199 | 'name' => 'Redeem Flag Test ' . uniqid(), |
| 200 | 'aktiv' => 1, |
| 201 | 'meta' => '{}', |
| 202 | ]); |
| 203 | |
| 204 | $code = 'REDF' . strtoupper(uniqid()); |
| 205 | $codeId = $this->db->insert('codes', [ |
| 206 | 'code' => $code, |
| 207 | 'code_display' => $code, |
| 208 | 'cvv' => '', |
| 209 | 'meta' => '{}', |
| 210 | 'aktiv' => 1, |
| 211 | 'redeemed' => 0, |
| 212 | 'list_id' => $listId, |
| 213 | 'order_id' => 0, |
| 214 | ]); |
| 215 | |
| 216 | // Mark as redeemed |
| 217 | $this->db->update('codes', ['redeemed' => 1], ['id' => $codeId]); |
| 218 | |
| 219 | $retrieved = $this->core->retrieveCodeById($codeId); |
| 220 | $this->assertEquals(1, $retrieved['redeemed']); |
| 221 | } |
| 222 | |
| 223 | // ── reinigen_in (input sanitization) ─────────────────────── |
| 224 | |
| 225 | public function test_reinigen_in_trims(): void { |
| 226 | $this->assertSame('hello', $this->db->reinigen_in(' hello ')); |
| 227 | } |
| 228 | |
| 229 | public function test_reinigen_in_length_limit(): void { |
| 230 | $result = $this->db->reinigen_in('abcdefghij', 5); |
| 231 | $this->assertSame(5, strlen($result)); |
| 232 | } |
| 233 | |
| 234 | public function test_reinigen_in_html_entities(): void { |
| 235 | $result = $this->db->reinigen_in('<script>alert(1)</script>', 0, 0, 0, 1); |
| 236 | $this->assertStringNotContainsString('<script>', $result); |
| 237 | } |
| 238 | |
| 239 | // ── insert validation ────────────────────────────────────── |
| 240 | |
| 241 | public function test_insert_throws_on_empty_fields(): void { |
| 242 | $this->expectException(Exception::class); |
| 243 | $this->db->insert('codes', []); |
| 244 | } |
| 245 | |
| 246 | public function test_update_throws_on_empty_where(): void { |
| 247 | $this->expectException(Exception::class); |
| 248 | $this->db->update('codes', ['aktiv' => 1], []); |
| 249 | } |
| 250 | } |
| 251 |