Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for including theme image format config #34

Open
wants to merge 1 commit into
base: 3.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DependencyInjection/CompilerPass/ImageFormatCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions Tests/Application/theme/config/image-formats.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<formats xmlns="http://schemas.sulu.io/media/formats"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/media/formats http://schemas.sulu.io/media/formats-1.1.xsd">

<format key="600x">
<meta>
<title lang="en">Example Image</title>
<title lang="de">Beispielbild</title>
</meta>

<scale x="600"/>
</format>
</formats>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ThemeBundle\Tests\Unit\DependencyInjection\CompilerPass;

use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass\ImageFormatCompilerPass;
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class ImageFormatCompilerPassTest extends TestCase
{
/**
* @var ThemeRepositoryInterface|ObjectProphecy
*/
private $themeRepository;

/**
* @var ContainerBuilder
*/
private $container;

/**
* @var ImageFormatCompilerPass
*/
private $compilerPass;

protected function setUp(): void
{
$this->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);
}
}