50 lines
1.2 KiB
Text
50 lines
1.2 KiB
Text
|
|
--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
|