File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/scratch/test_clean_state_creation.php
Back
<?php /** * Test Clean State Lifecycle * Verifies that: * 1. Customer frontend currently displays 0 demo stores/products * 2. A new seller can create a store and product * 3. Newly created product is visible on customer frontend * 4. Cleaning up leaves the marketplace clean */ declare(strict_types=1); require_once __DIR__ . '/../database/Database.php'; require_once __DIR__ . '/../app/Models/Product.php'; require_once __DIR__ . '/../app/Models/Store.php'; require_once __DIR__ . '/../app/Models/Category.php'; require_once __DIR__ . '/../app/Models/User.php'; require_once __DIR__ . '/../app/Services/ProductService.php'; $db = Database::getInstance(); $productService = new ProductService(); $storeModel = new Store(); $productModel = new Product(); $userModel = new User(); echo "\n=== 1. VERIFY CLEAN STATE ===\n"; $homeData = $productService->getHomepageData(); echo "Featured Products count: " . count($homeData['featured_products']) . "\n"; echo "Latest Products count: " . count($homeData['latest_products']) . "\n"; echo "Active Stores count: " . count($homeData['stores']) . "\n"; assert(count($homeData['featured_products']) === 0, "Expected 0 featured products"); assert(count($homeData['latest_products']) === 0, "Expected 0 latest products"); assert(count($homeData['stores']) === 0, "Expected 0 active stores"); echo " [PASS] Clean frontend state verified!\n"; echo "\n=== 2. SELLER CREATES NEW STORE & PRODUCT ===\n"; // Use real user ctn_ng (id: 2) or create a fresh store $storeSlug = 'cargoo-official-store'; $existingStore = $db->query("SELECT id FROM stores WHERE store_slug = '{$storeSlug}'")->fetch(PDO::FETCH_ASSOC); if ($existingStore) { $db->exec("DELETE FROM stores WHERE id = {$existingStore['id']}"); } $newStoreId = $storeModel->insert([ 'user_id' => 2, 'store_name' => 'CARGOO Official Store', 'store_slug' => $storeSlug, 'description' => 'ร้านค้าอย่างเป็นทางการ CARGOO', 'status' => 'active', 'verified_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); echo "Created new active store ID: {$newStoreId}\n"; $prodSlug = 'cargoo-premium-tshirt'; $existingProd = $db->query("SELECT id FROM products WHERE slug = '{$prodSlug}'")->fetch(PDO::FETCH_ASSOC); if ($existingProd) { $db->exec("DELETE FROM products WHERE id = {$existingProd['id']}"); } $newProductId = $productModel->insert([ 'store_id' => $newStoreId, 'seller_id' => 2, 'category_id' => 1, 'name' => 'CARGOO Premium T-Shirt', 'slug' => $prodSlug, 'description' => 'เสื้อยืดลิขสิทธิ์แท้ CARGOO ผ้าคอตตอน 100%', 'price' => 390.00, 'original_price' => 590.00, 'stock' => 100, 'status' => 'active', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); echo "Created new active product ID: {$newProductId}\n"; echo "\n=== 3. VERIFY NEW STORE & PRODUCT ON CUSTOMER FRONTEND ===\n"; $homeDataAfter = $productService->getHomepageData(); echo "Featured Products count after creation: " . count($homeDataAfter['featured_products']) . "\n"; echo "Active Stores count after creation: " . count($homeDataAfter['stores']) . "\n"; assert(count($homeDataAfter['featured_products']) === 1, "Expected 1 featured product"); assert(count($homeDataAfter['stores']) === 1, "Expected 1 active store"); echo " [PASS] Newly created store and product appear seamlessly on Customer Frontend!\n"; echo "\n=== 4. CLEANING UP TEST CREATION ===\n"; $db->exec("DELETE FROM products WHERE id = {$newProductId}"); $db->exec("DELETE FROM stores WHERE id = {$newStoreId}"); $finalHomeData = $productService->getHomepageData(); assert(count($finalHomeData['featured_products']) === 0, "Expected 0 featured products after cleanup"); assert(count($finalHomeData['stores']) === 0, "Expected 0 stores after cleanup"); echo " [PASS] Marketplace returned to clean state!\n";
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings