Skip to content

Commit 300af6c

Browse files
committed
Merge branch 'develop' into testing32
2 parents 9889db6 + 8653d65 commit 300af6c

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

tests/system/Router/RouteCollectionTest.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,120 @@ public function testOffsetParameters()
10941094
$this->assertEquals($expected, $routes->getRoutes());
10951095
}
10961096

1097+
//--------------------------------------------------------------------
1098+
// Battery of tests for reported issue
1099+
// @see https://github.com/codeigniter4/CodeIgniter4/issues/1697
1100+
1101+
/**
1102+
*/
1103+
public function testRouteToWithSubdomainMatch()
1104+
{
1105+
$routes = $this->getCollector();
1106+
1107+
$_SERVER['REQUEST_METHOD'] = 'GET';
1108+
$_SERVER['HTTP_HOST'] = 'doc.example.com';
1109+
1110+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => 'doc', 'as' => 'doc_item']);
1111+
1112+
$this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth'));
1113+
}
1114+
1115+
public function testRouteToWithSubdomainMismatch()
1116+
{
1117+
$routes = $this->getCollector();
1118+
1119+
$_SERVER['REQUEST_METHOD'] = 'GET';
1120+
$_SERVER['HTTP_HOST'] = 'dev.example.com';
1121+
1122+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => 'doc', 'as' => 'doc_item']);
1123+
1124+
$this->assertFalse($routes->reverseRoute('doc_item', 'sth'));
1125+
}
1126+
1127+
public function testRouteToWithSubdomainNot()
1128+
{
1129+
$routes = $this->getCollector();
1130+
1131+
$_SERVER['REQUEST_METHOD'] = 'GET';
1132+
$_SERVER['HTTP_HOST'] = 'example.com';
1133+
1134+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => 'doc', 'as' => 'doc_item']);
1135+
1136+
$this->assertFalse($routes->reverseRoute('doc_item', 'sth'));
1137+
}
1138+
1139+
public function testRouteToWithGenericSubdomainMatch()
1140+
{
1141+
$routes = $this->getCollector();
1142+
1143+
$_SERVER['REQUEST_METHOD'] = 'GET';
1144+
$_SERVER['HTTP_HOST'] = 'doc.example.com';
1145+
1146+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']);
1147+
1148+
$this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth'));
1149+
}
1150+
1151+
public function testRouteToWithGenericSubdomainMismatch()
1152+
{
1153+
$routes = $this->getCollector();
1154+
1155+
$_SERVER['REQUEST_METHOD'] = 'GET';
1156+
$_SERVER['HTTP_HOST'] = 'dev.example.com';
1157+
1158+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']);
1159+
1160+
$this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth'));
1161+
}
1162+
1163+
public function testRouteToWithGenericSubdomainNot()
1164+
{
1165+
$routes = $this->getCollector();
1166+
1167+
$_SERVER['REQUEST_METHOD'] = 'GET';
1168+
$_SERVER['HTTP_HOST'] = 'example.com';
1169+
1170+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']);
1171+
1172+
$this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth'));
1173+
}
1174+
1175+
public function testRouteToWithoutSubdomainMatch()
1176+
{
1177+
$routes = $this->getCollector();
1178+
1179+
$_SERVER['REQUEST_METHOD'] = 'GET';
1180+
$_SERVER['HTTP_HOST'] = 'doc.example.com';
1181+
1182+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['hostname' => 'example.com', 'as' => 'doc_item']);
1183+
1184+
$this->assertFalse($routes->reverseRoute('doc_item', 'sth'));
1185+
}
1186+
1187+
public function testRouteToWithoutSubdomainMismatch()
1188+
{
1189+
$routes = $this->getCollector();
1190+
1191+
$_SERVER['REQUEST_METHOD'] = 'GET';
1192+
$_SERVER['HTTP_HOST'] = 'dev.example.com';
1193+
1194+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['hostname' => 'example.com', 'as' => 'doc_item']);
1195+
1196+
$this->assertFalse($routes->reverseRoute('doc_item', 'sth'));
1197+
}
1198+
1199+
public function testRouteToWithoutSubdomainNot()
1200+
{
1201+
$routes = $this->getCollector();
1202+
1203+
$_SERVER['REQUEST_METHOD'] = 'GET';
1204+
$_SERVER['HTTP_HOST'] = 'example.com';
1205+
1206+
$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['hostname' => 'example.com', 'as' => 'doc_item']);
1207+
1208+
$this->assertEquals('/i/sth', $routes->reverseRoute('doc_item', 'sth'));
1209+
}
1210+
10971211
//--------------------------------------------------------------------
10981212
// Tests for router overwritting issue
10991213
// @see https://github.com/codeigniter4/CodeIgniter4/issues/1692

0 commit comments

Comments
 (0)