File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/scratch/test_store_schema_fix.php
Back
<?php /** * Store Schema Alignment & Operations Test Suite */ require_once __DIR__ . '/../database/Database.php'; require_once __DIR__ . '/../app/Models/Store.php'; require_once __DIR__ . '/../app/Models/Product.php'; require_once __DIR__ . '/../app/Services/AdminSellerService.php'; require_once __DIR__ . '/../app/Services/AdminDashboardService.php'; require_once __DIR__ . '/../app/Services/StoreService.php'; $totalPassed = 0; $totalFailed = 0; function assertTest(bool $condition, string $name) { global $totalPassed, $totalFailed; if ($condition) { echo " [PASS] {$name}" . PHP_EOL; $totalPassed++; } else { echo " [FAIL] {$name}" . PHP_EOL; $totalFailed++; } } echo PHP_EOL . "==========================================================" . PHP_EOL; echo "TEST SUITE: Store Model & Admin Dashboard Integration" . PHP_EOL; echo "==========================================================" . PHP_EOL; $storeModel = new Store(); $dashboardService = new AdminDashboardService(); $adminSellerService = new AdminSellerService(); $storeService = new StoreService(); $productModel = new Product(); // 1. Test getPlatformStoreStats() try { $storeStats = $storeModel->getPlatformStoreStats(); assertTest(is_array($storeStats), 'getPlatformStoreStats returns array'); assertTest(isset($storeStats['total_stores']), 'store_stats has total_stores'); assertTest(isset($storeStats['official_stores']), 'store_stats has official_stores'); assertTest(isset($storeStats['active_stores']), 'store_stats has active_stores'); } catch (Exception $e) { assertTest(false, 'getPlatformStoreStats threw exception: ' . $e->getMessage()); } // 2. Test AdminDashboardService::getDashboardData() try { $dashData = $dashboardService->getDashboardData(); assertTest(is_array($dashData), 'AdminDashboardService::getDashboardData executes without error'); assertTest(!empty($dashData['store_stats']), 'Dashboard data contains store_stats'); } catch (Exception $e) { assertTest(false, 'AdminDashboardService::getDashboardData threw exception: ' . $e->getMessage()); } echo PHP_EOL . "==========================================================" . PHP_EOL; echo "TEST SUITE: Admin Seller Listing & Filters" . PHP_EOL; echo "==========================================================" . PHP_EOL; // 3. Test getStores with various filters try { $allStores = $adminSellerService->getStores(['q' => '', 'status' => 'all', 'store_type' => 'all'], 1, 10); assertTest(is_array($allStores['stores']), 'getStores (all) executes successfully'); $officialStores = $adminSellerService->getStores(['q' => '', 'status' => 'all', 'store_type' => 'official'], 1, 10); assertTest(is_array($officialStores['stores']), 'getStores (official) executes successfully'); $standardStores = $adminSellerService->getStores(['q' => '', 'status' => 'all', 'store_type' => 'standard'], 1, 10); assertTest(is_array($standardStores['stores']), 'getStores (standard) executes successfully'); $activeStores = $adminSellerService->getStores(['q' => '', 'status' => 'active', 'store_type' => 'all'], 1, 10); assertTest(is_array($activeStores['stores']), 'getStores (status=active) executes successfully'); } catch (Exception $e) { assertTest(false, 'getStores filter queries threw exception: ' . $e->getMessage()); } echo PHP_EOL . "==========================================================" . PHP_EOL; echo "TEST SUITE: Store Details & Official Status Toggle" . PHP_EOL; echo "==========================================================" . PHP_EOL; // 4. Test store detail & official status toggle on first available store $firstStore = $storeModel->fetchOne("SELECT id, user_id, verified_at FROM stores WHERE deleted_at IS NULL LIMIT 1"); if ($firstStore) { $testStoreId = (int)$firstStore['id']; // Get store detail $detail = $adminSellerService->getStoreDetail($testStoreId); assertTest($detail !== null, "getStoreDetail(#{$testStoreId}) returns valid data"); assertTest(isset($detail['stats']), "Store detail includes stats"); // Toggle official to TRUE $res1 = $adminSellerService->setOfficialStatus($testStoreId, true, 1); assertTest($res1['success'] === true, 'setOfficialStatus(true) succeeds'); $check1 = $storeModel->fetchOne("SELECT verified_at FROM stores WHERE id = :id", [':id' => $testStoreId]); assertTest(!empty($check1['verified_at']), 'verified_at is populated when official is true'); // Toggle official to FALSE $res2 = $adminSellerService->setOfficialStatus($testStoreId, false, 1); assertTest($res2['success'] === true, 'setOfficialStatus(false) succeeds'); $check2 = $storeModel->fetchOne("SELECT verified_at FROM stores WHERE id = :id", [':id' => $testStoreId]); assertTest(empty($check2['verified_at']), 'verified_at is NULL when official is false'); // Restore original state if needed if (!empty($firstStore['verified_at'])) { $adminSellerService->setOfficialStatus($testStoreId, true, 1); } } else { echo " [SKIP] No store found in database to test store detail" . PHP_EOL; } echo PHP_EOL . "==========================================================" . PHP_EOL; echo "TEST SUITE: Customer Storefront & Product Association" . PHP_EOL; echo "==========================================================" . PHP_EOL; try { $activeStores = $storeModel->getActiveStores(4); assertTest(is_array($activeStores), 'getActiveStores returns list for homepage'); $catalogSearch = $productModel->search([], 5, 0); assertTest(is_array($catalogSearch), 'product search includes store join without errors'); } catch (Exception $e) { assertTest(false, 'Customer storefront queries threw exception: ' . $e->getMessage()); } echo PHP_EOL . "==========================================================" . PHP_EOL; echo "TEST RESULTS SUMMARY: Passed: {$totalPassed} | Failed: {$totalFailed}" . PHP_EOL; echo "==========================================================" . PHP_EOL; if ($totalFailed === 0) { echo ">>> ALL STORE SCHEMA & OPERATION TESTS PASSED! <<<" . PHP_EOL; exit(0); } else { echo ">>> SOME TESTS FAILED! <<<" . PHP_EOL; exit(1); }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings