|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\UX\Icons\Tests\Unit\Registry; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\UX\Icons\Registry\LocalSvgIconRegistry; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Kevin Bond <[email protected]> |
| 19 | + */ |
| 20 | +final class LocalSvgIconRegistryTest extends TestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @dataProvider validSvgProvider |
| 24 | + */ |
| 25 | + public function testValidSvgs(string $name, array $expectedAttributes, string $expectedContent): void |
| 26 | + { |
| 27 | + [$content, $attributes] = $this->registry()->get($name); |
| 28 | + |
| 29 | + $this->assertSame($expectedContent, $content); |
| 30 | + $this->assertSame($expectedAttributes, $attributes); |
| 31 | + } |
| 32 | + |
| 33 | + public static function validSvgProvider(): iterable |
| 34 | + { |
| 35 | + 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>']; |
| 36 | + 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>']; |
| 37 | + 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>']; |
| 38 | + 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>']; |
| 39 | + 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>']; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @dataProvider invalidSvgProvider |
| 44 | + */ |
| 45 | + public function testInvalidSvgs(string $name): void |
| 46 | + { |
| 47 | + $this->expectException(\RuntimeException::class); |
| 48 | + |
| 49 | + $this->registry()->get($name); |
| 50 | + } |
| 51 | + |
| 52 | + public static function invalidSvgProvider(): iterable |
| 53 | + { |
| 54 | + yield ['invalid1']; |
| 55 | + yield ['invalid2']; |
| 56 | + yield ['invalid3']; |
| 57 | + yield ['invalid4']; |
| 58 | + } |
| 59 | + |
| 60 | + private function registry(): LocalSvgIconRegistry |
| 61 | + { |
| 62 | + return new LocalSvgIconRegistry(__DIR__.'/../../Fixtures/svg'); |
| 63 | + } |
| 64 | +} |
0 commit comments