@@ -85,9 +85,8 @@ public function testMethodNotAllowedAggregatesAllowedMethods()
85
85
}
86
86
}
87
87
88
- public function testMatch ()
88
+ public function testPatternMatchAndParameterReturn ()
89
89
{
90
- // test the patterns are matched and parameters are returned
91
90
$ collection = new RouteCollection ();
92
91
$ collection ->add ('foo ' , new Route ('/foo/{bar} ' ));
93
92
$ matcher = $ this ->getUrlMatcher ($ collection );
@@ -96,14 +95,21 @@ public function testMatch()
96
95
$ this ->fail ();
97
96
} catch (ResourceNotFoundException $ e ) {
98
97
}
98
+
99
99
$ this ->assertEquals (['_route ' => 'foo ' , 'bar ' => 'baz ' ], $ matcher ->match ('/foo/baz ' ));
100
+ }
100
101
102
+ public function testDefaultsAreMerged ()
103
+ {
101
104
// test that defaults are merged
102
105
$ collection = new RouteCollection ();
103
106
$ collection ->add ('foo ' , new Route ('/foo/{bar} ' , ['def ' => 'test ' ]));
104
107
$ matcher = $ this ->getUrlMatcher ($ collection );
105
108
$ this ->assertEquals (['_route ' => 'foo ' , 'bar ' => 'baz ' , 'def ' => 'test ' ], $ matcher ->match ('/foo/baz ' ));
109
+ }
106
110
111
+ public function testMethodIsIgnoredIfNoMethodGiven ()
112
+ {
107
113
// test that route "method" is ignored if no method is given in the context
108
114
$ collection = new RouteCollection ();
109
115
$ collection ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , [], ['get ' , 'head ' ]));
@@ -123,8 +129,10 @@ public function testMatch()
123
129
$ this ->assertInternalType ('array ' , $ matcher ->match ('/foo ' ));
124
130
$ matcher = $ this ->getUrlMatcher ($ collection , new RequestContext ('' , 'head ' ));
125
131
$ this ->assertInternalType ('array ' , $ matcher ->match ('/foo ' ));
132
+ }
126
133
127
- // route with an optional variable as the first segment
134
+ public function testRouteWithOptionalVariableAsFirstSegment ()
135
+ {
128
136
$ collection = new RouteCollection ();
129
137
$ collection ->add ('bar ' , new Route ('/{bar}/foo ' , ['bar ' => 'bar ' ], ['bar ' => 'foo|bar ' ]));
130
138
$ matcher = $ this ->getUrlMatcher ($ collection );
@@ -136,8 +144,10 @@ public function testMatch()
136
144
$ matcher = $ this ->getUrlMatcher ($ collection );
137
145
$ this ->assertEquals (['_route ' => 'bar ' , 'bar ' => 'foo ' ], $ matcher ->match ('/foo ' ));
138
146
$ this ->assertEquals (['_route ' => 'bar ' , 'bar ' => 'bar ' ], $ matcher ->match ('/ ' ));
147
+ }
139
148
140
- // route with only optional variables
149
+ public function testRouteWithOnlyOptionalVariables ()
150
+ {
141
151
$ collection = new RouteCollection ();
142
152
$ collection ->add ('bar ' , new Route ('/{foo}/{bar} ' , ['foo ' => 'foo ' , 'bar ' => 'bar ' ], []));
143
153
$ matcher = $ this ->getUrlMatcher ($ collection );
@@ -512,6 +522,141 @@ public function testWithHostOnRouteCollection()
512
522
$ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' , 'locale ' => 'en ' ], $ matcher ->match ('/bar/bar ' ));
513
523
}
514
524
525
+ public function testVariationInTrailingSlashWithHosts ()
526
+ {
527
+ $ coll = new RouteCollection ();
528
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], 'foo.example.com ' ));
529
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], 'bar.example.com ' ));
530
+
531
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
532
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
533
+
534
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
535
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
536
+ }
537
+
538
+ public function testVariationInTrailingSlashWithHostsInReverse ()
539
+ {
540
+ // The order should not matter
541
+ $ coll = new RouteCollection ();
542
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], 'bar.example.com ' ));
543
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], 'foo.example.com ' ));
544
+
545
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
546
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
547
+
548
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
549
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
550
+ }
551
+
552
+ public function testVariationInTrailingSlashWithHostsAndVariable ()
553
+ {
554
+ $ coll = new RouteCollection ();
555
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], 'foo.example.com ' ));
556
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], 'bar.example.com ' ));
557
+
558
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
559
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
560
+
561
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
562
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
563
+ }
564
+
565
+ public function testVariationInTrailingSlashWithHostsAndVariableInReverse ()
566
+ {
567
+ // The order should not matter
568
+ $ coll = new RouteCollection ();
569
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], 'bar.example.com ' ));
570
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], 'foo.example.com ' ));
571
+
572
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
573
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
574
+
575
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
576
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
577
+ }
578
+
579
+ public function testVariationInTrailingSlashWithMethods ()
580
+ {
581
+ $ coll = new RouteCollection ();
582
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], '' , [], ['POST ' ]));
583
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], '' , [], ['GET ' ]));
584
+
585
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
586
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
587
+
588
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
589
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
590
+ }
591
+
592
+ public function testVariationInTrailingSlashWithMethodsInReverse ()
593
+ {
594
+ // The order should not matter
595
+ $ coll = new RouteCollection ();
596
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], '' , [], ['GET ' ]));
597
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], '' , [], ['POST ' ]));
598
+
599
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
600
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
601
+
602
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
603
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
604
+ }
605
+
606
+ public function testVariableVariationInTrailingSlashWithMethods ()
607
+ {
608
+ $ coll = new RouteCollection ();
609
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], '' , [], ['POST ' ]));
610
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], '' , [], ['GET ' ]));
611
+
612
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
613
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
614
+
615
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
616
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
617
+ }
618
+
619
+ public function testVariableVariationInTrailingSlashWithMethodsInReverse ()
620
+ {
621
+ // The order should not matter
622
+ $ coll = new RouteCollection ();
623
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], '' , [], ['GET ' ]));
624
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], '' , [], ['POST ' ]));
625
+
626
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
627
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
628
+
629
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
630
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
631
+ }
632
+
633
+ public function testMixOfStaticAndVariableVariationInTrailingSlashWithHosts ()
634
+ {
635
+ $ coll = new RouteCollection ();
636
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], 'foo.example.com ' ));
637
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], 'bar.example.com ' ));
638
+
639
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
640
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
641
+
642
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
643
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
644
+ }
645
+
646
+ public function testMixOfStaticAndVariableVariationInTrailingSlashWithMethods ()
647
+ {
648
+ $ coll = new RouteCollection ();
649
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], '' , [], ['POST ' ]));
650
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], '' , [], ['GET ' ]));
651
+
652
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
653
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
654
+
655
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
656
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
657
+ $ this ->assertEquals (['foo ' => 'foo ' , '_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
658
+ }
659
+
515
660
/**
516
661
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
517
662
*/
0 commit comments