3
3
namespace Symfony \Cmf \Bundle \RoutingBundle \Tests \Functional \Controller ;
4
4
5
5
use PHPCR \Util \PathHelper ;
6
- use Symfony \Cmf \Bundle \RoutingBundle \Tests \Functional \BaseTestCase ;
7
6
8
7
use Symfony \Component \HttpFoundation \RedirectResponse ;
9
8
10
9
use Symfony \Cmf \Bundle \RoutingBundle \Doctrine \Phpcr \Route ;
11
10
use Symfony \Cmf \Bundle \RoutingBundle \Doctrine \Phpcr \RedirectRoute ;
12
11
use Symfony \Cmf \Bundle \RoutingBundle \Controller \RedirectController ;
12
+ use Symfony \Cmf \Bundle \RoutingBundle \Tests \Functional \BaseTestCase ;
13
+ use PHPCR \Util \NodeHelper ;
13
14
14
15
class RedirectControllerTest extends BaseTestCase
15
16
{
@@ -18,32 +19,35 @@ class RedirectControllerTest extends BaseTestCase
18
19
/**
19
20
* @var \Symfony\Cmf\Bundle\RoutingBundle\Controller\RedirectController
20
21
*/
21
- protected static $ controller ;
22
+ protected $ controller ;
22
23
23
- public static function setupBeforeClass ( array $ options = array (), $ routebase = null )
24
+ public function setUp ( )
24
25
{
25
- parent ::setupBeforeClass (array (), PathHelper::getNodeName (self ::ROUTE_ROOT ));
26
- $ router = self ::$ kernel ->getContainer ()->get ('router ' );
27
- self ::$ controller = new RedirectController ($ router );
26
+ parent ::setUp ();
27
+ $ this ->db ('PHPCR ' )->createTestNode ();
28
+ $ this ->createRoute (self ::ROUTE_ROOT );
29
+
30
+ $ router = $ this ->getContainer ()->get ('router ' );
31
+ $ this ->controller = new RedirectController ($ router );
28
32
}
29
33
30
34
public function testRedirectUri ()
31
35
{
32
- $ root = self :: $ dm ->find (null , self ::ROUTE_ROOT );
36
+ $ root = $ this -> getDm () ->find (null , self ::ROUTE_ROOT );
33
37
34
38
$ redirect = new RedirectRoute ;
35
39
$ redirect ->setPosition ($ root , 'redirectUri ' );
36
40
$ redirect ->setUri ('http://example.com/test-url ' );
37
41
$ redirect ->setParameters (array ('test ' => 7 )); // parameters should be ignored in this case
38
42
$ redirect ->setPermanent (true );
39
- self :: $ dm ->persist ($ redirect );
43
+ $ this -> getDm () ->persist ($ redirect );
40
44
41
- self :: $ dm ->flush ();
45
+ $ this -> getDm () ->flush ();
42
46
43
- self :: $ dm ->clear ();
47
+ $ this -> getDm () ->clear ();
44
48
45
- $ redirect = self :: $ dm ->find (null , self ::ROUTE_ROOT .'/redirectUri ' );
46
- $ response = self :: $ controller ->redirectAction ($ redirect );
49
+ $ redirect = $ this -> getDm () ->find (null , self ::ROUTE_ROOT .'/redirectUri ' );
50
+ $ response = $ this -> controller ->redirectAction ($ redirect );
47
51
48
52
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\RedirectResponse ' , $ response );
49
53
$ this ->assertSame (301 , $ response ->getStatusCode ());
@@ -52,25 +56,27 @@ public function testRedirectUri()
52
56
53
57
public function testRedirectContent ()
54
58
{
55
- $ root = self ::$ dm ->find (null , self ::ROUTE_ROOT );
59
+ $ content = $ this ->createContent ('/test/content ' );
60
+
61
+ $ root = $ this ->getDm ()->find (null , self ::ROUTE_ROOT );
56
62
57
63
$ route = new Route ;
58
- $ route ->setContent ($ root ); // this happens to be a referenceable node
64
+ $ route ->setContent ($ content );
59
65
$ route ->setPosition ($ root , 'testroute ' );
60
- self :: $ dm ->persist ($ route );
66
+ $ this -> getDm () ->persist ($ route );
61
67
62
68
$ redirect = new RedirectRoute ;
63
69
$ redirect ->setPosition ($ root , 'redirectContent ' );
64
70
$ redirect ->setRouteTarget ($ route );
65
71
$ redirect ->setParameters (array ('test ' => 'content ' ));
66
- self :: $ dm ->persist ($ redirect );
72
+ $ this -> getDm () ->persist ($ redirect );
67
73
68
- self :: $ dm ->flush ();
74
+ $ this -> getDm () ->flush ();
69
75
70
- self :: $ dm ->clear ();
76
+ $ this -> getDm () ->clear ();
71
77
72
- $ redirect = self :: $ dm ->find (null , self ::ROUTE_ROOT .'/redirectContent ' );
73
- $ response = self :: $ controller ->redirectAction ($ redirect );
78
+ $ redirect = $ this -> getDm () ->find (null , self ::ROUTE_ROOT .'/redirectContent ' );
79
+ $ response = $ this -> controller ->redirectAction ($ redirect );
74
80
75
81
$ this ->assertInstanceOf ('Symfony \\Component \\HttpFoundation \\RedirectResponse ' , $ response );
76
82
$ this ->assertSame (302 , $ response ->getStatusCode ());
@@ -79,21 +85,20 @@ public function testRedirectContent()
79
85
80
86
public function testRedirectName ()
81
87
{
82
- $ root = self :: $ dm ->find (null , self ::ROUTE_ROOT );
88
+ $ root = $ this -> getDm () ->find (null , self ::ROUTE_ROOT );
83
89
84
90
$ redirect = new RedirectRoute ;
85
91
$ redirect ->setPosition ($ root , 'redirectName ' );
86
92
$ redirect ->setRouteName ('symfony_route ' );
87
93
$ redirect ->setParameters (array ('param ' =>7 )); // parameters should be ignored in this case
88
- self ::$ dm ->persist ($ redirect );
89
-
90
- self ::$ dm ->flush ();
94
+ $ this ->getDm ()->persist ($ redirect );
91
95
92
- self :: $ dm -> clear ();
96
+ $ this -> getDm ()-> flush ();
93
97
94
- $ redirect = self ::$ dm ->find (null , self ::ROUTE_ROOT .'/redirectName ' );
95
- $ response = self ::$ controller ->redirectAction ($ redirect );
98
+ $ this ->getDm ()->clear ();
96
99
100
+ $ redirect = $ this ->getDm ()->find (null , self ::ROUTE_ROOT .'/redirectName ' );
101
+ $ response = $ this ->controller ->redirectAction ($ redirect );
97
102
$ this ->assertInstanceOf ('Symfony \\Component \\HttpFoundation \\RedirectResponse ' , $ response );
98
103
$ this ->assertSame (302 , $ response ->getStatusCode ());
99
104
$ this ->assertSame ('http://localhost/symfony_route_test?param=7 ' , $ response ->getTargetUrl ());
0 commit comments