Admin -> ShowImage', function () { // Test 1: API returns image data $response = curl_exec_with_fallback('https://localhost/api/images', [ 'headers' => ['User-Agent: Mozilla/5.0'], 'json' => true ]); expect($response)->toBeArray(); expect($response['images'])->toBeArray(); expect(count($response['images']))->toBeGreaterThan(0); $firstImage = $response['images'][0]; expect($firstImage)->toHaveKey('filename'); expect($firstImage)->toHaveKey('url'); expect($firstImage['url'])->toStartWith('/images/'); $imageUrl = $firstImage['url']; $filename = $firstImage['filename']; // Test 2: Admin page loads successfully $adminResponse = curl_exec_with_fallback('https://localhost/admin/images', [ 'headers' => ['User-Agent: Mozilla/5.0'] ]); expect($adminResponse)->toBeString(); expect(strlen($adminResponse))->toBeGreaterThan(1000); // Should be substantial HTML // Test 3: ShowImage controller responds (even if file missing) $imageResponse = curl_exec_with_status('https://localhost' . $imageUrl, [ 'headers' => ['User-Agent: Mozilla/5.0'] ]); // Either success (200) or file not found error (500 with specific message) $status = $imageResponse['status']; $content = $imageResponse['content']; if ($status === 200) { // Image exists and is served expect($content)->toBeString(); expect(strlen($content))->toBeGreaterThan(0); } else { // Image not found - this is expected for some test images expect($status)->toBe(500); expect($content)->toContain('Image file not found on filesystem'); } // Test 4: Database lookup works (API returned data) expect($firstImage['ulid'])->toBeString(); expect(strlen($firstImage['ulid']))->toBe(26); // ULID length }); it('identifies the specific issue preventing image display', function () { // Get all images from API $apiResponse = curl_exec_with_fallback('https://localhost/api/images', [ 'headers' => ['User-Agent: Mozilla/5.0'], 'json' => true ]); $images = $apiResponse['images']; $workingImages = []; $brokenImages = []; foreach ($images as $image) { $imageUrl = 'https://localhost' . $image['url']; $response = curl_exec_with_status($imageUrl, [ 'headers' => ['User-Agent: Mozilla/5.0'] ]); if ($response['status'] === 200) { $workingImages[] = $image; } else { $brokenImages[] = [ 'image' => $image, 'error' => $response['content'] ]; } } // Report findings $totalImages = count($images); $workingCount = count($workingImages); $brokenCount = count($brokenImages); expect($totalImages)->toBeGreaterThan(0); if ($brokenCount > 0) { // Identify the issue pattern $errorPatterns = []; foreach ($brokenImages as $broken) { if (str_contains($broken['error'], 'Image file not found on filesystem')) { $errorPatterns['missing_files'][] = $broken['image']['filename']; } elseif (str_contains($broken['error'], 'Image not found:')) { $errorPatterns['db_missing'][] = $broken['image']['filename']; } else { $errorPatterns['other_errors'][] = $broken['error']; } } // Diagnostic output echo "\n=== IMAGE DISPLAY DIAGNOSTIC ===\n"; echo "Total images in API: $totalImages\n"; echo "Working images: $workingCount\n"; echo "Broken images: $brokenCount\n"; if (isset($errorPatterns['missing_files'])) { $count = count($errorPatterns['missing_files']); echo "\nMissing files on filesystem: $count\n"; foreach (array_slice($errorPatterns['missing_files'], 0, 3) as $filename) { echo " - $filename\n"; } } if (isset($errorPatterns['db_missing'])) { $count = count($errorPatterns['db_missing']); echo "\nMissing from database: $count\n"; } if (isset($errorPatterns['other_errors'])) { echo "\nOther errors:\n"; foreach (array_slice($errorPatterns['other_errors'], 0, 2) as $error) { echo " - " . substr($error, 0, 100) . "\n"; } } echo "\n=== RECOMMENDATION ===\n"; if (isset($errorPatterns['missing_files']) && count($errorPatterns['missing_files']) > 0) { echo "Primary issue: Image files missing from filesystem\n"; echo "Solution: Clean up database or restore missing files\n"; } else { echo "Issue: " . array_keys($errorPatterns)[0] . "\n"; } echo "================================\n"; } // The test passes - we're just diagnosing expect(true)->toBeTrue(); }); // Helper function for making HTTP requests function curl_exec_with_fallback(string $url, array $options = []): mixed { $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => $options['headers'] ?? ['User-Agent: Mozilla/5.0'] ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode !== 200) { throw new Exception("HTTP $httpCode for $url"); } if (isset($options['json']) && $options['json']) { return json_decode($response, true); } return $response; } function curl_exec_with_status(string $url, array $options = []): array { $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => $options['headers'] ?? ['User-Agent: Mozilla/5.0'] ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return [ 'status' => $httpCode, 'content' => $response ]; }