` and viewBox. */ function symbolGeometry(string $file): string { $svg = trim((string) file_get_contents(__DIR__.'/../../../resources/svg/symbols/'.$file.'.svg')); return substr($svg, (int) strpos($svg, '><') + 1); } it('draws a symbol inline, hidden from screen readers, 24px by default', function () { $this->blade('') ->assertSee('class="shrink-0 size-6"', false) ->assertSee('aria-hidden="true"', false) ->assertSee('fill="currentColor"', false) ->assertSee('viewBox="0 -960 960 960"', false); }); it('leaves the size to a caller who gives one', function () { $this->blade('') ->assertSee('class="shrink-0 size-4 text-primary"', false) ->assertDontSee('size-6', false); }); it('names the icon for a screen reader when it carries the meaning alone', function () { $this->blade('') ->assertSee('aria-label="Password protected"', false) ->assertSee('role="img"', false) ->assertDontSee('aria-hidden', false); }); it('draws the filled symbol when asked', function () { $outlined = (string) $this->blade(''); $filled = (string) $this->blade(''); expect($filled)->not->toBe($outlined) ->and($filled)->toContain('blade(''); $dense = (string) $this->blade(''); expect($dense)->not->toBe($standard) ->and($dense)->toContain('class="shrink-0 size-5"') ->and($dense)->toContain('fill="currentColor"') ->and($dense)->toContain(symbolGeometry('outlined-20/home')); }); it('combines the filled state with the 20 cut', function () { $outlined = (string) $this->blade(''); $filled = (string) $this->blade(''); expect($filled)->not->toBe($outlined) ->and($outlined)->toContain(symbolGeometry('outlined-20/favorite')) ->and($filled)->toContain(symbolGeometry('filled-20/favorite')) ->and($filled)->not->toContain(symbolGeometry('filled/favorite')); }); it('falls back to the 24 cut for an optical size it does not ship', function () { $standard = (string) $this->blade(''); expect((string) $this->blade(''))->toBe($standard) ->and((string) $this->blade(''))->toBe($standard) ->and((string) $this->blade(''))->toBe($standard); }); it('refuses a name that is not a symbol', function () { expect(fn () => $this->blade('')) ->toThrow(ViewException::class, 'There is no Material Symbol named [not_a_symbol_at_all].'); }); it('points a Heroicon name at the symbol catalogue', function () { expect(fn () => $this->blade('')) ->toThrow(ViewException::class, 'is not a Material Symbol name'); }); it('ships every symbol outlined and filled in both cuts, painted in the text colour', function () { $symbols = SvgFile::symbolNames(); expect(count($symbols))->toBeGreaterThan(4000); foreach (['filled', 'outlined-20', 'filled-20'] as $folder) { $names = array_map(fn (string $file): string => basename($file, '.svg'), glob(__DIR__."/../../../resources/svg/symbols/{$folder}/*.svg")); expect($names)->toEqual($symbols, "{$folder} holds a different catalogue than outlined"); } foreach (['outlined', 'filled', 'outlined-20', 'filled-20'] as $folder) { foreach (['home', 'search', 'cloud_upload', 'content_copy', 'delete'] as $name) { expect(file_get_contents(__DIR__."/../../../resources/svg/symbols/{$folder}/{$name}.svg")) ->toStartWith('not->toContain('width='); } } }); it('draws the two cuts from different geometry, not the same file scaled', function () { foreach (['home', 'search', 'cloud_upload', 'content_copy', 'delete'] as $name) { expect(symbolGeometry("outlined-20/{$name}"))->not->toBe(symbolGeometry("outlined/{$name}")) ->and(symbolGeometry("filled-20/{$name}"))->not->toBe(symbolGeometry("filled/{$name}")); } });