Skip to content

Commit 0fb73ac

Browse files
committed
Most tests pass, 95% done ...
1 parent 0f4c42d commit 0fb73ac

File tree

11 files changed

+178
-176
lines changed

11 files changed

+178
-176
lines changed

Tests/Functional/BaseTestCase.php

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,27 @@
55
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
66

77
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8-
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase ;
8+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as ComponentBaseTestCase;
9+
use PHPCR\Util\PathHelper;
910

10-
class BaseTestCase extends BaseTestCase
11+
class BaseTestCase extends ComponentBaseTestCase
1112
{
12-
/**
13-
* @var \Doctrine\ODM\PHPCR\DocumentManager
14-
*/
15-
protected static $dm;
16-
17-
protected static function createKernel(array $options = array())
13+
public function getDm()
1814
{
19-
return new AppKernel(
20-
isset($options['config']) ? $options['config'] : 'default.yml'
21-
);
15+
$dm = $this->db('PHPCR')->getOm();
16+
return $dm;
2217
}
2318

24-
/**
25-
* careful: the kernel is shut down after the first test, if you need the
26-
* kernel, recreate it.
27-
*
28-
* @param array $options passed to self:.createKernel
29-
* @param string $routebase base name for routes under /test to use
30-
*/
31-
public static function setupBeforeClass(array $options = array(), $routebase = null)
19+
public function createRoute($path)
3220
{
33-
self::$kernel = self::createKernel($options);
34-
self::$kernel->init();
35-
self::$kernel->boot();
36-
37-
self::$dm = self::$kernel->getContainer()->get('doctrine_phpcr.odm.document_manager');
38-
39-
if (null == $routebase) {
40-
return;
41-
}
42-
43-
$session = self::$kernel->getContainer()->get('doctrine_phpcr.session');
44-
if ($session->nodeExists("/test/$routebase")) {
45-
$session->getNode("/test/$routebase")->remove();
46-
}
47-
if (! $session->nodeExists('/test')) {
48-
$session->getRootNode()->addNode('test', 'nt:unstructured');
49-
}
50-
$session->save();
51-
52-
$root = self::$dm->find(null, '/test');
21+
$parentPath = PathHelper::getParentPath($path);
22+
$parent = $this->getDm()->find(null, $parentPath);
23+
$name = PathHelper::getNodeName($path);
5324
$route = new Route;
54-
$route->setPosition($root, $routebase);
55-
self::$dm->persist($route);
56-
self::$dm->flush();
25+
$route->setPosition($parent, $name);
26+
$this->getDm()->persist($route);
27+
$this->getDm()->flush();
28+
29+
return $route;
5730
}
5831
}

Tests/Functional/Controller/RedirectControllerTest.php

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Controller;
44

55
use PHPCR\Util\PathHelper;
6-
use Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\BaseTestCase;
76

87
use Symfony\Component\HttpFoundation\RedirectResponse;
98

109
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
1110
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute;
1211
use Symfony\Cmf\Bundle\RoutingBundle\Controller\RedirectController;
12+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
13+
use Symfony\Cmf\Component\Testing\Document\Content;
14+
use PHPCR\Util\NodeHelper;
1315

1416
class RedirectControllerTest extends BaseTestCase
1517
{
@@ -18,32 +20,36 @@ class RedirectControllerTest extends BaseTestCase
1820
/**
1921
* @var \Symfony\Cmf\Bundle\RoutingBundle\Controller\RedirectController
2022
*/
21-
protected static $controller;
23+
protected $controller;
2224

23-
public static function setupBeforeClass(array $options = array(), $routebase = null)
25+
public function setUp()
2426
{
25-
parent::setupBeforeClass(array(), PathHelper::getNodeName(self::ROUTE_ROOT));
26-
$router = self::$kernel->getContainer()->get('router');
27-
self::$controller = new RedirectController($router);
27+
parent::setUp();
28+
$this->db('PHPCR')->createTestNode();
29+
$this->db('PHPCR')->createPath(self::ROUTE_ROOT);
30+
$this->dm = $this->db('PHPCR')->getOm();
31+
32+
$router = $this->getContainer()->get('router');
33+
$this->controller = new RedirectController($router);
2834
}
2935

3036
public function testRedirectUri()
3137
{
32-
$root = self::$dm->find(null, self::ROUTE_ROOT);
38+
$root = $this->dm->find(null, self::ROUTE_ROOT);
3339

3440
$redirect = new RedirectRoute;
3541
$redirect->setPosition($root, 'redirectUri');
3642
$redirect->setUri('http://example.com/test-url');
3743
$redirect->setParameters(array('test' => 7)); // parameters should be ignored in this case
3844
$redirect->setPermanent(true);
39-
self::$dm->persist($redirect);
45+
$this->dm->persist($redirect);
4046

41-
self::$dm->flush();
47+
$this->dm->flush();
4248

43-
self::$dm->clear();
49+
$this->dm->clear();
4450

45-
$redirect = self::$dm->find(null, self::ROUTE_ROOT.'/redirectUri');
46-
$response = self::$controller->redirectAction($redirect);
51+
$redirect = $this->dm->find(null, self::ROUTE_ROOT.'/redirectUri');
52+
$response = $this->controller->redirectAction($redirect);
4753

4854
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
4955
$this->assertSame(301, $response->getStatusCode());
@@ -52,25 +58,31 @@ public function testRedirectUri()
5258

5359
public function testRedirectContent()
5460
{
55-
$root = self::$dm->find(null, self::ROUTE_ROOT);
61+
$root = $this->dm->find(null, self::ROUTE_ROOT);
62+
63+
$content = new Content;
64+
$content->setId('/test/content');
65+
$content->setTitle('Foo Content');
66+
$this->dm->persist($content);
67+
$this->dm->flush();
5668

5769
$route = new Route;
58-
$route->setContent($root); // this happens to be a referenceable node
70+
$route->setContent($content);
5971
$route->setPosition($root, 'testroute');
60-
self::$dm->persist($route);
72+
$this->dm->persist($route);
6173

6274
$redirect = new RedirectRoute;
6375
$redirect->setPosition($root, 'redirectContent');
6476
$redirect->setRouteTarget($route);
6577
$redirect->setParameters(array('test' => 'content'));
66-
self::$dm->persist($redirect);
78+
$this->dm->persist($redirect);
6779

68-
self::$dm->flush();
80+
$this->dm->flush();
6981

70-
self::$dm->clear();
82+
$this->dm->clear();
7183

72-
$redirect = self::$dm->find(null, self::ROUTE_ROOT.'/redirectContent');
73-
$response = self::$controller->redirectAction($redirect);
84+
$redirect = $this->dm->find(null, self::ROUTE_ROOT.'/redirectContent');
85+
$response = $this->controller->redirectAction($redirect);
7486

7587
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
7688
$this->assertSame(302, $response->getStatusCode());
@@ -79,21 +91,20 @@ public function testRedirectContent()
7991

8092
public function testRedirectName()
8193
{
82-
$root = self::$dm->find(null, self::ROUTE_ROOT);
94+
$root = $this->dm->find(null, self::ROUTE_ROOT);
8395

8496
$redirect = new RedirectRoute;
8597
$redirect->setPosition($root, 'redirectName');
8698
$redirect->setRouteName('symfony_route');
8799
$redirect->setParameters(array('param'=>7)); // parameters should be ignored in this case
88-
self::$dm->persist($redirect);
89-
90-
self::$dm->flush();
100+
$this->dm->persist($redirect);
91101

92-
self::$dm->clear();
102+
$this->dm->flush();
93103

94-
$redirect = self::$dm->find(null, self::ROUTE_ROOT.'/redirectName');
95-
$response = self::$controller->redirectAction($redirect);
104+
$this->dm->clear();
96105

106+
$redirect = $this->dm->find(null, self::ROUTE_ROOT.'/redirectName');
107+
$response = $this->controller->redirectAction($redirect);
97108
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
98109
$this->assertSame(302, $response->getStatusCode());
99110
$this->assertSame('http://localhost/symfony_route_test?param=7', $response->getTargetUrl());

Tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,47 @@
55
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
66
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute;
77
use PHPCR\Util\PathHelper;
8-
98
use Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\BaseTestCase;
9+
use Symfony\Cmf\Component\Testing\Document\Content;
1010

1111
class RedirectRouteTest extends BaseTestCase
1212
{
1313
const ROUTE_ROOT = '/test/redirectroute';
1414

15-
public static function setupBeforeClass(array $options = array(), $routebase = null)
15+
public function setUp()
1616
{
17-
parent::setupBeforeClass(array(), PathHelper::getNodeName(self::ROUTE_ROOT));
17+
parent::setUp();
18+
$this->db('PHPCR')->createTestNode();
19+
$this->createRoute(self::ROUTE_ROOT);
1820
}
1921

2022
public function testRedirectDoctrine()
2123
{
22-
$root = self::$dm->find(null, self::ROUTE_ROOT);
24+
$root = $this->getDm()->find(null, self::ROUTE_ROOT);
25+
26+
$content = new Content;
27+
$content->setId('/test/content');
28+
$content->setTitle('Foo Content');
29+
$this->getDm()->persist($content);
30+
$this->getDm()->flush();
2331

2432
$route = new Route;
25-
$route->setContent($root); // this happens to be a referenceable node
33+
$route->setContent($content);
2634
$route->setPosition($root, 'testroute');
27-
self::$dm->persist($route);
35+
$this->getDm()->persist($route);
2836

2937
$redirect = new RedirectRoute;
3038
$redirect->setPosition($root, 'redirect');
3139
$redirect->setRouteTarget($route);
3240
$redirect->setDefault('test', 'toast');
33-
self::$dm->persist($redirect);
41+
$this->getDm()->persist($redirect);
3442

35-
self::$dm->flush();
43+
$this->getDm()->flush();
3644

37-
self::$dm->clear();
45+
$this->getDm()->clear();
3846

39-
$route = self::$dm->find(null, self::ROUTE_ROOT.'/testroute');
40-
$redirect = self::$dm->find(null, self::ROUTE_ROOT.'/redirect');
47+
$route = $this->getDm()->find(null, self::ROUTE_ROOT.'/testroute');
48+
$redirect = $this->getDm()->find(null, self::ROUTE_ROOT.'/redirect');
4149

4250
$this->assertInstanceOf('Symfony\\Cmf\\Component\\Routing\\RedirectRouteInterface', $redirect);
4351
$this->assertSame($redirect, $redirect->getContent());

Tests/Functional/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,39 @@ class RouteRepositoryTest extends BaseTestCase
1616
const ROUTE_ROOT = '/test/routing';
1717

1818
/** @var RouteProvider */
19-
private static $repository;
19+
private $repository;
2020

21-
public static function setupBeforeClass(array $options = array(), $routebase = null)
21+
public function setUp()
2222
{
23-
parent::setupBeforeClass(array(), PathHelper::getNodeName(self::ROUTE_ROOT));
24-
self::$repository = self::$kernel->getContainer()->get('cmf_routing.route_provider');
23+
parent::setUp();
24+
$this->db('PHPCR')->createTestNode();
25+
$this->createRoute(self::ROUTE_ROOT);
26+
$this->repository = $this->getContainer()->get('cmf_routing.route_provider');
2527
}
2628

2729
public function testGetRouteCollectionForRequest()
2830
{
2931
$route = new Route;
30-
$root = self::$dm->find(null, self::ROUTE_ROOT);
32+
$root = $this->getDm()->find(null, self::ROUTE_ROOT);
3133

3234
$route->setPosition($root, 'testroute');
33-
self::$dm->persist($route);
35+
$this->getDm()->persist($route);
3436

3537
// smuggle a non-route thing into the repository
3638
$noroute = new Generic;
3739
$noroute->setParent($route);
3840
$noroute->setNodename('noroute');
39-
self::$dm->persist($noroute);
41+
$this->getDm()->persist($noroute);
4042

4143
$childroute = new Route;
4244
$childroute->setPosition($noroute, 'child');
43-
self::$dm->persist($childroute);
45+
$this->getDm()->persist($childroute);
4446

45-
self::$dm->flush();
47+
$this->getDm()->flush();
4648

47-
self::$dm->clear();
49+
$this->getDm()->clear();
4850

49-
$routes = self::$repository->getRouteCollectionForRequest(Request::create('/testroute/noroute/child'));
51+
$routes = $this->repository->getRouteCollectionForRequest(Request::create('/testroute/noroute/child'));
5052
$this->assertCount(3, $routes);
5153

5254
foreach ($routes as $route) {
@@ -56,13 +58,13 @@ public function testGetRouteCollectionForRequest()
5658

5759
public function testFindNophpcrUrl()
5860
{
59-
$collection = self::$repository->getRouteCollectionForRequest(Request::create(':///'));
61+
$collection = $this->repository->getRouteCollectionForRequest(Request::create(':///'));
6062
$this->assertInstanceOf('Symfony\\Component\\Routing\\RouteCollection', $collection);
6163
$this->assertCount(0, $collection);
6264
}
6365

6466
public function testSetPrefix()
6567
{
66-
self::$repository->setPrefix(self::ROUTE_ROOT);
68+
$this->repository->setPrefix(self::ROUTE_ROOT);
6769
}
6870
}

0 commit comments

Comments
 (0)