|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Test script for finfo_file() with remote URLs |
| 4 | + * This tests the fix for the bug where finfo_file() returned false for remote URLs |
| 5 | + */ |
| 6 | + |
| 7 | +echo "Testing finfo_file() with remote URLs\n"; |
| 8 | +echo str_repeat("=", 50) . "\n\n"; |
| 9 | + |
| 10 | +$finfo = finfo_open(); |
| 11 | + |
| 12 | +// Check if HTTPS wrapper is available |
| 13 | +$wrappers = stream_get_wrappers(); |
| 14 | +$hasHttps = in_array('https', $wrappers); |
| 15 | + |
| 16 | +// Test 1: Remote URL (the original failing case) |
| 17 | +echo "Test 1: Remote URL (https://example.com)\n"; |
| 18 | +if (!$hasHttps) { |
| 19 | + echo "⚠ SKIPPED: HTTPS wrapper not available (OpenSSL support required)\n"; |
| 20 | + echo " To enable HTTPS support, rebuild PHP with: ./configure --with-openssl\n\n"; |
| 21 | +} else { |
| 22 | + $result = finfo_file($finfo, "https://example.com"); |
| 23 | + if ($result === false) { |
| 24 | + echo "❌ FAILED: finfo_file() returned false (this is the bug we're fixing)\n"; |
| 25 | + } else { |
| 26 | + echo "✅ PASSED: finfo_file() returned: " . var_export($result, true) . "\n"; |
| 27 | + // Expected something like: "HTML document, ASCII text, with very long lines (512)" |
| 28 | + if (stripos($result, "HTML") !== false || stripos($result, "text") !== false) { |
| 29 | + echo " ✓ Result contains expected content type indicators\n"; |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | +echo "\n"; |
| 34 | + |
| 35 | +// Test 2: Local file (should still work) |
| 36 | +echo "Test 2: Local file (this script itself)\n"; |
| 37 | +$result = finfo_file($finfo, __FILE__); |
| 38 | +if ($result === false) { |
| 39 | + echo "❌ FAILED: finfo_file() returned false for local file\n"; |
| 40 | +} else { |
| 41 | + echo "✅ PASSED: finfo_file() returned: " . var_export($result, true) . "\n"; |
| 42 | +} |
| 43 | +echo "\n"; |
| 44 | + |
| 45 | +// Test 3: Directory (should still work and return "directory") |
| 46 | +echo "Test 3: Directory\n"; |
| 47 | +$result = finfo_file($finfo, __DIR__); |
| 48 | +if ($result === false) { |
| 49 | + echo "❌ FAILED: finfo_file() returned false for directory\n"; |
| 50 | +} else { |
| 51 | + echo "✅ PASSED: finfo_file() returned: " . var_export($result, true) . "\n"; |
| 52 | + if ($result === "directory") { |
| 53 | + echo " ✓ Correctly identified as directory\n"; |
| 54 | + } else { |
| 55 | + echo " ⚠ WARNING: Expected 'directory', got something else\n"; |
| 56 | + } |
| 57 | +} |
| 58 | +echo "\n"; |
| 59 | + |
| 60 | +// Test 4: Another remote URL (different domain) |
| 61 | +echo "Test 4: Another remote URL (http://httpbin.org/html)\n"; |
| 62 | +$result = finfo_file($finfo, "http://httpbin.org/html"); |
| 63 | +if ($result === false) { |
| 64 | + echo "❌ FAILED: finfo_file() returned false for remote URL\n"; |
| 65 | +} else { |
| 66 | + echo "✅ PASSED: finfo_file() returned: " . var_export($result, true) . "\n"; |
| 67 | +} |
| 68 | +echo "\n"; |
| 69 | + |
| 70 | +echo str_repeat("=", 50) . "\n"; |
| 71 | +echo "Test completed!\n"; |
| 72 | + |
0 commit comments