Add breadcrumbs function, docs and tests

This commit is contained in:
Ruben 2026-05-20 23:23:01 +02:00
parent 4448798bf5
commit 2bdb432a9f
12 changed files with 451 additions and 0 deletions

View file

@ -0,0 +1,39 @@
--TEST--
buildBreadcrumbs: skips non-existent directories gracefully
--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 only level 1
$tempBase = sys_get_temp_dir() . '/phpt_' . getmypid();
$tempContent = $tempBase . '/content';
$tempLevel1 = $tempContent . '/nyheter';
mkdir($tempLevel1, 0777, true);
file_put_contents($tempLevel1 . '/metadata.ini', "title = Nyheter\n");
// Request path has middle directories that don't exist
$ctx = new Context(
contentDir: $tempContent,
templates: new Templates('/tmp/base.php', '/tmp/page.php', '/tmp/list.php'),
requestPath: 'nyheter/nonexistent/artikkel',
hasTrailingSlash: false
);
$result = buildBreadcrumbs($ctx);
// Only nyheter exists, so only 1 breadcrumb
echo count($result) . "\n";
// Cleanup
unlink($tempLevel1 . '/metadata.ini');
rmdir($tempLevel1);
rmdir($tempContent);
rmdir($tempBase);
?>
--EXPECT--
1