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
This commit is contained in:
parent
33943a907b
commit
449e6f8e03
22 changed files with 909 additions and 7 deletions
49
devel/tests/cache/build_cache_key.phpt
vendored
Normal file
49
devel/tests/cache/build_cache_key.phpt
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
--TEST--
|
||||
buildCacheKey: returns md5 string, varies by path and langPrefix
|
||||
--FILE--
|
||||
<?php
|
||||
require '/var/www/app/cache.php';
|
||||
|
||||
$dir = sys_get_temp_dir() . '/phpt_cachekey_' . getmypid();
|
||||
mkdir($dir);
|
||||
$file = "$dir/page.md";
|
||||
file_put_contents($file, '# Hello');
|
||||
|
||||
// Returns a 32-char hex string
|
||||
$key = buildCacheKey($file);
|
||||
echo (bool)preg_match('/^[0-9a-f]{32}$/', $key) ? 'valid md5' : 'invalid';
|
||||
echo "\n";
|
||||
|
||||
// Same inputs produce same key
|
||||
echo ($key === buildCacheKey($file)) ? 'stable' : 'unstable';
|
||||
echo "\n";
|
||||
|
||||
// Different langPrefix produces different key
|
||||
$keyFr = buildCacheKey($file, '/fr');
|
||||
echo ($key !== $keyFr) ? 'prefix differs' : 'prefix same';
|
||||
echo "\n";
|
||||
|
||||
// Different file path produces different key
|
||||
$file2 = "$dir/other.md";
|
||||
file_put_contents($file2, '# Other');
|
||||
$key2 = buildCacheKey($file2);
|
||||
echo ($key !== $key2) ? 'path differs' : 'path same';
|
||||
echo "\n";
|
||||
|
||||
// Adding metadata.ini changes the key
|
||||
file_put_contents("$dir/metadata.ini", "title = Test\n");
|
||||
$keyWithMeta = buildCacheKey($file);
|
||||
echo ($key !== $keyWithMeta) ? 'meta invalidates' : 'meta ignored';
|
||||
echo "\n";
|
||||
|
||||
unlink($file);
|
||||
unlink($file2);
|
||||
unlink("$dir/metadata.ini");
|
||||
rmdir($dir);
|
||||
?>
|
||||
--EXPECT--
|
||||
valid md5
|
||||
stable
|
||||
prefix differs
|
||||
path differs
|
||||
meta invalidates
|
||||
36
devel/tests/cache/get_set_cached_markdown.phpt
vendored
Normal file
36
devel/tests/cache/get_set_cached_markdown.phpt
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
--TEST--
|
||||
getCachedMarkdown / setCachedMarkdown: store and retrieve rendered HTML by file key
|
||||
--FILE--
|
||||
<?php
|
||||
require '/var/www/app/cache.php';
|
||||
|
||||
$dir = sys_get_temp_dir() . '/phpt_mdcache_' . getmypid();
|
||||
mkdir($dir);
|
||||
$file = "$dir/post.md";
|
||||
file_put_contents($file, '# Hello');
|
||||
|
||||
// Nothing cached yet
|
||||
echo (getCachedMarkdown($file) ?? 'null') . "\n";
|
||||
|
||||
// Store and retrieve
|
||||
setCachedMarkdown($file, '<h1>Hello</h1>');
|
||||
echo getCachedMarkdown($file) . "\n";
|
||||
|
||||
// langPrefix produces a separate cache entry
|
||||
echo (getCachedMarkdown($file, '/fr') ?? 'null') . "\n";
|
||||
|
||||
setCachedMarkdown($file, '<h1>Bonjour</h1>', '/fr');
|
||||
echo getCachedMarkdown($file, '/fr') . "\n";
|
||||
|
||||
// Default key is unaffected
|
||||
echo getCachedMarkdown($file) . "\n";
|
||||
|
||||
unlink($file);
|
||||
rmdir($dir);
|
||||
?>
|
||||
--EXPECT--
|
||||
null
|
||||
<h1>Hello</h1>
|
||||
null
|
||||
<h1>Bonjour</h1>
|
||||
<h1>Hello</h1>
|
||||
Loading…
Add table
Add a link
Reference in a new issue