folderweb/devel/tests/helpers/extract_title.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

49 lines
1.2 KiB
PHP

--TEST--
extractTitle: extracts title from # heading in .md or <h1> in .html
--FILE--
<?php
require '/var/www/app/constants.php';
require '/var/www/app/hooks.php';
require '/var/www/app/content.php';
require '/var/www/app/helpers.php';
$dir = sys_get_temp_dir() . '/phpt_title_' . getmypid();
mkdir($dir);
// No content files
echo (extractTitle($dir) ?? 'null') . "\n";
// Markdown with # heading
file_put_contents("$dir/index.md", "# My Great Post\n\nSome body text.");
echo extractTitle($dir) . "\n";
unlink("$dir/index.md");
// Markdown heading with extra whitespace
file_put_contents("$dir/index.md", "# Spaced Title \n\nBody.");
echo extractTitle($dir) . "\n";
unlink("$dir/index.md");
// HTML with <h1>
file_put_contents("$dir/index.html", "<h1>HTML Title</h1><p>Body</p>");
echo extractTitle($dir) . "\n";
unlink("$dir/index.html");
// HTML with attributes on h1
file_put_contents("$dir/index.html", '<h1 class="main">Styled Title</h1>');
echo extractTitle($dir) . "\n";
unlink("$dir/index.html");
// Markdown without heading
file_put_contents("$dir/index.md", "Just a paragraph, no heading.");
echo (extractTitle($dir) ?? 'null') . "\n";
unlink("$dir/index.md");
rmdir($dir);
?>
--EXPECT--
null
My Great Post
Spaced Title
HTML Title
Styled Title
null