folderweb/devel/tests/helpers/find_page_js.phpt
Ruben 449e6f8e03 Update framework testing infrastructure and standards
- Add phpt test runner and suite for app functions
- Introduce testing workflow to AGENT.md
- Add tests for cache, content, context, helpers, hooks, plugins,
  rendering
- Mount tests directory in dev container
2026-03-17 12:51:07 +01:00

36 lines
934 B
PHP

--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