mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
create tests (with app/kernel fixtures) for menu composer #217
This commit is contained in:
parent
d66583758a
commit
31779fec4e
2
.gitignore
vendored
2
.gitignore
vendored
@ -15,5 +15,7 @@ web/bundles/*
|
||||
app/config/parameters.ini
|
||||
app/config/parameters.yml
|
||||
|
||||
#composer
|
||||
composer.lock
|
||||
#sass-cache
|
||||
Resources/assets/gumpy/.sass-cache
|
||||
|
@ -45,15 +45,15 @@ class MenuComposer
|
||||
{
|
||||
$routes = array();
|
||||
|
||||
foreach ($this->routeCollection->all() as $key => $route) {
|
||||
foreach ($this->routeCollection->all() as $routeKey => $route) {
|
||||
if ($route->hasOption('menus')) {
|
||||
foreach ($route->getOption('menus') as $key => $params) {
|
||||
if ($menuId === $key) {
|
||||
foreach ($route->getOption('menus') as $menuKey => $params) {
|
||||
if ($menuId === $menuKey) {
|
||||
$route = array();
|
||||
$route['route'] = $key;
|
||||
$route['route'] = $routeKey;
|
||||
$route['label'] = $params['label'];
|
||||
$route['helper'] =
|
||||
(isset($params['helper'])) ? $params['helper'] : '';
|
||||
(isset($params['helper'])) ? $params['helper'] : null;
|
||||
|
||||
//add route to the routes array, avoiding duplicate 'order'
|
||||
// to erase previously added
|
||||
|
39
Tests/Fixtures/App/AppKernel.php
Normal file
39
Tests/Fixtures/App/AppKernel.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
|
||||
class AppKernel extends Kernel
|
||||
{
|
||||
public function registerBundles()
|
||||
{
|
||||
return array(
|
||||
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
|
||||
new \CL\Chill\MainBundle\CLChillMainBundle(),
|
||||
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
|
||||
new Symfony\Bundle\TwigBundle\TwigBundle(),
|
||||
new \Symfony\Bundle\AsseticBundle\AsseticBundle(),
|
||||
);
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCacheDir()
|
||||
{
|
||||
return sys_get_temp_dir().'/AcmeHelloBundle/cache';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLogDir()
|
||||
{
|
||||
return sys_get_temp_dir().'/AcmeHelloBundle/logs';
|
||||
}
|
||||
}
|
11
Tests/Fixtures/App/config/config.yml
Normal file
11
Tests/Fixtures/App/config/config.yml
Normal file
@ -0,0 +1,11 @@
|
||||
framework:
|
||||
secret: Not very secret
|
||||
router: { resource: "%kernel.root_dir%/config/routing.yml" }
|
||||
form: true
|
||||
csrf_protection: true
|
||||
session: ~
|
||||
default_locale: fr
|
||||
translator: { fallback: fr }
|
||||
profiler: { only_exceptions: false }
|
||||
templating:
|
||||
engines: ['twig']
|
7
Tests/Fixtures/App/config/config_test.yml
Normal file
7
Tests/Fixtures/App/config/config_test.yml
Normal file
@ -0,0 +1,7 @@
|
||||
imports:
|
||||
- { resource: config.yml }
|
||||
|
||||
framework:
|
||||
test: ~
|
||||
session:
|
||||
storage_id: session.storage.filesystem
|
24
Tests/Fixtures/App/config/routing.yml
Normal file
24
Tests/Fixtures/App/config/routing.yml
Normal file
@ -0,0 +1,24 @@
|
||||
hello_bundle:
|
||||
resource: "@CLChillMainBundle/Resources/config/routing.yml"
|
||||
|
||||
chill_main_dummy_0:
|
||||
pattern: /dummy
|
||||
defaults: { _controller: CLChillMainBundle:Default:index }
|
||||
options:
|
||||
menus:
|
||||
dummy0:
|
||||
order: 50
|
||||
label: 'test0'
|
||||
dummy1:
|
||||
order: 50
|
||||
label: test dummy 1
|
||||
|
||||
chill_main_dummy_1:
|
||||
pattern: /dummy1
|
||||
defaults: { _controller: CLChillMainBundle:Default:index }
|
||||
options:
|
||||
menus:
|
||||
dummy0:
|
||||
order: 50
|
||||
label: 'test1'
|
||||
helper: 'great helper'
|
@ -11,7 +11,7 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class MenuComposer extends KernelTestCase
|
||||
class MenuComposerTest extends KernelTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
@ -28,17 +28,17 @@ class MenuComposer extends KernelTestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
self::bootKernel(array('environment' => 'test'));
|
||||
$this->loader = static::$kernel->getContainer()
|
||||
->get('routing.loader');
|
||||
$this->menuComposer = static::$kernel->getContainer()
|
||||
->get('chill_main.menu_composer');
|
||||
->get('chill.main.menu_composer');
|
||||
}
|
||||
|
||||
public function testMenuComposer()
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
$collection->add($this->loader->load(__DIR__.'dummy_menu_composer.yml', 'yaml'));
|
||||
//$collection->add($this->loader->load(__DIR__.'dummy_menu_composer.yml', 'yaml'));
|
||||
|
||||
$routes = $this->menuComposer->getRoutesFor('dummy0');
|
||||
|
||||
@ -54,11 +54,12 @@ class MenuComposer extends KernelTestCase
|
||||
}
|
||||
$this->assertSame(array(
|
||||
50 => array(
|
||||
'key' => 'chill_main_dummy_0',
|
||||
'route' => 'chill_main_dummy_0',
|
||||
'label' => 'test0',
|
||||
'helper'=> null
|
||||
),
|
||||
51 => array(
|
||||
'key' => 'chill_main_dummy_1',
|
||||
'route' => 'chill_main_dummy_1',
|
||||
'label' => 'test1',
|
||||
'helper'=> 'great helper'
|
||||
)
|
@ -18,7 +18,9 @@
|
||||
"require": {
|
||||
"twig/extensions": "~1.0",
|
||||
"symfony/assetic-bundle": "~2.3",
|
||||
"symfony/monolog-bundle": "~2.4"
|
||||
"symfony/monolog-bundle": "~2.4",
|
||||
"symfony/framework-bundle": "2.5.*",
|
||||
"symfony/yaml": "2.5.*",
|
||||
"symfony/symfony": "2.5.*"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,4 +16,7 @@
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<php>
|
||||
<server name="KERNEL_DIR" value="./Tests/Fixtures/App/" />
|
||||
</php>
|
||||
</phpunit>
|
||||
|
Loading…
x
Reference in New Issue
Block a user