|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\UX\Icons\Tests\Unit\Registry; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Symfony\UX\Icons\Registry\LocalSvgIconRegistry; |
| 7 | + |
| 8 | +/** |
| 9 | + * @author Kevin Bond <[email protected]> |
| 10 | + */ |
| 11 | +final class LocalSvgIconRegistryTest extends TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @test |
| 15 | + * @dataProvider validSvgProvider |
| 16 | + */ |
| 17 | + public function valid_svgs(string $name, array $expectedAttributes, string $expectedContent): void |
| 18 | + { |
| 19 | + [$content, $attributes] = $this->registry()->get($name); |
| 20 | + |
| 21 | + $this->assertSame($expectedContent, $content); |
| 22 | + $this->assertSame($expectedAttributes, $attributes); |
| 23 | + } |
| 24 | + |
| 25 | + public static function validSvgProvider(): iterable |
| 26 | + { |
| 27 | + yield ['valid1', ['viewBox' => '0 0 24 24'], '<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path>']; |
| 28 | + yield ['valid2', ['viewBox' => '0 0 24 24'], '<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path>']; |
| 29 | + yield ['valid3', ['viewBox' => '0 0 24 24'], '<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path>']; |
| 30 | + yield ['valid4', ['viewBox' => '0 0 24 24'], '<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path><path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path>']; |
| 31 | + yield ['valid5', ['viewBox' => '0 0 24 24'], '<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path><g><path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd"></path></g>']; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @test |
| 36 | + * @dataProvider invalidSvgProvider |
| 37 | + */ |
| 38 | + public function invalid_svgs(string $name): void |
| 39 | + { |
| 40 | + $this->expectException(\RuntimeException::class); |
| 41 | + |
| 42 | + $this->registry()->get($name); |
| 43 | + } |
| 44 | + |
| 45 | + public static function invalidSvgProvider(): iterable |
| 46 | + { |
| 47 | + yield ['invalid1']; |
| 48 | + yield ['invalid2']; |
| 49 | + yield ['invalid3']; |
| 50 | + } |
| 51 | + |
| 52 | + private function registry(): LocalSvgIconRegistry |
| 53 | + { |
| 54 | + return new LocalSvgIconRegistry(__DIR__.'/../../Fixtures/svg'); |
| 55 | + } |
| 56 | +} |
0 commit comments