From 0d255c06aa78f5b5ae9e63fdf1362a36c837f3ec Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Wed, 3 Apr 2019 11:19:26 -0700 Subject: [PATCH] Additional RouteCollectionTests --- tests/system/Router/RouteCollectionTest.php | 114 ++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 1ea43d7ee12b..1dce6591a934 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -1094,4 +1094,118 @@ public function testOffsetParameters() $this->assertEquals($expected, $routes->getRoutes()); } + //-------------------------------------------------------------------- + // Battery of tests for reported issue + // @see https://github.com/codeigniter4/CodeIgniter4/issues/1697 + + /** + */ + public function testRouteToWithSubdomainMatch() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'doc.example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => 'doc', 'as' => 'doc_item']); + + $this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithSubdomainMismatch() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'dev.example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => 'doc', 'as' => 'doc_item']); + + $this->assertFalse($routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithSubdomainNot() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => 'doc', 'as' => 'doc_item']); + + $this->assertFalse($routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithGenericSubdomainMatch() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'doc.example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']); + + $this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithGenericSubdomainMismatch() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'dev.example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']); + + $this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithGenericSubdomainNot() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']); + + $this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithoutSubdomainMatch() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'doc.example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['hostname' => 'example.com', 'as' => 'doc_item']); + + $this->assertFalse($routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithoutSubdomainMismatch() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'dev.example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['hostname' => 'example.com', 'as' => 'doc_item']); + + $this->assertFalse($routes->reverseRoute('doc_item', 'sth')); + } + + public function testRouteToWithoutSubdomainNot() + { + $routes = $this->getCollector(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['HTTP_HOST'] = 'example.com'; + + $routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['hostname' => 'example.com', 'as' => 'doc_item']); + + $this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth')); + } + }