Skip to content

Commit ab63068

Browse files
committed
test: add tests for reverse routing
1 parent f7e6cff commit ab63068

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/system/Helpers/URLHelper/MiscUrlTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,43 @@ public function testUrlToWithSupportedLocaleInRoute(): void
906906
);
907907
}
908908

909+
public function testUrlToWithNamedRouteWithNestedParentheses(): void
910+
{
911+
Services::createRequest(new App());
912+
$routes = service('routes');
913+
914+
// The route will be:
915+
// docs/(master|\d+\.(?:\d+|x))/([a-z0-9-]+)
916+
$routes->addPlaceholder([
917+
'version' => 'master|\d+\.(?:\d+|x)',
918+
'page' => '[a-z0-9-]+',
919+
]);
920+
$routes->get('docs/(:version)/(:page)', static function () {
921+
echo 'Test the documentation segment';
922+
}, ['as' => 'docs.version']);
923+
924+
$this->assertSame(
925+
'http://example.com/index.php/docs/10.9/install',
926+
url_to('docs.version', '10.9', 'install')
927+
);
928+
}
929+
930+
public function testUrlToWithRouteWithNestedParentheses(): void
931+
{
932+
Services::createRequest(new App());
933+
$routes = service('routes');
934+
935+
// The route will be:
936+
// images/(^.*\.(?:jpg|png)$)
937+
$routes->addPlaceholder('imgFileExt', '^.*\.(?:jpg|png)$');
938+
$routes->get('images/(:imgFileExt)', 'Images::getFile/$1');
939+
940+
$this->assertSame(
941+
'http://example.com/index.php/images/test.jpg',
942+
url_to('Images::getFile', 'test.jpg')
943+
);
944+
}
945+
909946
/**
910947
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7651
911948
*/

0 commit comments

Comments
 (0)