|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * File containing the EzPublishCoreExtensionTest class. |
| 4 | + * |
| 5 | + * @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved. |
| 6 | + * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 |
| 7 | + * @version //autogentag// |
| 8 | + */ |
| 9 | + |
| 10 | +namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection; |
| 11 | + |
| 12 | +use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension; |
| 13 | +use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
| 14 | +use Symfony\Component\DependencyInjection\Definition; |
| 15 | +use Symfony\Component\Yaml\Yaml; |
| 16 | + |
| 17 | +class EzPublishCoreExtensionTest extends AbstractExtensionTestCase |
| 18 | +{ |
| 19 | + private $minimalConfig = array(); |
| 20 | + |
| 21 | + private $siteaccessConfig = array(); |
| 22 | + |
| 23 | + protected function setUp() |
| 24 | + { |
| 25 | + parent::setUp(); |
| 26 | + $this->siteaccessConfig = array( |
| 27 | + 'siteaccess' => array( |
| 28 | + 'default_siteaccess' => 'ezdemo_site', |
| 29 | + 'list' => array( 'ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin' ), |
| 30 | + 'groups' => array( |
| 31 | + 'ezdemo_group' => array( 'ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin' ), |
| 32 | + 'ezdemo_frontend_group' => array( 'ezdemo_site', 'eng', 'fre' ), |
| 33 | + ), |
| 34 | + 'match' => array( |
| 35 | + 'URILElement' => 1, |
| 36 | + 'Map\URI' => array( 'the_front' => 'ezdemo_site', 'the_back' => 'ezdemo_site_admin' ) |
| 37 | + ) |
| 38 | + ) |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + protected function getContainerExtensions() |
| 43 | + { |
| 44 | + return array( new EzPublishCoreExtension() ); |
| 45 | + } |
| 46 | + |
| 47 | + protected function getMinimalConfiguration() |
| 48 | + { |
| 49 | + return $this->minimalConfig = Yaml::parse( __DIR__ . '/Fixtures/ezpublish_minimal_no_siteaccess.yml' ); |
| 50 | + } |
| 51 | + |
| 52 | + public function testSiteAccessConfiguration() |
| 53 | + { |
| 54 | + $this->load( $this->siteaccessConfig ); |
| 55 | + $this->assertContainerBuilderHasParameter( |
| 56 | + 'ezpublish.siteaccess.list', |
| 57 | + $this->siteaccessConfig['siteaccess']['list'] |
| 58 | + ); |
| 59 | + $this->assertContainerBuilderHasParameter( |
| 60 | + 'ezpublish.siteaccess.default', |
| 61 | + $this->siteaccessConfig['siteaccess']['default_siteaccess'] |
| 62 | + ); |
| 63 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.groups', $this->siteaccessConfig['siteaccess']['groups'] ); |
| 64 | + |
| 65 | + $expectedMatchingConfig = array(); |
| 66 | + foreach ( $this->siteaccessConfig['siteaccess']['match'] as $key => $val ) |
| 67 | + { |
| 68 | + // Value is expected to always be an array (transformed by semantic configuration parser). |
| 69 | + $expectedMatchingConfig[$key] = is_array( $val ) ? $val : array( 'value' => $val ); |
| 70 | + } |
| 71 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.match_config', $expectedMatchingConfig ); |
| 72 | + |
| 73 | + $groupsBySiteaccess = array(); |
| 74 | + foreach ( $this->siteaccessConfig['siteaccess']['groups'] as $groupName => $groupMembers ) |
| 75 | + { |
| 76 | + foreach ( $groupMembers as $member ) |
| 77 | + { |
| 78 | + if ( !isset( $groupsBySiteaccess[$member] ) ) |
| 79 | + $groupsBySiteaccess[$member] = array(); |
| 80 | + |
| 81 | + $groupsBySiteaccess[$member][] = $groupName; |
| 82 | + } |
| 83 | + } |
| 84 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess ); |
| 85 | + } |
| 86 | + |
| 87 | + public function testSiteAccessNoConfiguration() |
| 88 | + { |
| 89 | + $this->load(); |
| 90 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.list', array( 'setup' ) ); |
| 91 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.default', 'setup' ); |
| 92 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.groups', array() ); |
| 93 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.groups_by_siteaccess', array() ); |
| 94 | + $this->assertContainerBuilderHasParameter( 'ezpublish.siteaccess.match_config', null ); |
| 95 | + } |
| 96 | + |
| 97 | + public function testImageMagickConfigurationBasic() |
| 98 | + { |
| 99 | + $this->load(); |
| 100 | + $this->assertContainerBuilderHasParameter( 'ezpublish.image.imagemagick.enabled', true ); |
| 101 | + $this->assertContainerBuilderHasParameter( 'ezpublish.image.imagemagick.executable_path', dirname( $this->minimalConfig['imagemagick']['path'] ) ); |
| 102 | + $this->assertContainerBuilderHasParameter( 'ezpublish.image.imagemagick.executable', basename( $this->minimalConfig['imagemagick']['path'] ) ); |
| 103 | + } |
| 104 | + |
| 105 | + public function testImageMagickConfigurationFilters() |
| 106 | + { |
| 107 | + $customFilters = array( |
| 108 | + 'foobar' => '-foobar', |
| 109 | + 'wow' => '-amazing' |
| 110 | + ); |
| 111 | + $this->load( |
| 112 | + array( |
| 113 | + 'imagemagick' => array( |
| 114 | + 'filters' => $customFilters |
| 115 | + ) |
| 116 | + ) |
| 117 | + ); |
| 118 | + $this->assertTrue( $this->container->hasParameter( 'ezpublish.image.imagemagick.filters' ) ); |
| 119 | + $filters = $this->container->getParameter( 'ezpublish.image.imagemagick.filters' ); |
| 120 | + $this->assertArrayHasKey( 'foobar', $filters ); |
| 121 | + $this->assertSame( $customFilters['foobar'], $filters['foobar'] ); |
| 122 | + $this->assertArrayHasKey( 'wow', $filters ); |
| 123 | + $this->assertSame( $customFilters['wow'], $filters['wow'] ); |
| 124 | + } |
| 125 | + |
| 126 | + public function testEzPageConfiguration() |
| 127 | + { |
| 128 | + $customLayouts = array( |
| 129 | + 'FoobarLayout' => array( 'name' => 'Foo layout', 'template' => 'foolayout.html.twig' ) |
| 130 | + ); |
| 131 | + $enabledLayouts = array( 'FoobarLayout', 'GlobalZoneLayout' ); |
| 132 | + $customBlocks = array( |
| 133 | + 'FoobarBlock' => array( 'name' => 'Foo block' ) |
| 134 | + ); |
| 135 | + $enabledBlocks = array( 'FoobarBlock', 'DemoBlock' ); |
| 136 | + $this->load( |
| 137 | + array( |
| 138 | + 'ezpage' => array( |
| 139 | + 'layouts' => $customLayouts, |
| 140 | + 'blocks' => $customBlocks, |
| 141 | + 'enabledLayouts' => $enabledLayouts, |
| 142 | + 'enabledBlocks' => $enabledBlocks |
| 143 | + ) |
| 144 | + ) |
| 145 | + ); |
| 146 | + |
| 147 | + $this->assertTrue( $this->container->hasParameter( 'ezpublish.ezpage.layouts' ) ); |
| 148 | + $layouts = $this->container->getParameter( 'ezpublish.ezpage.layouts' ); |
| 149 | + $this->assertArrayHasKey( 'FoobarLayout', $layouts ); |
| 150 | + $this->assertSame( $customLayouts['FoobarLayout'], $layouts['FoobarLayout'] ); |
| 151 | + $this->assertContainerBuilderHasParameter( 'ezpublish.ezpage.enabledLayouts', $enabledLayouts ); |
| 152 | + |
| 153 | + $this->assertTrue( $this->container->hasParameter( 'ezpublish.ezpage.blocks' ) ); |
| 154 | + $blocks = $this->container->getParameter( 'ezpublish.ezpage.blocks' ); |
| 155 | + $this->assertArrayHasKey( 'FoobarBlock', $blocks ); |
| 156 | + $this->assertSame( $customBlocks['FoobarBlock'], $blocks['FoobarBlock'] ); |
| 157 | + $this->assertContainerBuilderHasParameter( 'ezpublish.ezpage.enabledBlocks', $enabledBlocks ); |
| 158 | + } |
| 159 | + |
| 160 | + public function testRoutingConfiguration() |
| 161 | + { |
| 162 | + $this->load(); |
| 163 | + $this->assertContainerBuilderHasAlias( 'router', 'ezpublish.chain_router' ); |
| 164 | + |
| 165 | + $this->assertTrue( $this->container->hasParameter( 'ezpublish.default_router.non_siteaccess_aware_routes' ) ); |
| 166 | + $nonSiteaccessAwareRoutes = $this->container->getParameter( 'ezpublish.default_router.non_siteaccess_aware_routes' ); |
| 167 | + // See ezpublish_minimal_no_siteaccess.yml fixture |
| 168 | + $this->assertContains( 'foo_route', $nonSiteaccessAwareRoutes ); |
| 169 | + $this->assertContains( 'my_prefix_', $nonSiteaccessAwareRoutes ); |
| 170 | + |
| 171 | + $this->assertTrue( $this->container->hasParameter( 'ezpublish.default_router.legacy_aware_routes' ) ); |
| 172 | + $legacyAwareRoutes = $this->container->getParameter( 'ezpublish.default_router.legacy_aware_routes' ); |
| 173 | + $this->assertContains( 'legacy_foo_route', $legacyAwareRoutes ); |
| 174 | + $this->assertContains( 'my_prefix_', $legacyAwareRoutes ); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @dataProvider cacheConfigurationProvider |
| 179 | + * |
| 180 | + * @param array $customCachConfig |
| 181 | + * @param string $expectedPurgeService |
| 182 | + * @param int $expectedTimeout |
| 183 | + */ |
| 184 | + public function testCacheConfiguration( array $customCachConfig, $expectedPurgeService, $expectedTimeout ) |
| 185 | + { |
| 186 | + $this->load( $customCachConfig ); |
| 187 | + |
| 188 | + $this->assertContainerBuilderHasAlias( 'ezpublish.http_cache.purge_client', $expectedPurgeService ); |
| 189 | + $this->assertContainerBuilderHasParameter( 'ezpublish.http_cache.purge_client.http_client.timeout', $expectedTimeout ); |
| 190 | + } |
| 191 | + |
| 192 | + public function cacheConfigurationProvider() |
| 193 | + { |
| 194 | + return array( |
| 195 | + array( array(), 'ezpublish.http_cache.purge_client.local', 1 ), |
| 196 | + array( |
| 197 | + array( |
| 198 | + 'http_cache' => array( 'purge_type' => 'local', 'timeout' => 12 ) |
| 199 | + ), |
| 200 | + 'ezpublish.http_cache.purge_client.local', |
| 201 | + 12 |
| 202 | + ), |
| 203 | + array( |
| 204 | + array( |
| 205 | + 'http_cache' => array( 'purge_type' => 'multiple_http', 'timeout' => 5 ) |
| 206 | + ), |
| 207 | + 'ezpublish.http_cache.purge_client.multi_request', |
| 208 | + 5 |
| 209 | + ), |
| 210 | + array( |
| 211 | + array( |
| 212 | + 'http_cache' => array( 'purge_type' => 'single_http', 'timeout' => 1 ) |
| 213 | + ), |
| 214 | + 'ezpublish.http_cache.purge_client.single_request', |
| 215 | + 1 |
| 216 | + ), |
| 217 | + ); |
| 218 | + } |
| 219 | + |
| 220 | + /** |
| 221 | + * @expectedException \InvalidArgumentException |
| 222 | + */ |
| 223 | + public function testCacheConfigurationWrongPurgeType() |
| 224 | + { |
| 225 | + $this->load( |
| 226 | + array( |
| 227 | + 'http_cache' => array( 'purge_type' => 'foobar', 'timeout' => 12 ) |
| 228 | + ) |
| 229 | + ); |
| 230 | + } |
| 231 | + |
| 232 | + public function testCacheConfigurationCustomPurgeService() |
| 233 | + { |
| 234 | + $serviceId = 'foobar'; |
| 235 | + $this->setDefinition( $serviceId, new Definition() ); |
| 236 | + $this->load( |
| 237 | + array( |
| 238 | + 'http_cache' => array( 'purge_type' => 'foobar', 'timeout' => 12 ) |
| 239 | + ) |
| 240 | + ); |
| 241 | + } |
| 242 | + |
| 243 | + public function testLocaleConfiguration() |
| 244 | + { |
| 245 | + $this->load( array( 'locale_conversion' => array( 'foo' => 'bar' ) ) ); |
| 246 | + $conversionMap = $this->container->getParameter( 'ezpublish.locale.conversion_map' ); |
| 247 | + $this->assertArrayHasKey( 'foo', $conversionMap ); |
| 248 | + $this->assertSame( 'bar', $conversionMap['foo'] ); |
| 249 | + } |
| 250 | +} |
0 commit comments