Skip to content

Commit 41fc3a1

Browse files
committed
Merge pull request #135 from dantleech/admin_tests
Added Admin tests and fixed bug
2 parents 43eff7c + 67494d9 commit 41fc3a1

File tree

5 files changed

+165
-3
lines changed

5 files changed

+165
-3
lines changed

Admin/RedirectRouteAdmin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RedirectRouteAdmin extends Admin
1414
/**
1515
* work around https://github.com/sonata-project/SonataAdminBundle/pull/1472
1616
*/
17-
protected $baseRouteName = 'cmf_routing';
17+
protected $baseRouteName = 'cmf_routing_redirectroute';
1818

1919
/**
2020
* work around https://github.com/sonata-project/SonataAdminBundle/pull/1472

Admin/RouteAdmin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RouteAdmin extends Admin
1818
/**
1919
* work around https://github.com/sonata-project/SonataAdminBundle/pull/1472
2020
*/
21-
protected $baseRouteName = 'cmf_routing';
21+
protected $baseRouteName = 'cmf_routing_route';
2222

2323
/**
2424
* work around https://github.com/sonata-project/SonataAdminBundle/pull/1472
@@ -71,7 +71,7 @@ protected function configureFormFields(FormMapper $formMapper)
7171
$formMapper
7272
->with('form.group_general')
7373
->add('variablePattern', 'text', array('required' => false))
74-
->add('routeContent', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot))
74+
->add('content', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot))
7575
->add('defaults', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForDefaults()))
7676
->end();
7777
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Resources\DataFixtures\PHPCR;
4+
5+
use Doctrine\Common\DataFixtures\FixtureInterface;
6+
use Doctrine\Common\Persistence\ObjectManager;
7+
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
8+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
9+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute;
10+
use Doctrine\ODM\PHPCR\Document\Generic;
11+
12+
class LoadRouteData implements FixtureInterface, DependentFixtureInterface
13+
{
14+
public function getDependencies()
15+
{
16+
return array(
17+
'Symfony\Cmf\Component\Testing\DataFixtures\PHPCR\LoadBaseData',
18+
);
19+
}
20+
21+
public function load(ObjectManager $manager)
22+
{
23+
$root = $manager->find(null, '/test');
24+
$parent = new Generic;
25+
$parent->setParent($root);
26+
$parent->setNodename('routing');
27+
$manager->persist($parent);
28+
29+
$route = new Route;
30+
$route->setParent($parent);
31+
$route->setName('route-1');
32+
$manager->persist($route);
33+
34+
$redirectRoute = new RedirectRoute;
35+
$redirectRoute->setParent($parent);
36+
$redirectRoute->setName('redirect-route-1');
37+
$manager->persist($redirectRoute);
38+
39+
$manager->flush();
40+
}
41+
}
42+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\WebTest\Admin\RedirectRouteNodeAdminTest;
4+
5+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
6+
7+
class RedirectRouteAdminTest extends BaseTestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->db('PHPCR')->loadFixtures(array(
12+
'Symfony\Cmf\Bundle\RoutingBundle\Tests\Resources\DataFixtures\Phpcr\LoadRouteData',
13+
));
14+
$this->client = $this->createClient();
15+
}
16+
17+
public function testRedirectRouteList()
18+
{
19+
$crawler = $this->client->request('GET', '/admin/cmf/routing/redirectroute/list');
20+
$res = $this->client->getResponse();
21+
$this->assertEquals(200, $res->getStatusCode());
22+
$this->assertCount(1, $crawler->filter('html:contains("redirect-route-1")'));
23+
}
24+
25+
public function testRedirectRouteEdit()
26+
{
27+
$crawler = $this->client->request('GET', '/admin/cmf/routing/redirectroute/test/routing/redirect-route-1/edit');
28+
$res = $this->client->getResponse();
29+
$this->assertEquals(200, $res->getStatusCode());
30+
$this->assertCount(1, $crawler->filter('input[value="redirect-route-1"]'));
31+
}
32+
33+
public function testRedirectRouteShow()
34+
{
35+
$this->markTestSkipped('Not implemented yet.');
36+
}
37+
38+
public function testRedirectRouteCreate()
39+
{
40+
$crawler = $this->client->request('GET', '/admin/cmf/routing/redirectroute/create');
41+
$res = $this->client->getResponse();
42+
$this->assertEquals(200, $res->getStatusCode());
43+
44+
$button = $crawler->selectButton('Create');
45+
$form = $button->form();
46+
$node = $form->getFormNode();
47+
$actionUrl = $node->getAttribute('action');
48+
$uniqId = substr(strchr($actionUrl, '='), 1);
49+
50+
$form[$uniqId.'[parent]'] = '/test/routing';
51+
$form[$uniqId.'[name]'] = 'foo-test';
52+
53+
$this->client->submit($form);
54+
$res = $this->client->getResponse();
55+
56+
// If we have a 302 redirect, then all is well
57+
$this->assertEquals(302, $res->getStatusCode());
58+
}
59+
}
60+

Tests/WebTest/RouteAdminTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\WebTest\Admin\MenuNodeAdminTest;
4+
5+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
6+
7+
class RouteAdminTest extends BaseTestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->db('PHPCR')->loadFixtures(array(
12+
'Symfony\Cmf\Bundle\RoutingBundle\Tests\Resources\DataFixtures\Phpcr\LoadRouteData',
13+
));
14+
$this->client = $this->createClient();
15+
}
16+
17+
public function testMenuList()
18+
{
19+
$crawler = $this->client->request('GET', '/admin/cmf/routing/route/list');
20+
$res = $this->client->getResponse();
21+
$this->assertEquals(200, $res->getStatusCode());
22+
$this->assertCount(1, $crawler->filter('html:contains("route-1")'));
23+
}
24+
25+
public function testMenuEdit()
26+
{
27+
$crawler = $this->client->request('GET', '/admin/cmf/routing/route/test/routing/route-1/edit');
28+
$res = $this->client->getResponse();
29+
$this->assertEquals(200, $res->getStatusCode());
30+
$this->assertCount(1, $crawler->filter('input[value="route-1"]'));
31+
}
32+
33+
public function testMenuShow()
34+
{
35+
$this->markTestSkipped('Not implemented yet.');
36+
}
37+
38+
public function testMenuCreate()
39+
{
40+
$crawler = $this->client->request('GET', '/admin/cmf/routing/route/create');
41+
$res = $this->client->getResponse();
42+
$this->assertEquals(200, $res->getStatusCode());
43+
44+
$button = $crawler->selectButton('Create');
45+
$form = $button->form();
46+
$node = $form->getFormNode();
47+
$actionUrl = $node->getAttribute('action');
48+
$uniqId = substr(strchr($actionUrl, '='), 1);
49+
50+
$form[$uniqId.'[parent]'] = '/test/routing';
51+
$form[$uniqId.'[name]'] = 'foo-test';
52+
53+
$this->client->submit($form);
54+
$res = $this->client->getResponse();
55+
56+
// If we have a 302 redirect, then all is well
57+
$this->assertEquals(302, $res->getStatusCode());
58+
}
59+
}
60+

0 commit comments

Comments
 (0)