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
. '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 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); } }