Skip to content

Commit

Permalink
Merge pull request #8 from dekey/fix_menu
Browse files Browse the repository at this point in the history
Update node visit order
  • Loading branch information
dmaicher authored Apr 10, 2019
2 parents 63bfb1d + f8deb96 commit 29a89bf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/DAMA/MenuBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
class: DAMA\MenuBundle\NodeVisitor\NodeFilter
arguments: ["@security.token_storage", "@security.authorization_checker"]
tags:
- { name: dama_menu.node_visitor, priority: 1 }
- { name: dama_menu.node_visitor, priority: 3 }

dama_menu.node_visitor.activator:
class: DAMA\MenuBundle\NodeVisitor\NodeActivator
Expand All @@ -38,4 +38,4 @@ services:
dama_menu.node_visitor.node_route_propagator:
class: DAMA\MenuBundle\NodeVisitor\NodeRoutePropagator
tags:
- { name: dama_menu.node_visitor, priority: 3 }
- { name: dama_menu.node_visitor, priority: 1 }
9 changes: 6 additions & 3 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

class FunctionalTest extends WebTestCase
{
public function testRenderMenuOne()
public function testRenderMenuOne(): void
{
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$this->assertSame(200, $client->getResponse()->getStatusCode());

$this->assertCount(1, $crawler->filter('ul.menu-layer-1'));
$this->assertCount(1, $crawler->filter('ul.menu-layer-2'));
$this->assertCount(2, $crawler->filter('ul.menu-layer-2'));

$this->assertCount(2, $crawler->filter('li.menu-item'));
$this->assertCount(4, $crawler->filter('li.menu-item'));
$this->assertCount(0, $crawler->filter('li.bla-class'));
$this->assertCount(1, $crawler->filter('li.foo-child-class'));

$this->assertCount(2, $crawler->filter('a[href="/test_2"]'));
$this->assertCount(0, $crawler->filter('a[href="/test_1"]'));
}
}
13 changes: 11 additions & 2 deletions tests/Functional/TestMenuTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use DAMA\MenuBundle\MenuTree\MenuTreeBuilderInterface;
use DAMA\MenuBundle\Node\Node;
use Symfony\Component\ExpressionLanguage\Expression;

class TestMenuTreeBuilder implements MenuTreeBuilderInterface
{
public function build(Node $root)
public function build(Node $root): void
{
$root
->child('bla')
Expand All @@ -22,6 +21,16 @@ public function build(Node $root)
->setAttr('class', 'foo-child-class')
->end()
->end()
->child('bar')
->setAdditionalActiveRoutes(['test_1', 'test_2'])
->child('bar-sub-1')
->setRoute('test_1')
->setRequiredPermissions(['IS_AUTHENTICATED_FULLY'])
->end()
->child('bar-sub-2')
->setRoute('test_2')
->end()
->end()
;
}
}
11 changes: 11 additions & 0 deletions tests/Functional/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ test:
defaults:
template: test_menu.html.twig

test_1:
path: /test_1
controller: 'FrameworkBundle:Template:template'
defaults:
template: test_menu.html.twig

test_2:
path: /test_2
controller: 'FrameworkBundle:Template:template'
defaults:
template: test_menu.html.twig
6 changes: 3 additions & 3 deletions tests/MenuTree/MenuTreeTraverserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setUp()
$this->traverser->addVisitor($this->visitors[1]);
}

public function testTraverseCallsVisitOnEachVisitor()
public function testTraverseCallsVisitOnEachVisitor(): void
{
$root = new Node();
$child = new Node();
Expand All @@ -43,7 +43,7 @@ public function testTraverseCallsVisitOnEachVisitor()
$this->traverser->traverse($root);
}

public function testStopTraversal()
public function testStopTraversal(): void
{
$root = new Node();
$child = new Node();
Expand All @@ -64,7 +64,7 @@ public function testStopTraversal()
$this->traverser->traverse($root);
}

public function testTraverseRecursively()
public function testTraverseRecursively(): void
{
$root = new Node();
$child = new Node();
Expand Down

0 comments on commit 29a89bf

Please sign in to comment.