File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/scratch/test_admin_reports_flow.php
Back
<?php /** * Test Admin Reports End-to-End Flow */ require_once __DIR__ . '/../database/Database.php'; require_once __DIR__ . '/../app/Models/Report.php'; require_once __DIR__ . '/../app/Models/User.php'; require_once __DIR__ . '/../app/Services/AdminReportService.php'; $db = Database::getInstance(); $reportModel = new Report(); $service = new AdminReportService(); echo "=== TEST 1: Get Reports List & Status Counts ===\n"; $data = $service->getReports(['status' => 'all', 'report_type' => 'all', 'q' => '']); assert(isset($data['reports']), "Reports list should exist"); assert(isset($data['total']), "Total count should exist"); assert(isset($data['counts']), "Counts should exist"); assert(isset($data['counts']['pending']), "Pending count should exist"); assert(isset($data['counts']['reviewing']), "Reviewing count should exist"); assert(isset($data['counts']['resolved']), "Resolved count should exist"); assert(isset($data['counts']['rejected']), "Rejected count should exist"); echo " [PASS] Reports listing and status counts retrieved successfully. Total: {$data['total']}\n"; echo "\n=== TEST 2: Submit New Test Report ===\n"; $adminUser = $db->query("SELECT id FROM users WHERE is_super_admin = 1 LIMIT 1")->fetch(PDO::FETCH_ASSOC); $adminId = (int)($adminUser['id'] ?? 1); $testReportId = $reportModel->submitReport( $adminId, 'product', 1, 'สินค้าต้องสงสัยละเมิดเครื่องหมายการค้า', 'พบการแอบอ้างยี่ห้อและภาพสินค้าไม่ตรงกับของจริง', json_encode(['/uploads/evidence1.jpg', '/uploads/evidence2.jpg']) ); assert($testReportId > 0, "Test report ID should be positive"); echo " [PASS] Test report created with ID: {$testReportId}\n"; echo "\n=== TEST 3: Get Report Detail with Target Info ===\n"; $detail = $service->getReportDetail($testReportId); assert($detail !== null, "Report detail must exist"); assert($detail['status'] === 'pending', "Initial status must be pending"); assert($detail['reporter_id'] == $adminId, "Reporter ID must match"); echo " [PASS] Report detail fetched with reporter username: " . ($detail['reporter_username'] ?? 'N/A') . "\n"; echo "\n=== TEST 4: Assign and Review Report ===\n"; $resReview = $service->assignAndReview($testReportId, $adminId); assert($resReview['success'] === true, "Review action must succeed: " . ($resReview['message'] ?? '')); $detailAfterReview = $service->getReportDetail($testReportId); assert($detailAfterReview['status'] === 'reviewing', "Status must transition to reviewing"); assert($detailAfterReview['resolved_by'] == $adminId, "Admin ID must be recorded"); echo " [PASS] Transitioned to 'reviewing' successfully\n"; echo "\n=== TEST 5: Resolve Report ===\n"; $resResolve = $service->resolve($testReportId, 'ตรวจสอบแล้ว ทำการตักเตือนผู้ขายและซ่อนสินค้า', $adminId); assert($resResolve['success'] === true, "Resolve action must succeed: " . ($resResolve['message'] ?? '')); $detailAfterResolve = $service->getReportDetail($testReportId); assert($detailAfterResolve['status'] === 'resolved', "Status must transition to resolved"); assert(!empty($detailAfterResolve['resolution_note']), "Resolution note must be saved"); echo " [PASS] Transitioned to 'resolved' with note: {$detailAfterResolve['resolution_note']}\n"; echo "\n=== TEST 6: Reject Action on Another Test Report ===\n"; $testRejectId = $reportModel->submitReport($adminId, 'seller', 1, 'รายงานร้านค้า', 'รายละเอียด'); $resReject = $service->reject($testRejectId, 'ไม่พบหลักฐานความผิดปกติ', $adminId); assert($resReject['success'] === true, "Reject action must succeed"); $detailAfterReject = $service->getReportDetail($testRejectId); assert($detailAfterReject['status'] === 'rejected', "Status must transition to rejected"); echo " [PASS] Transitioned to 'rejected' successfully\n"; echo "\n=== TEST 7: Filtering and Search by Keyword ===\n"; $filterSearch = $service->getReports(['status' => 'resolved', 'report_type' => 'product', 'q' => 'เครื่องหมายการค้า']); assert($filterSearch['total'] >= 1, "Filter search must find the resolved product report"); echo " [PASS] Filter search returned matching reports count: {$filterSearch['total']}\n"; // Cleanup test reports $db->exec("DELETE FROM reports WHERE id IN ({$testReportId}, {$testRejectId})"); echo "\n=== CLEANUP: Removed test reports ===\n"; echo "ALL ADMIN REPORTS TESTS PASSED SUCCESSFULLY! (7/7)\n";
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings