@@ -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 );
@@ -532,6 +542,141 @@ public function testWithHostOnRouteCollection()
532
542
$ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' , 'locale ' => 'en ' ], $ matcher ->match ('/bar/bar ' ));
533
543
}
534
544
545
+ public function testVariationInTrailingSlashWithHosts ()
546
+ {
547
+ $ coll = new RouteCollection ();
548
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], 'foo.example.com ' ));
549
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], 'bar.example.com ' ));
550
+
551
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
552
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
553
+
554
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
555
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
556
+ }
557
+
558
+ public function testVariationInTrailingSlashWithHostsInReverse ()
559
+ {
560
+ // The order should not matter
561
+ $ coll = new RouteCollection ();
562
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], 'bar.example.com ' ));
563
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], 'foo.example.com ' ));
564
+
565
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
566
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
567
+
568
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
569
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
570
+ }
571
+
572
+ public function testVariationInTrailingSlashWithHostsAndVariable ()
573
+ {
574
+ $ coll = new RouteCollection ();
575
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], 'foo.example.com ' ));
576
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], 'bar.example.com ' ));
577
+
578
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
579
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
580
+
581
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
582
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
583
+ }
584
+
585
+ public function testVariationInTrailingSlashWithHostsAndVariableInReverse ()
586
+ {
587
+ // The order should not matter
588
+ $ coll = new RouteCollection ();
589
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], 'bar.example.com ' ));
590
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], 'foo.example.com ' ));
591
+
592
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
593
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
594
+
595
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
596
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
597
+ }
598
+
599
+ public function testVariationInTrailingSlashWithMethods ()
600
+ {
601
+ $ coll = new RouteCollection ();
602
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], '' , [], ['POST ' ]));
603
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], '' , [], ['GET ' ]));
604
+
605
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
606
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
607
+
608
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
609
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
610
+ }
611
+
612
+ public function testVariationInTrailingSlashWithMethodsInReverse ()
613
+ {
614
+ // The order should not matter
615
+ $ coll = new RouteCollection ();
616
+ $ coll ->add ('bar ' , new Route ('/foo ' , [], [], [], '' , [], ['GET ' ]));
617
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], '' , [], ['POST ' ]));
618
+
619
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
620
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
621
+
622
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
623
+ $ this ->assertEquals (['_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
624
+ }
625
+
626
+ public function testVariableVariationInTrailingSlashWithMethods ()
627
+ {
628
+ $ coll = new RouteCollection ();
629
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], '' , [], ['POST ' ]));
630
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], '' , [], ['GET ' ]));
631
+
632
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
633
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
634
+
635
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
636
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
637
+ }
638
+
639
+ public function testVariableVariationInTrailingSlashWithMethodsInReverse ()
640
+ {
641
+ // The order should not matter
642
+ $ coll = new RouteCollection ();
643
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], '' , [], ['GET ' ]));
644
+ $ coll ->add ('foo ' , new Route ('/{foo}/ ' , [], [], [], '' , [], ['POST ' ]));
645
+
646
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
647
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'foo ' ], $ matcher ->match ('/bar/ ' ));
648
+
649
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
650
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
651
+ }
652
+
653
+ public function testMixOfStaticAndVariableVariationInTrailingSlashWithHosts ()
654
+ {
655
+ $ coll = new RouteCollection ();
656
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], 'foo.example.com ' ));
657
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], 'bar.example.com ' ));
658
+
659
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'foo.example.com ' ));
660
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
661
+
662
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'bar.example.com ' ));
663
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
664
+ }
665
+
666
+ public function testMixOfStaticAndVariableVariationInTrailingSlashWithMethods ()
667
+ {
668
+ $ coll = new RouteCollection ();
669
+ $ coll ->add ('foo ' , new Route ('/foo/ ' , [], [], [], '' , [], ['POST ' ]));
670
+ $ coll ->add ('bar ' , new Route ('/{foo} ' , [], [], [], '' , [], ['GET ' ]));
671
+
672
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'POST ' ));
673
+ $ this ->assertEquals (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
674
+
675
+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ('' , 'GET ' ));
676
+ $ this ->assertEquals (['foo ' => 'bar ' , '_route ' => 'bar ' ], $ matcher ->match ('/bar ' ));
677
+ $ this ->assertEquals (['foo ' => 'foo ' , '_route ' => 'bar ' ], $ matcher ->match ('/foo ' ));
678
+ }
679
+
535
680
/**
536
681
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
537
682
*/
0 commit comments