@@ -25,12 +25,13 @@ public function setUp()
25
25
$ this ->repository = $ this ->getContainer ()->get ('cmf_routing.route_provider ' );
26
26
}
27
27
28
- public function testGetRouteCollectionForRequest ()
28
+ private function buildRoutes ()
29
29
{
30
- $ route = new Route ;
31
30
$ root = $ this ->getDm ()->find (null , self ::ROUTE_ROOT );
32
31
32
+ $ route = new Route ;
33
33
$ route ->setPosition ($ root , 'testroute ' );
34
+ $ route ->setDefault ('_format ' , 'html ' );
34
35
$ this ->getDm ()->persist ($ route );
35
36
36
37
// smuggle a non-route thing into the repository
@@ -41,24 +42,76 @@ public function testGetRouteCollectionForRequest()
41
42
42
43
$ childroute = new Route ;
43
44
$ childroute ->setPosition ($ noroute , 'child ' );
45
+ $ childroute ->setDefault ('_format ' , 'json ' );
44
46
$ this ->getDm ()->persist ($ childroute );
45
47
46
48
$ this ->getDm ()->flush ();
47
-
48
49
$ this ->getDm ()->clear ();
50
+ }
51
+
52
+ public function testGetRouteCollectionForRequest ()
53
+ {
54
+ $ this ->buildRoutes ();
49
55
50
56
$ routes = $ this ->repository ->getRouteCollectionForRequest (Request::create ('/testroute/noroute/child ' ));
51
57
$ this ->assertCount (3 , $ routes );
52
58
$ this ->assertContainsOnlyInstancesOf ('Symfony \\Cmf \\Component \\Routing \\RouteObjectInterface ' , $ routes );
59
+
60
+ $ routes = $ routes ->all ();
61
+ list ($ key , $ child ) = each ($ routes );
62
+ $ this ->assertEquals (self ::ROUTE_ROOT . '/testroute/noroute/child ' , $ key );
63
+ $ this ->assertEquals ('json ' , $ child ->getDefault ('_format ' ));
64
+ list ($ key , $ testroute ) = each ($ routes );
65
+ $ this ->assertEquals (self ::ROUTE_ROOT . '/testroute ' , $ key );
66
+ $ this ->assertEquals ('html ' , $ testroute ->getDefault ('_format ' ));
67
+ list ($ key , $ root ) = each ($ routes );
68
+ $ this ->assertEquals (self ::ROUTE_ROOT , $ key );
69
+ $ this ->assertNull ($ root ->getDefault ('_format ' ));
53
70
}
54
71
55
- public function testFindNophpcrUrl ()
72
+ public function testGetRouteCollectionForRequestFormat ()
73
+ {
74
+ $ this ->buildRoutes ();
75
+
76
+ $ routes = $ this ->repository ->getRouteCollectionForRequest (Request::create ('/testroute/noroute/child.html ' ));
77
+ $ this ->assertCount (3 , $ routes );
78
+ $ this ->assertContainsOnlyInstancesOf ('Symfony \\Cmf \\Component \\Routing \\RouteObjectInterface ' , $ routes );
79
+
80
+ $ routes = $ routes ->all ();
81
+ list ($ key , $ child ) = each ($ routes );
82
+ $ this ->assertEquals (self ::ROUTE_ROOT . '/testroute/noroute/child ' , $ key );
83
+ $ this ->assertEquals ('json ' , $ child ->getDefault ('_format ' ));
84
+ list ($ key , $ testroute ) = each ($ routes );
85
+ $ this ->assertEquals (self ::ROUTE_ROOT . '/testroute ' , $ key );
86
+ $ this ->assertEquals ('html ' , $ testroute ->getDefault ('_format ' ));
87
+ list ($ key , $ root ) = each ($ routes );
88
+ $ this ->assertEquals (self ::ROUTE_ROOT , $ key );
89
+ $ this ->assertEquals ('html ' , $ root ->getDefault ('_format ' ));
90
+ }
91
+
92
+ public function testGetRouteCollectionForRequestNophpcrUrl ()
56
93
{
57
94
$ collection = $ this ->repository ->getRouteCollectionForRequest (Request::create (':/// ' ));
58
95
$ this ->assertInstanceOf ('Symfony \\Component \\Routing \\RouteCollection ' , $ collection );
59
96
$ this ->assertCount (0 , $ collection );
60
97
}
61
98
99
+ public function testGetRoutesByNames ()
100
+ {
101
+ $ this ->buildRoutes ();
102
+
103
+ $ routeNames = array (
104
+ self ::ROUTE_ROOT . '/testroute/noroute/child ' ,
105
+ self ::ROUTE_ROOT . '/testroute/noroute ' ,
106
+ self ::ROUTE_ROOT . '/testroute '
107
+ );
108
+
109
+ $ routes = $ this ->repository ->getRoutesByNames ($ routeNames );
110
+ $ this ->assertCount (2 , $ routes );
111
+ $ this ->assertContainsOnlyInstancesOf ('Symfony \\Cmf \\Component \\Routing \\RouteObjectInterface ' , $ routes );
112
+ }
113
+
114
+
62
115
public function testSetPrefix ()
63
116
{
64
117
$ this ->repository ->setPrefix (self ::ROUTE_ROOT );
0 commit comments