Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 709ca61

Browse files
committed
Added functional test for auto-route service
1 parent 0cb652e commit 709ca61

18 files changed

+2769
-6
lines changed

AutoRoute/AutoRouteManager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class AutoRouteManager
1717
{
1818
protected $dm;
19-
protected $metadataFactory;
19+
protected $mapping;
2020
protected $defaultPath;
2121
protected $slugifier;
2222

@@ -34,7 +34,7 @@ class AutoRouteManager
3434
*/
3535
public function __construct(
3636
DocumentManager $dm,
37-
$mapping,
37+
array $mapping,
3838
SlugifierInterface $slugifier,
3939
$defaultPath
4040
)
@@ -231,6 +231,11 @@ public function fetchAutoRoutesForDocument($document)
231231
return $routes;
232232
}
233233

234+
public function getDefaultPath()
235+
{
236+
return $this->defaultPath;
237+
}
238+
234239
protected function isDocumentPersisted($document)
235240
{
236241
$metadata = $this->dm->getClassMetadata(get_class($document));

DependencyInjection/Configuration.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoRouteBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\ConfigurationInterface;
6+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7+
8+
class Configuration implements ConfigurationInterface
9+
{
10+
/**
11+
* Returns the config tree builder.
12+
*
13+
* @return TreeBuilder
14+
*/
15+
public function getConfigTreeBuilder()
16+
{
17+
$treeBuilder = new TreeBuilder();
18+
$treeBuilder->root('symfony_cmf_routing_auto_route')
19+
->children()
20+
->scalarNode('basepath')
21+
->defaultValue('/cms/auto-routes')
22+
->end()
23+
->arrayNode('auto_route_by_class')
24+
->useAttributeAsKey('class')
25+
->prototype('array')
26+
->children()
27+
->scalarNode('base_path')->end()
28+
->scalarNode('route_method_name')->end()
29+
->end()
30+
->end();
31+
32+
return $treeBuilder;
33+
}
34+
}
35+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoRouteBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\Config\Definition\Processor;
8+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9+
use Symfony\Component\DependencyInjection\Reference;
10+
use Symfony\Component\Config\Loader\LoaderInterface;
11+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
12+
13+
class SymfonyCmfRoutingAutoRouteExtension extends Extension
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function load(array $configs, ContainerBuilder $container)
19+
{
20+
$processor = new Processor();
21+
$configuration = new Configuration();
22+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
23+
$loader->load('auto_route.xml');
24+
25+
$config = $processor->processConfiguration($configuration, $configs);
26+
27+
$keys = array(
28+
'basepath',
29+
'auto_route_by_class'
30+
);
31+
32+
foreach ($keys as $key) {
33+
$container->setParameter('symfony_cmf_routing_auto_route.'.$key, $config[$key]);
34+
}
35+
}
36+
}
37+

Resources/config/auto_route.xml

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+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<parameters>
7+
<parameter key="symfony_cmf_routing_auto_route.phpcrodm_auto_route_subscriber_class">Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Subscriber\AutoRouteSubscriber</parameter>
8+
<parameter key="symfony_cmf_routing_auto_route.auto_route_manager_class">Symfony\Cmf\Bundle\RoutingAutoRouteBundle\AutoRoute\AutoRouteManager</parameter>
9+
<parameter key="symfony_cmf_routing_auto_route.basepath"></parameter>
10+
<parameter key="symfony_cmf_routing_auto_route.auto_route_by_class"></parameter>
11+
</parameters>
12+
13+
<services>
14+
<service
15+
id="symfony_cmf_routing_auto_route.slugifier"
16+
class="Symfony\Cmf\Bundle\CoreBundle\Slugifier\CallbackSlugifier"
17+
>
18+
<argument>URLify::filter</argument>
19+
</service>
20+
21+
<service
22+
id="symfony_cmf_routing_auto_route.auto_route_manager"
23+
class="Symfony\Cmf\Bundle\RoutingAutoRouteBundle\AutoRoute\AutoRouteManager"
24+
>
25+
<argument type="service" id="doctrine_phpcr.odm.default_document_manager"/>
26+
<argument>%symfony_cmf_routing_auto_route.auto_route_by_class%</argument>
27+
<argument type="service" id="symfony_cmf_routing_auto_route.slugifier"/>
28+
<argument>%symfony_cmf_routing_auto_route.basepath%</argument>
29+
</service>
30+
</services>
31+
</container>
32+

SymfonyCmfRoutingAutoRouteBundle.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoRouteBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
class SymfonyCmfRoutingAutoRouteBundle extends Bundle
9+
{
10+
public function build(ContainerBuilder $container)
11+
{
12+
parent::build($container);
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Tests\Functional\AutoRoute;
4+
use Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Tests\Functional\BaseTestCase;
5+
6+
/**
7+
* Description here
8+
*
9+
* @author Daniel Leech <[email protected]>
10+
* @date 13/03/08
11+
*/
12+
class AutoRouteManagerTest extends BaseTestCase
13+
{
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
$this->arm = $this->getContainer()->get(
18+
'symfony_cmf_routing_auto_route.auto_route_manager'
19+
);
20+
}
21+
22+
public function testContainer()
23+
{
24+
$res = $this->arm->getDefaultPath();
25+
$this->assertEquals('/cms/auto-routes', $res);
26+
27+
$refl = new \ReflectionClass(get_class($this->arm));
28+
$prop = $refl->getProperty('mapping');
29+
$prop->setAccessible(true);
30+
$res = $prop->getValue($this->arm);
31+
32+
$this->assertEquals(array(
33+
'Symfony\Cmf\Bundle\AutoRouteBundle\Tests\Functional\app\Document\Post' => array(
34+
'base_path' => '/test/posts/test-post',
35+
'route_method_name' => 'getTitle'
36+
)
37+
), $res);
38+
}
39+
}

Tests/Functional/BaseTestCase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Tests\Functional;
44

5+
require __DIR__.'/app/AppKernel.php';
6+
57
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
68

79
class BaseTestCase extends WebTestCase
@@ -11,26 +13,31 @@ class BaseTestCase extends WebTestCase
1113
*/
1214
protected $dm;
1315

14-
protected function createKernel(array $options = array())
16+
static protected function createKernel(array $options = array())
1517
{
1618
return new AppKernel(
1719
isset($options['config']) ? $options['config'] : 'default.yml'
1820
);
1921
}
2022

21-
public static function setUp(array $options = array(), $routebase = null)
23+
public function getContainer()
24+
{
25+
return self::$kernel->getContainer();
26+
}
27+
28+
public function setUp(array $options = array(), $routebase = null)
2229
{
2330
self::$kernel = self::createKernel($options);
2431
self::$kernel->init();
2532
self::$kernel->boot();
2633

27-
$this->dm = self::$kernel->getContainer()->get('doctrine_phpcr.odm.document_manager');
34+
$this->dm = $this->getContainer()->get('doctrine_phpcr.odm.document_manager');
2835

2936
if (null == $routebase) {
3037
return;
3138
}
3239

33-
$session = self::$kernel->getContainer()->get('doctrine_phpcr.session');
40+
$session = $this->getContainer()->get('doctrine_phpcr.session');
3441

3542
if ($session->nodeExists("/test/$routebase")) {
3643
$session->getNode("/test/$routebase")->remove();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingExtraBundle\Tests\Functional\Testdoc;
4+
5+
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
6+
use Symfony\Cmf\Bundle\RoutingExtraBundle\Mapping\Annotations as CMFRouting;
7+
8+
/**
9+
* @PHPCR\Document(
10+
* referenceable=true
11+
* )
12+
*/
13+
class Post
14+
{
15+
/**
16+
* @PHPCR\Id()
17+
*/
18+
public $path;
19+
20+
/**
21+
* @PHPCR\Referrers(filter="routeContent")
22+
*/
23+
public $routes;
24+
25+
/**
26+
* @PHPCR\String()
27+
*/
28+
public $title;
29+
30+
public function getTitle()
31+
{
32+
return $this->title;
33+
}
34+
}
35+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
imports:
2+
- { resource: parameters.yml }
3+
- { resource: framework.yml }
4+
- { resource: monolog.yml }
5+
- { resource: doctrine.yml }
6+
- { resource: phpcrodm.yml }
7+
- { resource: routingautoroute.yml }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
doctrine:
2+
dbal:
3+
driver: %database_driver%
4+
path: %database_path%
5+
charset: UTF8

0 commit comments

Comments
 (0)