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

Commit 3ba369b

Browse files
dantleechdbu
authored andcommitted
Added webtest for Request Identity Voter
1 parent 5f29b60 commit 3ba369b

File tree

7 files changed

+46
-13
lines changed

7 files changed

+46
-13
lines changed

Tests/Resources/Controller/CmiTestController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function requestContentIdentityAction(Request $request)
2323
$content = $request->get(DynamicRouter::CONTENT_KEY);
2424
if (!$content) {
2525
$content = $this->container->get('doctrine_phpcr.odm.document_manager')->find(null, '/test/content-1');
26-
$request->query->set(DynamicRouter::CONTENT_KEY, $content);
26+
$request->attributes->set(DynamicRouter::CONTENT_KEY, $content);
27+
2728
return $this->render('::tests/cmi/requestContentVoterActive.html.twig', array('content' => $content));
2829
}
2930
return $this->render('::tests/cmi/requestContent.html.twig', array('content' => $content));

Tests/Resources/DataFixtures/PHPCR/LoadMenuData.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,11 @@ protected function loadSideMenu($manager)
136136
$manager->persist($content);
137137

138138
$route = new Route();
139-
$route->setContent($content);
140139
$route->setId('/test/routes/contents/content-1');
141140
$route->setDefault('_controller', 'Symfony\Cmf\Bundle\MenuBundle\Tests\Resources\Controller\CmiTestController::requestContentIdentityAction');
141+
$route->setContent($content);
142142
$manager->persist($route);
143143

144-
$content = new Content;
145-
$content->setTitle('CMI Content 1');
146-
$content->setId('/test/cmi-content-1');
147-
$manager->persist($content);
148-
149144
$menu = new Menu;
150145
$menu->setName('side-menu');
151146
$menu->setLabel('Side Menu');
@@ -163,7 +158,7 @@ protected function loadSideMenu($manager)
163158
$menuNode->setParent($menu);
164159
$menuNode->setLabel('Request Content Identity Voter');
165160
$menuNode->setName('request-content-identity-voter');
166-
$menuNode->setContent($route);
161+
$menuNode->setContent($content);
167162
$manager->persist($menuNode);
168163

169164
$menuNode = new MenuNode;

Tests/Resources/Document/Content.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ class Content implements MenuNodeReferrersInterface, RouteReferrersReadInterface
4545
*/
4646
protected $menuNodes;
4747

48+
/**
49+
* @PHPCRODM\Referrers(
50+
* referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route",
51+
* referencedBy="content"
52+
* )
53+
*/
54+
protected $routes;
55+
4856
public function __construct()
4957
{
5058
$this->menuNodes = new ArrayCollection();
59+
$this->routes = new ArrayCollection();
5160
}
5261

5362
public function getId()
@@ -80,13 +89,21 @@ public function addMenuNode(NodeInterface $menuNode)
8089
$this->menuNodes->add($menuNode);
8190
}
8291

92+
public function addRoute($route)
93+
{
94+
$this->routes->add($route);
95+
}
96+
97+
8398
public function removeMenuNode(NodeInterface $menuNode)
8499
{
85100
$this->menuNodes->remove($menuNode);
86101
}
87102

88103
public function getRoutes()
89104
{
90-
return array(new Route('http://www.example.com/content'));
105+
foreach ($this->routes as $route) {
106+
}
107+
return $this->routes;
91108
}
92109
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
<nav class="side">
22
{{ knp_menu_render('side-menu') }}
33
</nav>
4+
<h3>Test Links</h3>
5+
<ul>
6+
<li><a href="{{ path('current_menu_item_request_content_identity') }}">Test Request Content Identity Voter</a></li>
7+
</ul>
8+
<h3>Request Content</h3>
9+
{% if content is defined %}
10+
<table>
11+
<tr>
12+
<th>Title</th>
13+
<td>{{ content.title }}</td>
14+
</tr>
15+
<tr>
16+
<th>URI</th>
17+
<td>{{ path(content) }}</td>
18+
</tr>
19+
</table>
20+
{% else %}
21+
<p>
22+
No content
23+
</p>
24+
{% endif %}

Tests/Resources/app/Resources/views/tests/cmi/requestContent.html.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% extends "::layout.html.twig" %}
22
{% block content %}
33
{% include "::tests/cmi/_sideMenu.html.twig" %}
4-
<h1>Request Content</h1>
5-
This is the content: {{ content.title }}
64
<p>
75
This page does NOT use the content identity voter because the URI of the request matches that of the content.
86
</p>

Tests/Resources/app/Resources/views/tests/cmi/requestContentVoterActive.html.twig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{% extends "::layout.html.twig" %}
22
{% block content %}
33
{% include "::tests/cmi/_sideMenu.html.twig" %}
4-
<h1>Request Content</h1>
5-
This is the content: {{ content.title }}
4+
<h1>Content Identity Test</h1>
65
<p>
76
The content identity voter should now be in use and the "Request Content Identity" menu item should be hilighted.
87
</p>

Tests/Resources/app/config/cmf_menu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ cmf_menu:
1010
enabled: true
1111
use_sonata_admin: true
1212
menu_basepath: /test/menus
13+
voters:
14+
content_identity: ~
1315

1416
cmf_routing:
1517
dynamic:

0 commit comments

Comments
 (0)