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

Commit 7746983

Browse files
committed
Added web test cases
1 parent c59f4ef commit 7746983

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

Tests/WebTest/Voter/BaseTestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\MenuBundle\Tests\WebTest\Voter;
4+
5+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as BaseBaseTestCase;
6+
7+
abstract class BaseTestCase extends BaseBaseTestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->db('PHPCR')->loadFixtures(array(
12+
'Symfony\Cmf\Bundle\MenuBundle\Tests\Resources\DataFixtures\PHPCR\LoadMenuData',
13+
));
14+
$this->client = $this->createClient();
15+
}
16+
17+
protected function assertCurrentItem($crawler, $title)
18+
{
19+
$res = $crawler->filter('li.current:contains("'.$title.'")')->count();
20+
$this->assertEquals(1, $res, 'Failed matching current menu item "'.$title.'", got '.$crawler->html());
21+
}
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\MenuBundle\Tests\WebTest\Voter;
4+
5+
class RequestContentIdentityTest extends BaseTestCase
6+
{
7+
public function testRequestContentIdentityVoterNoOp()
8+
{
9+
// this test will not invoke the content identity voter because
10+
// the URL of the content is the same as the URL for the menu item anyway
11+
// so it works by default
12+
$crawler = $this->client->request('GET', '/contents/content-1');
13+
$res = $this->client->getResponse();
14+
$this->assertCurrentItem($crawler, 'Request Content Identity Voter');
15+
$this->assertEquals(200, $res->getStatusCode());
16+
}
17+
18+
public function testRequestContentIdentityVoter()
19+
{
20+
// this test DOES invoke the RequestContentIdentity voter because
21+
// the URL is different from that of the content, so if the menu item
22+
// is highlighted, it is because the voter is working.
23+
$crawler = $this->client->request('GET', '/cmi/request_content_identity');
24+
$res = $this->client->getResponse();
25+
$this->assertCurrentItem($crawler, 'Request Content Identity Voter');
26+
$this->assertEquals(200, $res->getStatusCode());
27+
}
28+
}
29+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\MenuBundle\Tests\WebTest\Voter;
4+
5+
class RequestContentParentIdentityTest extends BaseTestCase
6+
{
7+
public function testRequestContentParentIdentityNoOp()
8+
{
9+
// this test loads the "blog" page which corresponds directly
10+
// to the "Request Content PArent Identity" menu item and so DOES NOT invoke
11+
// the voter.
12+
$crawler = $this->client->request('GET', '/blog');
13+
$this->assertCurrentItem($crawler, 'Request Parent Content Identity Voter');
14+
$res = $this->client->getResponse();
15+
$this->assertEquals(200, $res->getStatusCode());
16+
}
17+
18+
public function testRequestContentParentIdentity()
19+
{
20+
// this test shows an post whose parent is the blog content referenced in teh menu item
21+
$crawler = $this->client->request('GET', '/blog/my-post');
22+
$res = $this->client->getResponse();
23+
$this->assertCurrentItem($crawler, 'Request Parent Content Identity Voter');
24+
$this->assertEquals(200, $res->getStatusCode());
25+
}
26+
}
27+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\MenuBundle\Tests\WebTest\Voter;
4+
5+
class UriPrefixVoterTest extends BaseTestCase
6+
{
7+
public function testUriPrefixArticlesHomepage()
8+
{
9+
// this test loads the "articles" page which corresponds directly
10+
// to the "URI Prefix Voter" menu item and so DOES NOT invoke
11+
// the voter.
12+
$crawler = $this->client->request('GET', '/articles');
13+
$res = $this->client->getResponse();
14+
$this->assertCurrentItem($crawler, 'URI Prefix Voter');
15+
$this->assertEquals(200, $res->getStatusCode());
16+
}
17+
18+
public function testUriPrefixArticle()
19+
{
20+
// this test shows an article which contains the prefix in the "/articles" route
21+
// as currentUriPrefix, and so the Voter IS used and the item should be selected.
22+
$crawler = $this->client->request('GET', '/articles/some-category/article-1');
23+
$res = $this->client->getResponse();
24+
$this->assertCurrentItem($crawler, 'URI Prefix Voter');
25+
$this->assertEquals(200, $res->getStatusCode());
26+
}
27+
}
28+

0 commit comments

Comments
 (0)