Skip to content

Commit 403062e

Browse files
committed
Added configuration test
Conflicts: composer.json
1 parent 7b39111 commit 403062e

File tree

6 files changed

+186
-1
lines changed

6 files changed

+186
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getConfigTreeBuilder()
6767
->prototype('scalar')->end()
6868
->end()
6969
->arrayNode('templates_by_class')
70-
->useAttributeAsKey('alias')
70+
->useAttributeAsKey('class')
7171
->prototype('scalar')->end()
7272
->end()
7373
->arrayNode('persistence')
@@ -81,6 +81,21 @@ public function getConfigTreeBuilder()
8181
->scalarNode('route_basepath')->defaultValue('/cms/routes')->end()
8282
->scalarNode('content_basepath')->defaultValue('/cms/content')->end()
8383
->enumNode('use_sonata_admin')
84+
->beforeNormalization()
85+
->ifString()
86+
->then(function ($v) {
87+
switch ($v) {
88+
case 'true':
89+
return true;
90+
91+
case 'false':
92+
return false;
93+
94+
default:
95+
return $v;
96+
}
97+
})
98+
->end()
8499
->values(array(true, false, 'auto'))
85100
->defaultValue('auto')
86101
->end()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
$container->loadFromExtension('cmf_routing', array(
4+
'chain' => array(
5+
'routers_by_id' => array(
6+
'cmf_routing.router' => 300,
7+
'router.default' => 100,
8+
),
9+
'replace_symfony_router' => true,
10+
),
11+
'dynamic' => array(
12+
'generic_controller' => 'acme_main.controller:mainAction',
13+
'controllers_by_type' => array(
14+
'editable' => 'acme_main.some_controller:editableAction',
15+
),
16+
'controllers_by_class' => array(
17+
'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'cmf_content.controller:indexAction',
18+
),
19+
'templates_by_class' => array(
20+
'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'CmfContentBundle:StaticContent:index.html.twig',
21+
),
22+
'persistence' => array(
23+
'phpcr' => array(
24+
'route_basepath' => '/cms/routes',
25+
'content_basepath' => '/cms/content',
26+
'use_sonata_admin' => 'false',
27+
),
28+
),
29+
'locales' => array('en', 'fr'),
30+
),
31+
));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
5+
6+
<chain replace-symfony-router="true">
7+
<router-by-id id="cmf_routing.router">300</router-by-id>
8+
<router-by-id id="router.default">100</router-by-id>
9+
</chain>
10+
11+
<dynamic generic-controller="acme_main.controller:mainAction">
12+
<controller-by-type type="editable">acme_main.some_controller:editableAction</controller-by-type>
13+
<controller-by-class class="Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent">
14+
cmf_content.controller:indexAction
15+
</controller-by-class>
16+
<template-by-class class="Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent">
17+
CmfContentBundle:StaticContent:index.html.twig
18+
</template-by-class>
19+
20+
<persistence>
21+
<phpcr
22+
route-basepath="/cms/routes"
23+
content-basepath="/cms/content"
24+
use-sonata-admin="false"
25+
/>
26+
</persistence>
27+
28+
<locale>en</locale>
29+
<locale>fr</locale>
30+
</dynamic>
31+
</config>
32+
</container>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmf_routing:
2+
chain:
3+
routers_by_id:
4+
cmf_routing.router: 300
5+
router.default: 100
6+
replace_symfony_router: true
7+
dynamic:
8+
generic_controller: acme_main.controller:mainAction
9+
controllers_by_type:
10+
editable: acme_main.some_controller:editableAction
11+
controllers_by_class:
12+
Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent: cmf_content.controller:indexAction
13+
templates_by_class:
14+
Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent: CmfContentBundle:StaticContent:index.html.twig
15+
persistence:
16+
phpcr:
17+
route_basepath: /cms/routes
18+
content_basepath: /cms/content
19+
use_sonata_admin: false
20+
locales: [en, fr]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2013 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+
13+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\DependencyInjection;
14+
15+
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\CmfRoutingExtension;
16+
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Configuration;
17+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
18+
19+
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
20+
{
21+
protected function getContainerExtension()
22+
{
23+
return new CmfRoutingExtension();
24+
}
25+
26+
protected function getConfiguration()
27+
{
28+
return new Configuration();
29+
}
30+
31+
public function testSupportsAllConfigFormats()
32+
{
33+
$expectedConfiguration = array(
34+
'chain' => array(
35+
'routers_by_id' => array(
36+
'cmf_routing.router' => 300,
37+
'router.default' => 100,
38+
),
39+
'replace_symfony_router' => true,
40+
),
41+
'dynamic' => array(
42+
'generic_controller' => 'acme_main.controller:mainAction',
43+
'controllers_by_type' => array(
44+
'editable' => 'acme_main.some_controller:editableAction',
45+
),
46+
'controllers_by_class' => array(
47+
'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'cmf_content.controller:indexAction',
48+
),
49+
'templates_by_class' => array(
50+
'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'CmfContentBundle:StaticContent:index.html.twig',
51+
),
52+
'persistence' => array(
53+
'phpcr' => array(
54+
'enabled' => true,
55+
'route_basepath' => '/cms/routes',
56+
'content_basepath' => '/cms/content',
57+
'manager_name' => null,
58+
'use_sonata_admin' => false,
59+
),
60+
'orm' => array(
61+
'enabled' => false,
62+
'manager_name' => null,
63+
),
64+
),
65+
'enabled' => true,
66+
'default_controller' => null,
67+
'uri_filter_regexp' => '',
68+
'route_filters_by_id' => array(),
69+
'locales' => array('en', 'fr'),
70+
),
71+
);
72+
73+
$formats = array_map(function ($path) {
74+
return __DIR__.'/../../Resources/Fixtures/'.$path;
75+
}, array(
76+
'config/config.yml',
77+
'config/config.xml',
78+
'config/config.php',
79+
));
80+
81+
foreach ($formats as $format) {
82+
$this->assertProcessedConfigurationEquals($expectedConfiguration, array($format));
83+
}
84+
}
85+
}

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"require-dev": {
2222
"symfony-cmf/core-bundle": "1.0.*",
2323
"symfony-cmf/testing": "1.1.*",
24+
"matthiasnoback/symfony-dependency-injection-test": "0.*",
25+
"matthiasnoback/symfony-config-test": "0.*",
2426
"sonata-project/doctrine-phpcr-admin-bundle": "1.0.*",
2527
"symfony/monolog-bundle": "2.2.*",
2628
"doctrine/orm": "2.3.*"

0 commit comments

Comments
 (0)