diff --git a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php index 75850a2..e5a6255 100644 --- a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php +++ b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php @@ -34,6 +34,11 @@ protected function getFiles(ContainerBuilder $container) $files = []; foreach ($themeRepository->findAll() as $theme) { + // Add theme config if exists + if (\file_exists($theme->getPath() . '/' . $configPath)) { + $files[] = $theme->getPath() . '/' . $configPath; + } + foreach ($bundles as $bundle) { $bundleReflection = new \ReflectionClass($bundle); $fileName = $bundleReflection->getFileName(); diff --git a/Tests/Application/theme/config/image-formats.xml b/Tests/Application/theme/config/image-formats.xml new file mode 100644 index 0000000..257b1ef --- /dev/null +++ b/Tests/Application/theme/config/image-formats.xml @@ -0,0 +1,14 @@ + + + + + + Example Image + Beispielbild + + + + + diff --git a/Tests/Unit/DependencyInjection/CompilerPass/ImageFormatCompilerPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/ImageFormatCompilerPassTest.php new file mode 100644 index 0000000..2ddc5df --- /dev/null +++ b/Tests/Unit/DependencyInjection/CompilerPass/ImageFormatCompilerPassTest.php @@ -0,0 +1,73 @@ +themeRepository = $this->prophesize(ThemeRepositoryInterface::class); + + $this->container = new ContainerBuilder(); + $this->container->setParameter('sulu_media.format_manager.default_imagine_options', []); + $this->container->setParameter('kernel.bundles', []); + $this->container->set('sylius.repository.theme', $this->themeRepository->reveal()); + + $this->compilerPass = new ImageFormatCompilerPass(); + } + + public function testGetFiles(): void + { + /** @var ThemeInterface|ObjectProphecy $theme */ + $theme = $this->prophesize(ThemeInterface::class); + $theme->getPath() + ->willReturn('Tests/Application/theme') + ->shouldBeCalled(); + + $this->themeRepository + ->findAll() + ->willReturn([$theme->reveal()]) + ->shouldBeCalled(); + + $this->compilerPass->process($this->container); + + $formats = $this->container->getParameter('sulu_media.image.formats'); + + $this->assertCount(1, $formats); + // @phpstan-ignore-next-line + $this->assertArrayHasKey('600x', $formats); + } +}