Story 3.6: optimisation images

This commit is contained in:
2026-02-04 17:17:51 +01:00
parent d3e699d00e
commit d8fd2d9c6c
6 changed files with 98 additions and 53 deletions

20
tests/images.test.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
require_once __DIR__ . '/../includes/functions.php';
function assertTrue($cond, $msg) {
if (!$cond) {
fwrite(STDERR, $msg . PHP_EOL);
exit(1);
}
}
$htmlLazy = projectImage('ecommerce-xyz-thumb.webp', 'Test', 400, 225, true);
assertTrue(strpos($htmlLazy, 'loading="lazy"') !== false, 'lazy attr missing');
assertTrue(strpos($htmlLazy, 'type="image/webp"') !== false, 'webp source missing');
assertTrue(strpos($htmlLazy, 'width="400"') !== false, 'width missing');
assertTrue(strpos($htmlLazy, 'height="225"') !== false, 'height missing');
$htmlNoLazy = projectImage('ecommerce-xyz-thumb.webp', 'Test', 400, 225, false);
assertTrue(strpos($htmlNoLazy, 'loading="lazy"') === false, 'lazy should be absent');
fwrite(STDOUT, "OK\n");