@@ -685,20 +685,20 @@ public function it_accepts_query_string_parameters_using_named_routes()
685
685
$ this ->withoutExceptionHandling ();
686
686
$ this ->setSupportedLocales (['en ' , 'nl ' ]);
687
687
688
- Route::get ('route/{slug} ' , function () {
688
+ Route::get ('route/{slug}/{optional?} ' , function () {
689
689
return [
690
- 'current ' => Route::localizedUrl (null , ['another-slug ' , 'new ' => 'value ' ]),
691
- 'en ' => Route::localizedUrl ('en ' , ['another-slug ' , 'new ' => 'value ' ]),
692
- 'nl ' => Route::localizedUrl ('nl ' , ['another-slug ' , 'new ' => 'value ' ]),
690
+ 'current ' => Route::localizedUrl (null , ['another-slug ' , 'optional-slug ' , ' new ' => 'value ' ]),
691
+ 'en ' => Route::localizedUrl ('en ' , ['another-slug ' , 'optional-slug ' , ' new ' => 'value ' ]),
692
+ 'nl ' => Route::localizedUrl ('nl ' , ['another-slug ' , 'optional-slug ' , ' new ' => 'value ' ]),
693
693
];
694
694
})->name ('route ' );
695
695
696
696
$ response = $ this ->call ('GET ' , '/route/some-slug?param=value ' );
697
697
$ response ->assertOk ();
698
698
$ this ->assertEquals ([
699
- 'current ' => url ('/route/another-slug?new=value ' ),
700
- 'en ' => url ('/route/another-slug?new=value ' ),
701
- 'nl ' => url ('/route/another-slug?new=value ' ),
699
+ 'current ' => url ('/route/another-slug/optional-slug ?new=value ' ),
700
+ 'en ' => url ('/route/another-slug/optional-slug ?new=value ' ),
701
+ 'nl ' => url ('/route/another-slug/optional-slug ?new=value ' ),
702
702
], $ response ->original );
703
703
}
704
704
@@ -708,20 +708,66 @@ public function it_accepts_query_string_parameters_using_unnamed_routes()
708
708
$ this ->withoutExceptionHandling ();
709
709
$ this ->setSupportedLocales (['en ' , 'nl ' ]);
710
710
711
- Route::get ('route/{slug} ' , function () {
711
+ Route::get ('route/{slug}/{optional?} ' , function () {
712
712
return [
713
- 'current ' => Route::localizedUrl (null , ['another-slug ' , 'new ' => 'value ' ]),
714
- 'en ' => Route::localizedUrl ('en ' , ['another-slug ' , 'new ' => 'value ' ]),
715
- 'nl ' => Route::localizedUrl ('nl ' , ['another-slug ' , 'new ' => 'value ' ]),
713
+ 'current ' => Route::localizedUrl (null , ['another-slug ' , 'optional-slug ' , ' new ' => 'value ' ]),
714
+ 'en ' => Route::localizedUrl ('en ' , ['another-slug ' , 'optional-slug ' , ' new ' => 'value ' ]),
715
+ 'nl ' => Route::localizedUrl ('nl ' , ['another-slug ' , 'optional-slug ' , ' new ' => 'value ' ]),
716
716
];
717
717
});
718
718
719
719
$ response = $ this ->call ('GET ' , '/route/some-slug?param=value ' );
720
720
$ response ->assertOk ();
721
721
$ this ->assertEquals ([
722
- 'current ' => url ('/route/another-slug?new=value ' ),
723
- 'en ' => url ('/route/another-slug?new=value ' ),
724
- 'nl ' => url ('/route/another-slug?new=value ' ),
722
+ 'current ' => url ('/route/another-slug/optional-slug?new=value ' ),
723
+ 'en ' => url ('/route/another-slug/optional-slug?new=value ' ),
724
+ 'nl ' => url ('/route/another-slug/optional-slug?new=value ' ),
725
+ ], $ response ->original );
726
+ }
727
+
728
+ /** @test */
729
+ public function it_allows_optional_parameters_with_named_routes ()
730
+ {
731
+ $ this ->withoutExceptionHandling ();
732
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
733
+
734
+ Route::get ('route/{slug}/{one?}/{two?} ' , function () {
735
+ return [
736
+ 'current ' => Route::localizedUrl (null , ['another-slug ' ]),
737
+ 'en ' => Route::localizedUrl ('en ' , ['another-slug ' ]),
738
+ 'nl ' => Route::localizedUrl ('nl ' , ['another-slug ' ]),
739
+ ];
740
+ })->name ('route ' );
741
+
742
+ $ response = $ this ->call ('GET ' , '/route/some-slug ' );
743
+ $ response ->assertOk ();
744
+ $ this ->assertEquals ([
745
+ 'current ' => url ('/route/another-slug ' ),
746
+ 'en ' => url ('/route/another-slug ' ),
747
+ 'nl ' => url ('/route/another-slug ' ),
748
+ ], $ response ->original );
749
+ }
750
+
751
+ /** @test */
752
+ public function it_allows_optional_parameters_with_unnamed_routes ()
753
+ {
754
+ $ this ->withoutExceptionHandling ();
755
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
756
+
757
+ Route::get ('route/{slug}/{one?}/{two?} ' , function () {
758
+ return [
759
+ 'current ' => Route::localizedUrl (null , ['another-slug ' ]),
760
+ 'en ' => Route::localizedUrl ('en ' , ['another-slug ' ]),
761
+ 'nl ' => Route::localizedUrl ('nl ' , ['another-slug ' ]),
762
+ ];
763
+ });
764
+
765
+ $ response = $ this ->call ('GET ' , '/route/some-slug ' );
766
+ $ response ->assertOk ();
767
+ $ this ->assertEquals ([
768
+ 'current ' => url ('/route/another-slug ' ),
769
+ 'en ' => url ('/route/another-slug ' ),
770
+ 'nl ' => url ('/route/another-slug ' ),
725
771
], $ response ->original );
726
772
}
727
773
0 commit comments