From 1ec9d0f3e1588bdef06a3e8080dc3b3c5ebed7c3 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 31 Oct 2022 21:39:06 +0100 Subject: [PATCH] Fix for including theme image format config --- .../CompilerPass/ImageFormatCompilerPass.php | 5 ++ .../theme/config/image-formats.xml | 14 ++++ .../ImageFormatCompilerPassTest.php | 73 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 Tests/Application/theme/config/image-formats.xml create mode 100644 Tests/Unit/DependencyInjection/CompilerPass/ImageFormatCompilerPassTest.php 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); + } +}