|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony CMF package. |
| 5 | + * |
| 6 | + * (c) 2011-2017 Symfony CMF |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Unit\DependencyInjection; |
| 13 | + |
| 14 | +use Symfony\Bundle\SecurityBundle\SecurityBundle; |
| 15 | +use Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\CmfCoreExtension; |
| 16 | +use Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle; |
| 17 | +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
| 18 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 19 | +use Symfony\Component\DependencyInjection\Definition; |
| 20 | +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
| 21 | +use Symfony\Component\Routing\Router; |
| 22 | + |
| 23 | +class CmfCoreExtensionTest extends \PHPUnit_Framework_TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var CmfCoreExtension |
| 27 | + */ |
| 28 | + protected $extension; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->extension = new CmfCoreExtension(); |
| 33 | + } |
| 34 | + |
| 35 | + public function testPublishWorkflowAutoSupported() |
| 36 | + { |
| 37 | + $container = $this->createContainer(['kernel.bundles' => ['SecurityBundle' => SecurityBundle::class]]); |
| 38 | + |
| 39 | + $this->extension->load([['publish_workflow' => ['request_listener' => false]]], $container); |
| 40 | + |
| 41 | + $this->assertTrue($container->hasAlias('cmf_core.publish_workflow.checker')); |
| 42 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.checker.default')); |
| 43 | + $this->assertTrue($container->hasDefinition('cmf_core.security.publishable_voter')); |
| 44 | + $this->assertTrue($container->hasDefinition('cmf_core.security.publish_time_period_voter')); |
| 45 | + $this->assertFalse($container->hasDefinition('cmf_core.publish_workflow.request_listener')); |
| 46 | + } |
| 47 | + |
| 48 | + public function testPublishWorkflowListenerEnabled() |
| 49 | + { |
| 50 | + $container = $this->createContainer(['kernel.bundles' => [ |
| 51 | + 'SecurityBundle' => SecurityBundle::class, |
| 52 | + 'CmfRoutingBundle' => CmfRoutingBundle::class, |
| 53 | + ]]); |
| 54 | + |
| 55 | + $this->extension->load([], $container); |
| 56 | + |
| 57 | + $this->assertTrue($container->hasAlias('cmf_core.publish_workflow.checker')); |
| 58 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.checker.default')); |
| 59 | + $this->assertTrue($container->hasDefinition('cmf_core.security.publishable_voter')); |
| 60 | + $this->assertTrue($container->hasDefinition('cmf_core.security.publish_time_period_voter')); |
| 61 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.request_listener')); |
| 62 | + } |
| 63 | + |
| 64 | + public function testPublishWorkflowAutoNotSupported() |
| 65 | + { |
| 66 | + $container = $this->createContainer(['kernel.bundles' => []]); |
| 67 | + |
| 68 | + $this->extension->load([], $container); |
| 69 | + |
| 70 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.checker')); |
| 71 | + $this->assertFalse($container->hasAlias('cmf_core.publish_workflow.checker')); |
| 72 | + $this->assertFalse($container->hasDefinition('cmf_core.publish_workflow.checker.default')); |
| 73 | + $this->assertFalse($container->hasDefinition('cmf_core.security.publishable_voter')); |
| 74 | + $this->assertFalse($container->hasDefinition('cmf_core.security.publish_time_period_voter')); |
| 75 | + $this->assertFalse($container->hasDefinition('cmf_core.publish_workflow.request_listener')); |
| 76 | + } |
| 77 | + |
| 78 | + public function testPublishWorkflowFalse() |
| 79 | + { |
| 80 | + $container = $this->createContainer(['kernel.bundles' => [ |
| 81 | + 'SecurityBundle' => SecurityBundle::class, |
| 82 | + 'CmfRoutingBundle' => CmfRoutingBundle::class, |
| 83 | + ]]); |
| 84 | + |
| 85 | + $this->extension->load([['publish_workflow' => false]], $container); |
| 86 | + |
| 87 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.checker')); |
| 88 | + $this->assertFalse($container->hasAlias('cmf_core.publish_workflow.checker')); |
| 89 | + $this->assertFalse($container->hasDefinition('cmf_core.publish_workflow.checker.default')); |
| 90 | + $this->assertFalse($container->hasDefinition('cmf_core.security.publishable_voter')); |
| 91 | + $this->assertFalse($container->hasDefinition('cmf_core.security.publish_time_period_voter')); |
| 92 | + $this->assertFalse($container->hasDefinition('cmf_core.publish_workflow.request_listener')); |
| 93 | + } |
| 94 | + |
| 95 | + public function testPublishWorkflowTrueSupported() |
| 96 | + { |
| 97 | + $container = $this->createContainer(['kernel.bundles' => [ |
| 98 | + 'SecurityBundle' => SecurityBundle::class, |
| 99 | + 'CmfRoutingBundle' => CmfRoutingBundle::class, |
| 100 | + ]]); |
| 101 | + |
| 102 | + $this->extension->load([['publish_workflow' => true]], $container); |
| 103 | + |
| 104 | + $this->assertTrue($container->hasAlias('cmf_core.publish_workflow.checker')); |
| 105 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.checker.default')); |
| 106 | + $this->assertTrue($container->hasDefinition('cmf_core.security.publishable_voter')); |
| 107 | + $this->assertTrue($container->hasDefinition('cmf_core.security.publish_time_period_voter')); |
| 108 | + $this->assertTrue($container->hasDefinition('cmf_core.publish_workflow.request_listener')); |
| 109 | + } |
| 110 | + |
| 111 | + public function testPublishWorkflowTrueNotSupported() |
| 112 | + { |
| 113 | + $container = $this->createContainer(['kernel.bundles' => [ |
| 114 | + 'CmfRoutingBundle' => CmfRoutingBundle::class, |
| 115 | + ]]); |
| 116 | + |
| 117 | + $this->expectException(InvalidConfigurationException::class); |
| 118 | + $this->extension->load([['publish_workflow' => true]], $container); |
| 119 | + } |
| 120 | + |
| 121 | + private function createContainer(array $parameters) |
| 122 | + { |
| 123 | + $parameters = array_merge(['kernel.debug' => false], $parameters); |
| 124 | + $container = new ContainerBuilder( |
| 125 | + new ParameterBag($parameters) |
| 126 | + ); |
| 127 | + |
| 128 | + // The cache_manager service depends on the router service |
| 129 | + $container->setDefinition( |
| 130 | + 'router', |
| 131 | + new Definition(Router::class) |
| 132 | + ); |
| 133 | + |
| 134 | + return $container; |
| 135 | + } |
| 136 | +} |
0 commit comments