folderweb/devel/tests/helpers/find_page_js.phpt

37 lines
934 B
Text
Raw Normal View History

--TEST--
findPageJs: returns URL and hash for script.js, null when absent
--FILE--
<?php
require '/var/www/app/helpers.php';
$contentDir = sys_get_temp_dir() . '/phpt_js_' . getmypid();
$pageDir = "$contentDir/section/page";
mkdir($pageDir, 0777, true);
// No script.js
echo (findPageJs($pageDir, $contentDir) ?? 'null') . "\n";
// Add script.js
file_put_contents("$pageDir/script.js", 'console.log("hi");');
$result = findPageJs($pageDir, $contentDir);
echo $result['url'] . "\n";
echo ($result['hash'] === md5_file("$pageDir/script.js") ? 'hash ok' : 'hash mismatch') . "\n";
// Root-level page (no subpath)
$rootJs = "$contentDir/script.js";
file_put_contents($rootJs, '');
$result = findPageJs($contentDir, $contentDir);
echo $result['url'] . "\n";
unlink("$pageDir/script.js");
unlink($rootJs);
rmdir($pageDir);
rmdir("$contentDir/section");
rmdir($contentDir);
?>
--EXPECT--
null
/section/page/script.js
hash ok
/script.js