49 lines
1.5 KiB
Text
49 lines
1.5 KiB
Text
|
|
--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
|