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
47
devel/tests/content/find_all_content_files.phpt
Normal file
47
devel/tests/content/find_all_content_files.phpt
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
--TEST--
|
||||
findAllContentFiles: returns sorted content file paths, ignores non-content files and index.php
|
||||
--FILE--
|
||||
<?php
|
||||
require '/var/www/app/constants.php';
|
||||
require '/var/www/app/hooks.php';
|
||||
require '/var/www/app/content.php';
|
||||
|
||||
$dir = sys_get_temp_dir() . '/phpt_content_' . getmypid();
|
||||
mkdir($dir);
|
||||
|
||||
// Non-existent directory
|
||||
echo count(findAllContentFiles($dir . '/nope')) . "\n";
|
||||
|
||||
// Empty directory
|
||||
echo count(findAllContentFiles($dir)) . "\n";
|
||||
|
||||
// Content files
|
||||
file_put_contents("$dir/page.md", '# Hello');
|
||||
file_put_contents("$dir/extra.html", '<p>Hi</p>');
|
||||
file_put_contents("$dir/script.php", '<?php echo "hi";');
|
||||
|
||||
// Non-content files are excluded
|
||||
file_put_contents("$dir/styles.css", 'body {}');
|
||||
file_put_contents("$dir/image.jpg", '');
|
||||
|
||||
// index.php is always excluded
|
||||
file_put_contents("$dir/index.php", '<?php');
|
||||
|
||||
$files = findAllContentFiles($dir);
|
||||
echo count($files) . "\n";
|
||||
|
||||
// Results are full paths, sorted by filename (natural order)
|
||||
foreach ($files as $f) {
|
||||
echo basename($f) . "\n";
|
||||
}
|
||||
|
||||
array_map('unlink', glob("$dir/*"));
|
||||
rmdir($dir);
|
||||
?>
|
||||
--EXPECT--
|
||||
0
|
||||
0
|
||||
3
|
||||
extra.html
|
||||
page.md
|
||||
script.php
|
||||
44
devel/tests/content/load_metadata.phpt
Normal file
44
devel/tests/content/load_metadata.phpt
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
--TEST--
|
||||
loadMetadata: parses metadata.ini, returns null when absent
|
||||
--FILE--
|
||||
<?php
|
||||
require '/var/www/app/hooks.php';
|
||||
require '/var/www/app/content.php';
|
||||
|
||||
$dir = sys_get_temp_dir() . '/phpt_meta_' . getmypid();
|
||||
mkdir($dir);
|
||||
|
||||
// No metadata file
|
||||
echo (loadMetadata($dir) ?? 'null') . "\n";
|
||||
|
||||
// Basic key-value metadata
|
||||
file_put_contents("$dir/metadata.ini", "title = My Page\nsummary = A summary\nmenu = true\n");
|
||||
$meta = loadMetadata($dir);
|
||||
echo $meta['title'] . "\n";
|
||||
echo $meta['summary'] . "\n";
|
||||
echo $meta['menu'] . "\n";
|
||||
|
||||
// _raw is always present
|
||||
echo isset($meta['_raw']) ? 'raw present' : 'raw missing';
|
||||
echo "\n";
|
||||
|
||||
// Sections are in _raw but not in base metadata
|
||||
file_put_contents("$dir/metadata.ini", "[en]\ntitle = English Title\n\n[fr]\ntitle = French Title\n");
|
||||
$meta = loadMetadata($dir);
|
||||
echo isset($meta['en']) ? 'section leaked' : 'section contained';
|
||||
echo "\n";
|
||||
echo $meta['_raw']['en']['title'] . "\n";
|
||||
echo $meta['_raw']['fr']['title'] . "\n";
|
||||
|
||||
array_map('unlink', glob("$dir/*"));
|
||||
rmdir($dir);
|
||||
?>
|
||||
--EXPECT--
|
||||
null
|
||||
My Page
|
||||
A summary
|
||||
1
|
||||
raw present
|
||||
section contained
|
||||
English Title
|
||||
French Title
|
||||
48
devel/tests/content/resolve_slug_to_folder.phpt
Normal file
48
devel/tests/content/resolve_slug_to_folder.phpt
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
--TEST--
|
||||
resolveSlugToFolder: resolves URL slug to actual folder name, supports metadata slug override
|
||||
--FILE--
|
||||
<?php
|
||||
require '/var/www/app/hooks.php';
|
||||
require '/var/www/app/content.php';
|
||||
|
||||
$parent = sys_get_temp_dir() . '/phpt_slug_' . getmypid();
|
||||
mkdir($parent);
|
||||
|
||||
// Non-existent parent directory
|
||||
echo (resolveSlugToFolder($parent . '/nope', 'anything') ?? 'null') . "\n";
|
||||
|
||||
// Folder name matches slug directly
|
||||
mkdir("$parent/my-post");
|
||||
echo resolveSlugToFolder($parent, 'my-post') . "\n";
|
||||
|
||||
// Slug not found
|
||||
echo (resolveSlugToFolder($parent, 'missing') ?? 'null') . "\n";
|
||||
|
||||
// Metadata slug overrides folder name
|
||||
mkdir("$parent/2024-01-15-article");
|
||||
file_put_contents("$parent/2024-01-15-article/metadata.ini", "slug = article\n");
|
||||
echo resolveSlugToFolder($parent, 'article') . "\n";
|
||||
|
||||
// Original folder name still works when no slug conflicts
|
||||
echo resolveSlugToFolder($parent, '2024-01-15-article') . "\n";
|
||||
|
||||
// Metadata slug takes precedence over folder with that name
|
||||
mkdir("$parent/other");
|
||||
file_put_contents("$parent/other/metadata.ini", "slug = my-post\n");
|
||||
// 'my-post' folder exists AND 'other' has slug=my-post — folder name wins (first match)
|
||||
echo resolveSlugToFolder($parent, 'my-post') . "\n";
|
||||
|
||||
array_map('unlink', glob("$parent/2024-01-15-article/*"));
|
||||
rmdir("$parent/2024-01-15-article");
|
||||
array_map('unlink', glob("$parent/other/*"));
|
||||
rmdir("$parent/other");
|
||||
rmdir("$parent/my-post");
|
||||
rmdir($parent);
|
||||
?>
|
||||
--EXPECT--
|
||||
null
|
||||
my-post
|
||||
null
|
||||
2024-01-15-article
|
||||
2024-01-15-article
|
||||
my-post
|
||||
Loading…
Add table
Add a link
Reference in a new issue