@@ -125,6 +125,8 @@ public function testConnectBasic() {
125
125
*/
126
126
public function testConnectExtensions () {
127
127
$ routes = new ScopedRouteCollection ('/l ' , [], ['json ' ]);
128
+ $ this ->assertEquals (['json ' ], $ routes ->extensions ());
129
+
128
130
$ routes ->connect ('/:controller ' );
129
131
$ route = $ routes ->routes ()[0 ];
130
132
@@ -288,4 +290,62 @@ public function testMatch() {
288
290
$ this ->assertFalse ($ result , 'No matches ' );
289
291
}
290
292
293
+ /**
294
+ * Test matching plugin routes.
295
+ *
296
+ * @return void
297
+ */
298
+ public function testMatchPlugin () {
299
+ $ context = [
300
+ '_base ' => '/ ' ,
301
+ '_scheme ' => 'http ' ,
302
+ '_host ' => 'example.org ' ,
303
+ ];
304
+ $ routes = new ScopedRouteCollection ('/contacts ' , ['plugin ' => 'Contacts ' ]);
305
+ $ routes ->connect ('/ ' , ['controller ' => 'Contacts ' ]);
306
+
307
+ $ result = $ routes ->match (
308
+ ['plugin ' => 'Contacts ' , 'controller ' => 'Contacts ' , 'action ' => 'index ' ],
309
+ $ context
310
+ );
311
+ $ this ->assertFalse ($ result );
312
+
313
+ $ result = $ routes ->match (['controller ' => 'Contacts ' , 'action ' => 'index ' ], $ context );
314
+ $ this ->assertFalse ($ result );
315
+ }
316
+
317
+ /**
318
+ * Test connecting resources.
319
+ *
320
+ * @return void
321
+ */
322
+ public function testResource () {
323
+ $ routes = new ScopedRouteCollection ('/api ' , ['prefix ' => 'api ' ]);
324
+ $ routes ->resource ('Articles ' , ['_ext ' => 'json ' ]);
325
+
326
+ $ all = $ routes ->routes ();
327
+ $ this ->assertCount (6 , $ all );
328
+
329
+ $ this ->assertEquals ('/api/articles ' , $ all [0 ]->template );
330
+ $ this ->assertEquals ('json ' , $ all [0 ]->defaults ['_ext ' ]);
331
+ $ this ->assertEquals ('Articles ' , $ all [0 ]->defaults ['controller ' ]);
332
+ }
333
+
334
+ /**
335
+ * Test nesting resources
336
+ *
337
+ * @return void
338
+ */
339
+ public function testResourceNested () {
340
+ $ routes = new ScopedRouteCollection ('/api ' , ['prefix ' => 'api ' ]);
341
+ $ routes ->resource ('Articles ' , function ($ routes ) {
342
+ $ this ->assertEquals ('/api/articles/ ' , $ routes ->path ());
343
+ $ this ->assertEquals (['prefix ' => 'api ' ], $ routes ->params ());
344
+
345
+ $ routes ->resource ('Comments ' );
346
+ $ route = $ routes ->routes ()[0 ];
347
+ $ this ->assertEquals ('/api/articles/:article_id/comments ' , $ route ->template );
348
+ });
349
+ }
350
+
291
351
}
0 commit comments