Skip to content

Commit

Permalink
Merged branch '1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Sep 30, 2020
2 parents 61f3420 + edfd1ac commit b2f7571
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
*/
namespace eZ\Bundle\EzPublishIOBundle\Tests\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\ChainConfigResolverPass;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ComplexSettings\ComplexSettingParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension;
use eZ\Bundle\EzPublishIOBundle\DependencyInjection\EzPublishIOExtension;
use eZ\Bundle\EzPublishIOBundle\DependencyInjection\ConfigurationFactory;
use eZ\Publish\API\Repository\Tests\Container\Compiler\SetAllServicesPublicPass;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Symfony\Component\Yaml\Yaml;

class EzPublishIOExtensionTest extends AbstractExtensionTestCase
{
private const FIXTURES_DIR = __DIR__ . '/../_fixtures';

protected function getContainerExtensions(): array
{
$extension = new EzPublishIOExtension();
Expand Down Expand Up @@ -60,4 +68,41 @@ public function testParametersWithBinarydataHandler()
['my_binarydata_handler' => ['name' => 'my_binarydata_handler', 'type' => 'flysystem', 'adapter' => 'my_adapter']]
);
}

public function testUrlPrefixConfigurationIsUsedToDecorateUrl(): void
{
$this->container->registerExtension(
new EzPublishCoreExtension(
[
new Parser\IO(new ComplexSettingParser()),
]
)
);
$this->container->prependExtensionConfig(
'ezpublish',
Yaml::parseFile(self::FIXTURES_DIR . '/url_prefix_test_config.yaml')['ezplatform']
);
$this->buildMinimalContainerForUrlPrefixTest();

$decorator = $this->container->get('ezpublish.core.io.prefix_url_decorator');

self::assertEquals(
'http://static.example.com/my/image.png',
$decorator->decorate('my/image.png')
);
}

private function buildMinimalContainerForUrlPrefixTest(): void
{
// unrelated, but needed Container configuration
$this->container->setParameter('kernel.environment', 'dev');
$this->container->setParameter('kernel.debug', true);
$this->container->setParameter('kernel.project_dir', self::FIXTURES_DIR);
$this->container->setParameter('kernel.cache_dir', self::FIXTURES_DIR . '/cache');

$this->container->addCompilerPass(new ChainConfigResolverPass());
$this->container->addCompilerPass(new SetAllServicesPublicPass());

$this->container->compile();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ezplatform:
siteaccess:
list: [site]
default_siteaccess: site
match:
URIElement: 1
system:
default:
io:
url_prefix: 'http://static.example.com/'
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function buildDecorator(string $prefix): UrlDecorator
{
$ioConfigResolverMock = $this->createMock(IOConfigProvider::class);
$ioConfigResolverMock
->method('getLegacyUrlPrefix')
->method('getUrlPrefix')
->willReturn($prefix);

return new AbsolutePrefix($ioConfigResolverMock);
Expand Down
6 changes: 2 additions & 4 deletions eZ/Publish/Core/IO/UrlDecorator/AbsolutePrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@

namespace eZ\Publish\Core\IO\UrlDecorator;

use eZ\Publish\Core\IO\UrlDecorator;

/**
* Prefixes the URI with a string, and makes it absolute.
*/
class AbsolutePrefix extends Prefix implements UrlDecorator
class AbsolutePrefix extends Prefix
{
public function getPrefix(): string
{
$prefix = $this->ioConfigResolver->getLegacyUrlPrefix();
$prefix = $this->ioConfigResolver->getUrlPrefix();

if ($prefix !== '') {
$urlParts = parse_url($prefix);
Expand Down

0 comments on commit b2f7571

Please sign in to comment.