fix(issue-80): show all 13 house images + 3D floor plans
All checks were successful
Lint / PHP Syntax Check (push) Successful in 57s
PHPUnit / PHP Unit Tests (push) Successful in 1m7s
Lint / HTML Lint (htmlhint) (push) Successful in 1m38s
Lint / CSS Lint (stylelint) (push) Successful in 1m42s
Lint / PHP Syntax Check (pull_request) Successful in 58s
PHPUnit / PHP Unit Tests (pull_request) Successful in 1m3s
Lint / HTML Lint (htmlhint) (pull_request) Successful in 1m36s
Lint / CSS Lint (stylelint) (pull_request) Successful in 1m41s

This commit is contained in:
Hermes
2026-06-05 22:28:04 +00:00
parent 5781b5b5f0
commit db83e09a3a
6 changed files with 250 additions and 4 deletions

View File

@@ -0,0 +1,178 @@
<?php
declare(strict_types=1);
namespace Tests\Views;
use PHPUnit\Framework\TestCase;
/**
* Regression test for issue #80: all house images in public/bilder/ must be
* referenced from the home view. Catches drift when new photos are added to
* disk but not yet wired into the gallery or floor-plan map.
*/
final class HomeGalleryInventoryTest extends TestCase
{
private const VIEW_PATH = __DIR__ . '/../../app/views/home/index.php';
private const BILDER_DIR = __DIR__ . '/../../public/bilder';
/** @var list<string> Files that may exist on disk but are intentionally NOT shown on the page. */
private const ALLOWED_UNUSED = [
// Hero / page background uses a .webp variant; the .png in bilder/ is the
// gallery source. Hero-bg is referenced separately in the <header>.
'favicon/',
// -small.* variants are served as thumb hints by JS lazy-load optimization.
'*-small.*',
];
public function testAllBilderFilesAreReferencedInHomeView(): void
{
$view = file_get_contents(self::VIEW_PATH);
self::assertNotFalse($view, 'Could not read home view');
$diskFiles = $this->listBilderFiles();
self::assertNotEmpty($diskFiles, 'No files found in public/bilder/');
// Group files by base name (filename without extension) so the
// .jpg/.png/.jpeg source + auto-generated .webp variant count as ONE image.
$groups = [];
foreach ($diskFiles as $relPath) {
if ($this->isAllowedUnused($relPath)) {
continue;
}
$groups[$this->baseOf($relPath)][] = $relPath;
}
$missing = [];
foreach ($groups as $base => $variants) {
$hit = false;
foreach ($variants as $v) {
// View may reference raw or with leading slash.
if (str_contains($view, $v) || str_contains($view, '/' . ltrim($v, '/'))) {
$hit = true;
break;
}
}
if (!$hit) {
$missing[] = $base . ' (' . implode(', ', $variants) . ')';
}
}
self::assertSame(
[],
$missing,
sprintf(
"These image groups exist in public/bilder/ but are NOT referenced anywhere in the home view:\n - %s\n\nFix: add them to \$gridItems (gallery) or \$floorImageMap / \$floorImageMapExtra (floor plans), and add the matching Locale keys.",
implode("\n - ", $missing),
)
);
}
public function testGalleryContainsAllRequiredImages(): void
{
$view = file_get_contents(self::VIEW_PATH);
self::assertNotFalse($view, 'Could not read home view');
$required = [
// Bathrooms (3 new ones in addition to the existing Bad.jpg)
'bilder/Bad.jpg',
'bilder/Bad-2.jpeg',
'bilder/Bad-3.jpeg',
'bilder/Bad-4.jpeg',
// Kids room extras
'bilder/Kinderzimmer.png',
// Floor plans 2D
'bilder/grundrisse/EG.png',
'bilder/grundrisse/OG 1 2.png',
'bilder/grundrisse/OG 2 grundriss.png',
'bilder/grundrisse/Dachboden unten.png',
// Floor plans 3D / alternate
'bilder/grundrisse/EG 3D.png',
'bilder/grundrisse/OG 1 3D.png',
'bilder/grundrisse/OG 2 3D.png',
'bilder/grundrisse/Dachboden unten 2.png',
];
$missing = array_values(array_filter($required, static fn (string $img) => !str_contains($view, $img)));
self::assertSame(
[],
$missing,
sprintf(
"Required images missing from home view:\n - %s",
implode("\n - ", $missing),
)
);
}
public function testFloorPlanMapsCoverAllFloors(): void
{
$view = file_get_contents(self::VIEW_PATH);
self::assertNotFalse($view, 'Could not read home view');
// Each floor in the $floors array must have an entry in BOTH maps
// (primary 2D + extra 3D/alternate) so the floor body renders both.
foreach (['eg', 'og1', 'og2', 'attic'] as $floorId) {
self::assertStringContainsString(
"'{$floorId}'",
$view,
"Floor '{$floorId}' not declared in home view",
);
}
}
/**
* @return list<string> relative paths (forward-slash, e.g. "grundrisse/EG.png")
*/
private function listBilderFiles(): array
{
$files = [];
$iter = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(self::BILDER_DIR, \FilesystemIterator::SKIP_DOTS),
);
foreach ($iter as $file) {
if (!$file->isFile()) {
continue;
}
$rel = substr($file->getPathname(), strlen(self::BILDER_DIR) + 1);
$rel = str_replace(DIRECTORY_SEPARATOR, '/', $rel);
$files[] = $rel;
}
sort($files);
return $files;
}
private function isAllowedUnused(string $relPath): bool
{
foreach (self::ALLOWED_UNUSED as $pattern) {
if (str_ends_with($pattern, '/')) {
// Directory prefix
if (str_starts_with($relPath, $pattern)) {
return true;
}
} else {
// Glob-style match (only `*` supported, for `-small.*` variants)
$regex = '#^' . str_replace('\\*', '.*', preg_quote($pattern, '#')) . '$#';
if (preg_match($regex, $relPath) === 1) {
return true;
}
}
}
return false;
}
/**
* Base name = path minus extension. So "grundrisse/EG 3D.png" → "grundrisse/EG 3D",
* and "Küche 1.jpg" → "Küche 1". Used to group source + auto-generated variants.
*/
private function baseOf(string $relPath): string
{
$dot = strrpos($relPath, '.');
if ($dot === false || $dot === 0) {
return $relPath;
}
return substr($relPath, 0, $dot);
}
}