folderweb/devel/tests/helpers/build_breadcrumbs_extract_title_from_content.phpt

51 lines
1.4 KiB
PHP

--TEST--
buildBreadcrumbs: extracts title from content file when metadata has no title
--FILE--
<?php
require '/var/www/app/context.php';
require '/var/www/app/hooks.php';
require '/var/www/app/constants.php';
require '/var/www/app/helpers.php';
require '/var/www/app/content.php';
// Create temp directory structure with no metadata title
$tempBase = sys_get_temp_dir() . '/phpt_' . getmypid();
$tempContent = $tempBase . '/content';
$tempLevel1 = $tempContent . '/nyheter';
$tempLevel2 = $tempLevel1 . '/riksrevisjonen';
mkdir($tempLevel1, 0777, true);
mkdir($tempLevel2, 0777, true);
// Create content file with h1 title
file_put_contents($tempLevel2 . '/index.md', "# Riksrevisjonen\n\nSome content here.");
// Metadata without title
file_put_contents($tempLevel2 . '/metadata.ini', "slug = riksrevisjonen\n");
$ctx = new Context(
contentDir: $tempContent,
templates: new Templates('/tmp/base.php', '/tmp/page.php', '/tmp/list.php'),
requestPath: 'nyheter/riksrevisjonen/artikkel',
hasTrailingSlash: false
);
$result = buildBreadcrumbs($ctx);
// Output count and titles
echo count($result) . "\n";
echo $result[0]['title'] . "\n";
echo $result[1]['title'] . "\n";
// Cleanup
unlink($tempLevel2 . '/metadata.ini');
unlink($tempLevel2 . '/index.md');
rmdir($tempLevel2);
rmdir($tempLevel1);
rmdir($tempContent);
rmdir($tempBase);
?>
--EXPECT--
2
Nyheter
Riksrevisjonen