Use the logo as favicon
favicon.svg, favicon.ico (16/32/48) and apple-touch-icon.png, generated from the same geometry as .brand__mark (resources/favicon/generate.php). Linked from all layouts via one element. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
664088e139
commit
82b352c053
10 files changed
+232
-3
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* The logo as favicon: links in every layout and the files behind them.
|
||||
*/
|
||||
class FaviconTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
use PlenarioTestTrait;
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
||||
|
||||
public function testAllLayoutsLinkTheIcons(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$this->createSlide($poll);
|
||||
|
||||
// default, present and error layout
|
||||
foreach (['/', '/admin/' . $token . '/present', '/does-not-exist'] as $url) {
|
||||
$this->get($url);
|
||||
// Root-relative, no "img/" prefix (static files live directly in webroot/).
|
||||
$this->assertResponseRegExp('#<link rel="icon" href="/favicon\.svg(\?[^"]*)?" type="image/svg\+xml">#', $url);
|
||||
$this->assertResponseRegExp('#<link rel="icon" href="/favicon\.ico(\?[^"]*)?" sizes="32x32">#', $url);
|
||||
$this->assertResponseRegExp('#<link rel="apple-touch-icon" href="/apple-touch-icon\.png(\?[^"]*)?">#', $url);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIconFilesAreValid(): void
|
||||
{
|
||||
$svg = (string)file_get_contents(WWW_ROOT . 'favicon.svg');
|
||||
$this->assertStringContainsString('<svg', $svg);
|
||||
$this->assertNotFalse(simplexml_load_string($svg), 'favicon.svg is not well-formed XML');
|
||||
|
||||
// ICO: reserved 0, type 1, three images; each entry's data starts with the PNG signature.
|
||||
$ico = (string)file_get_contents(WWW_ROOT . 'favicon.ico');
|
||||
$header = unpack('vreserved/vtype/vcount', $ico);
|
||||
$this->assertSame([0, 1, 3], [$header['reserved'], $header['type'], $header['count']]);
|
||||
for ($i = 0; $i < $header['count']; $i++) {
|
||||
$entry = unpack('Voffset', $ico, 6 + 16 * $i + 12);
|
||||
$this->assertSame("\x89PNG", substr($ico, $entry['offset'], 4));
|
||||
}
|
||||
|
||||
$this->assertSame([180, 180], array_slice(getimagesize(WWW_ROOT . 'apple-touch-icon.png'), 0, 2));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user