diff --git a/composer.json b/composer.json index 695dbb3..f40887b 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ }, "autoload-dev": { "psr-4": { - "EzSystems\\Tests\\EzPlatformCoreBundle\\": "tests/EzPlatformCoreBundle/bundle/" + "EzSystems\\Tests\\EzPlatformCoreBundle\\": "tests/EzPlatformCoreBundle/bundle/", + "Ibexa\\Platform\\Tests\\Assets\\": "tests/IbexaPlatformAssetsBundle/lib/" } }, "require": { diff --git a/phpunit.xml b/phpunit.xml index 7183ebf..cf667ae 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,11 +6,18 @@ convertWarningsToExceptions="true" beStrictAboutTestsThatDoNotTestAnything="true" colors="true" + bootstrap="vendor/autoload.php" > - - tests/EzPlatformCoreBundle/bundle - + + + tests/EzPlatformCoreBundle/bundle + + + tests/IbexaPlatformAssetsBundle/bundle + tests/IbexaPlatformAssetsBundle/lib + + diff --git a/tests/IbexaPlatformAssetsBundle/lib/Resolver/IconPathResolverTest.php b/tests/IbexaPlatformAssetsBundle/lib/Resolver/IconPathResolverTest.php new file mode 100644 index 0000000..96ef003 --- /dev/null +++ b/tests/IbexaPlatformAssetsBundle/lib/Resolver/IconPathResolverTest.php @@ -0,0 +1,95 @@ +getDefaultConfig(); + + $this->configResolver = $this->getConfigResolverMock($config); + $this->packages = $this->getPackagesMock($config); + } + + /** + * @dataProvider testResolveDataProvider + */ + public function testResolve(string $icon, ?string $set, string $expectedPath): void + { + $iconPathResolver = new IconPathResolver($this->configRes, $packages); + + self::assertEquals($expectedPath, $iconPathResolver->resolve($icon, $set)); + } + + public function testResolveDataProvider() + { + return [ + [ + 'bookmark', + 'my_icon_set', + '/bundles/mybundle/my-icons.svg#bookmark', + ], + [ + 'folder', + null, + '/bundles/mybundle/my-icons.svg#folder', + ], + [ + 'bookmark', + 'my_other_icon_set', + '/bundles/my_other_icon_set/my-other-icons.svg#bookmark', + ], + ]; + } + + private function getDefaultConfig(): array + { + return [ + 'icon_sets' => [ + 'my_icon_set' => '/bundles/mybundle/my-icons.svg', + 'my_other_icon_set' => '/bundles/my_other_icon_set/my-other-icons.svg', + ], + 'default_icon_set' => 'my_icon_set', + ]; + } + + private function getConfigResolverMock(array $config): ConfigResolverInterface + { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturnMap([ + ['assets.icon_sets', null, null, $config['icon_sets']], + ['assets.default_icon_set', null, null, $config['default_icon_set']], + ]); + + return $configResolver; + } + + private function getPackagesMock(array $config): Packages + { + $packages = $this->createMock(Packages::class); + $packages->method('getUrl')->willReturnMap([ + [$config['icon_sets']['my_icon_set'], null, $config['icon_sets']['my_icon_set']], + [$config['icon_sets']['my_other_icon_set'], null, $config['icon_sets']['my_other_icon_set']], + ]); + + return $packages; + } +}