@@ -66,6 +66,7 @@ public function testGetRouteByName()
66
66
$ routeProvider = new RouteProvider ($ this ->managerRegistry );
67
67
$ routeProvider ->setManagerName ('default ' );
68
68
69
+ $ routeProvider ->setPrefix ('/cms/routes/ ' );
69
70
$ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
70
71
71
72
$ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
@@ -92,7 +93,7 @@ public function testGetRouteByNameNotFound()
92
93
93
94
$ routeProvider = new RouteProvider ($ this ->managerRegistry );
94
95
$ routeProvider ->setManagerName ('default ' );
95
-
96
+ $ routeProvider -> setPrefix ( ' /cms/routes/ ' );
96
97
$ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
97
98
}
98
99
@@ -116,15 +117,120 @@ public function testGetRouteByNameNoRoute()
116
117
117
118
$ routeProvider = new RouteProvider ($ this ->managerRegistry );
118
119
$ routeProvider ->setManagerName ('default ' );
120
+ $ routeProvider ->setPrefix ('/cms/routes/ ' );
119
121
120
122
$ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
121
123
}
122
124
123
- public function testGetRoutesByNames ()
125
+ /**
126
+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
127
+ */
128
+ public function testGetRouteByNameInvalidRoute ()
124
129
{
125
- $ this ->markTestIncomplete ();
130
+ $ this ->objectManager
131
+ ->expects ($ this ->never ())
132
+ ->method ('find ' )
133
+ ;
134
+
135
+ $ this ->managerRegistry
136
+ ->expects ($ this ->any ())
137
+ ->method ('getManager ' )
138
+ ->will ($ this ->returnValue ($ this ->objectManager ))
139
+ ;
140
+
141
+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
142
+ $ routeProvider ->setManagerName ('default ' );
143
+
144
+ $ routeProvider ->setPrefix ('/cms/routes ' );
145
+
146
+ $ routeProvider ->getRouteByName ('invalid_route ' );
147
+
148
+ }
149
+
150
+ public function testGetRouteByNameIdPrefixEmptyString ()
151
+ {
152
+
153
+ $ this ->route
154
+ ->expects ($ this ->any ())
155
+ ->method ('getPath ' )
156
+ ->will ($ this ->returnValue ('/cms/routes/test-route ' ))
157
+ ;
158
+
159
+ $ this ->objectManager
160
+ ->expects ($ this ->any ())
161
+ ->method ('find ' )
162
+ ->with (null , '/cms/routes/test-route ' )
163
+ ->will ($ this ->returnValue ($ this ->route ))
164
+ ;
165
+
166
+ $ this ->managerRegistry
167
+ ->expects ($ this ->any ())
168
+ ->method ('getManager ' )
169
+ ->will ($ this ->returnValue ($ this ->objectManager ))
170
+ ;
171
+
172
+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
173
+ $ routeProvider ->setManagerName ('default ' );
174
+
175
+ $ routeProvider ->setPrefix ('' );
176
+ $ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
177
+
178
+ $ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
179
+ $ this ->assertEquals ('/cms/routes/test-route ' , $ foundRoute ->getPath ());
180
+
126
181
}
127
182
183
+
184
+ /**
185
+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
186
+ */
187
+ public function testGetRouteByNameNotFoundIdPrefixEmptyString ()
188
+ {
189
+ $ this ->objectManager
190
+ ->expects ($ this ->any ())
191
+ ->method ('find ' )
192
+ ->with (null , '/cms/routes/test-route ' )
193
+ ->will ($ this ->returnValue (null ))
194
+ ;
195
+
196
+ $ this ->managerRegistry
197
+ ->expects ($ this ->any ())
198
+ ->method ('getManager ' )
199
+ ->will ($ this ->returnValue ($ this ->objectManager ))
200
+ ;
201
+
202
+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
203
+ $ routeProvider ->setManagerName ('default ' );
204
+ $ routeProvider ->setPrefix ('' );
205
+ $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
206
+ }
207
+
208
+ /**
209
+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
210
+ */
211
+ public function testGetRouteByNameNoRoutePrefixEmptyString ()
212
+ {
213
+ $ this ->objectManager
214
+ ->expects ($ this ->any ())
215
+ ->method ('find ' )
216
+ ->with (null , '/cms/routes/test-route ' )
217
+ ->will ($ this ->returnValue ($ this ))
218
+ ;
219
+
220
+ $ this ->managerRegistry
221
+ ->expects ($ this ->any ())
222
+ ->method ('getManager ' )
223
+ ->will ($ this ->returnValue ($ this ->objectManager ))
224
+ ;
225
+
226
+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
227
+ $ routeProvider ->setManagerName ('default ' );
228
+ $ routeProvider ->setPrefix ('' );
229
+
230
+ $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
231
+ }
232
+
233
+
128
234
/**
129
235
* Use getRouteByName() with two different document managers.
130
236
* The two document managers will return different route objects when searching for the same path.
@@ -173,6 +279,8 @@ function ($name) use ($objectManagers) {
173
279
$ routeProvider = new RouteProvider ($ this ->managerRegistry );
174
280
175
281
$ routeProvider ->setManagerName ('default ' );
282
+ $ routeProvider ->setPrefix ('/cms/routes/ ' );
283
+
176
284
$ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/test-route ' );
177
285
$ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
178
286
$ this ->assertEquals ('/cms/routes/test-route ' , $ foundRoute ->getPath ());
0 commit comments