mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 17:13:49 +00:00
68
Tests/Services/MenuComposer.php
Normal file
68
Tests/Services/MenuComposer.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace CL\Chill\MainBundle\Tests\Services;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* This class provide functional test for MenuComposer
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class MenuComposer extends KernelTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \CL\Chill\MainBundle\DependencyInjection\Services\MenuComposer;
|
||||
*/
|
||||
private $menuComposer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->loader = static::$kernel->getContainer()
|
||||
->get('routing.loader');
|
||||
$this->menuComposer = static::$kernel->getContainer()
|
||||
->get('chill_main.menu_composer');
|
||||
}
|
||||
|
||||
public function testMenuComposer()
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
$collection->add($this->loader->load(__DIR__.'dummy_menu_composer.yml', 'yaml'));
|
||||
|
||||
$routes = $this->menuComposer->getRoutesFor('dummy0');
|
||||
|
||||
$this->assertInternalType('array', $routes);
|
||||
$this->assertCount(2, $routes);
|
||||
//check that the keys are sorted
|
||||
$orders = array_keys($routes);
|
||||
foreach ($orders as $key => $order){
|
||||
if (array_key_exists($key + 1, $orders)) {
|
||||
$this->assertGreaterThan($order, $orders[$key + 1],
|
||||
'Failing to assert that routes are ordered');
|
||||
}
|
||||
}
|
||||
$this->assertSame(array(
|
||||
50 => array(
|
||||
'key' => 'chill_main_dummy_0',
|
||||
'label' => 'test0',
|
||||
),
|
||||
51 => array(
|
||||
'key' => 'chill_main_dummy_1',
|
||||
'label' => 'test1',
|
||||
'helper'=> 'great helper'
|
||||
)
|
||||
|
||||
), $routes);
|
||||
}
|
||||
}
|
21
Tests/Services/dummy_menu_composer.yml
Normal file
21
Tests/Services/dummy_menu_composer.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
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'
|
Reference in New Issue
Block a user