@@ -66,6 +66,7 @@ public function testGetRouteByName()
6666 $ routeProvider = new RouteProvider ($ this ->managerRegistry );
6767 $ routeProvider ->setManagerName ('default ' );
6868
69+ $ routeProvider ->setPrefix ('/cms/routes/ ' );
6970 $ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
7071
7172 $ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
@@ -92,7 +93,7 @@ public function testGetRouteByNameNotFound()
9293
9394 $ routeProvider = new RouteProvider ($ this ->managerRegistry );
9495 $ routeProvider ->setManagerName ('default ' );
95-
96+ $ routeProvider -> setPrefix ( ' /cms/routes/ ' );
9697 $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
9798 }
9899
@@ -116,6 +117,112 @@ public function testGetRouteByNameNoRoute()
116117
117118 $ routeProvider = new RouteProvider ($ this ->managerRegistry );
118119 $ routeProvider ->setManagerName ('default ' );
120+ $ routeProvider ->setPrefix ('/cms/routes/ ' );
121+ $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
122+ }
123+
124+ /**
125+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
126+ */
127+ public function testGetRouteByNameInvalidRoute ()
128+ {
129+ $ this ->objectManager
130+ ->expects ($ this ->never ())
131+ ->method ('find ' )
132+ ;
133+
134+ $ this ->managerRegistry
135+ ->expects ($ this ->any ())
136+ ->method ('getManager ' )
137+ ->will ($ this ->returnValue ($ this ->objectManager ))
138+ ;
139+
140+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
141+ $ routeProvider ->setManagerName ('default ' );
142+
143+ $ routeProvider ->setPrefix ('/cms/routes ' );
144+
145+ $ routeProvider ->getRouteByName ('invalid_route ' );
146+ }
147+
148+ public function testGetRouteByNameIdPrefixEmptyString ()
149+ {
150+
151+ $ this ->route
152+ ->expects ($ this ->any ())
153+ ->method ('getPath ' )
154+ ->will ($ this ->returnValue ('/cms/routes/test-route ' ))
155+ ;
156+
157+ $ this ->objectManager
158+ ->expects ($ this ->any ())
159+ ->method ('find ' )
160+ ->with (null , '/cms/routes/test-route ' )
161+ ->will ($ this ->returnValue ($ this ->route ))
162+ ;
163+
164+ $ this ->managerRegistry
165+ ->expects ($ this ->any ())
166+ ->method ('getManager ' )
167+ ->will ($ this ->returnValue ($ this ->objectManager ))
168+ ;
169+
170+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
171+ $ routeProvider ->setManagerName ('default ' );
172+
173+ $ routeProvider ->setPrefix ('' );
174+ $ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
175+
176+ $ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
177+ $ this ->assertEquals ('/cms/routes/test-route ' , $ foundRoute ->getPath ());
178+ }
179+
180+
181+ /**
182+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
183+ */
184+ public function testGetRouteByNameNotFoundIdPrefixEmptyString ()
185+ {
186+ $ this ->objectManager
187+ ->expects ($ this ->any ())
188+ ->method ('find ' )
189+ ->with (null , '/cms/routes/test-route ' )
190+ ->will ($ this ->returnValue (null ))
191+ ;
192+
193+ $ this ->managerRegistry
194+ ->expects ($ this ->any ())
195+ ->method ('getManager ' )
196+ ->will ($ this ->returnValue ($ this ->objectManager ))
197+ ;
198+
199+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
200+ $ routeProvider ->setManagerName ('default ' );
201+ $ routeProvider ->setPrefix ('' );
202+ $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
203+ }
204+
205+ /**
206+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
207+ */
208+ public function testGetRouteByNameNoRoutePrefixEmptyString ()
209+ {
210+ $ this ->objectManager
211+ ->expects ($ this ->any ())
212+ ->method ('find ' )
213+ ->with (null , '/cms/routes/test-route ' )
214+ ->will ($ this ->returnValue ($ this ))
215+ ;
216+
217+ $ this ->managerRegistry
218+ ->expects ($ this ->any ())
219+ ->method ('getManager ' )
220+ ->will ($ this ->returnValue ($ this ->objectManager ))
221+ ;
222+
223+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
224+ $ routeProvider ->setManagerName ('default ' );
225+ $ routeProvider ->setPrefix ('' );
119226
120227 $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
121228 }
@@ -173,6 +280,8 @@ function ($name) use ($objectManagers) {
173280 $ routeProvider = new RouteProvider ($ this ->managerRegistry );
174281
175282 $ routeProvider ->setManagerName ('default ' );
283+ $ routeProvider ->setPrefix ('/cms/routes/ ' );
284+
176285 $ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
177286 $ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
178287 $ this ->assertEquals ('/cms/routes/test-route ' , $ foundRoute ->getPath ());
0 commit comments