|
11 | 11 |
|
12 | 12 | namespace CodeIgniter\Router; |
13 | 13 |
|
14 | | -use App\Controllers\Home; |
15 | 14 | use CodeIgniter\Config\Services; |
16 | 15 | use CodeIgniter\Test\CIUnitTestCase; |
17 | 16 | use Config\Modules; |
@@ -1189,6 +1188,73 @@ static function () {}, |
1189 | 1188 | $this->assertSame($options, ['as' => 'admin', 'foo' => 'baz']); |
1190 | 1189 | } |
1191 | 1190 |
|
| 1191 | + /** |
| 1192 | + * @dataProvider optionsProvider |
| 1193 | + */ |
| 1194 | + public function testRoutesOptionsWithSameFromTwoRoutes(array $options1, array $options2) |
| 1195 | + { |
| 1196 | + $routes = $this->getCollector(); |
| 1197 | + |
| 1198 | + // This is the first route for `administrator`. |
| 1199 | + $routes->get( |
| 1200 | + 'administrator', |
| 1201 | + static function () {}, |
| 1202 | + $options1 |
| 1203 | + ); |
| 1204 | + // The second route for `administrator` should be ignored. |
| 1205 | + $routes->get( |
| 1206 | + 'administrator', |
| 1207 | + static function () {}, |
| 1208 | + $options2 |
| 1209 | + ); |
| 1210 | + |
| 1211 | + $options = $routes->getRoutesOptions('administrator'); |
| 1212 | + |
| 1213 | + $this->assertSame($options, $options1); |
| 1214 | + } |
| 1215 | + |
| 1216 | + public function optionsProvider() |
| 1217 | + { |
| 1218 | + yield from [ |
| 1219 | + [ |
| 1220 | + [ |
| 1221 | + 'foo' => 'options1', |
| 1222 | + ], |
| 1223 | + [ |
| 1224 | + 'foo' => 'options2', |
| 1225 | + ], |
| 1226 | + ], |
| 1227 | + [ |
| 1228 | + [ |
| 1229 | + 'as' => 'admin', |
| 1230 | + 'foo' => 'options1', |
| 1231 | + ], |
| 1232 | + [ |
| 1233 | + 'foo' => 'options2', |
| 1234 | + ], |
| 1235 | + ], |
| 1236 | + [ |
| 1237 | + [ |
| 1238 | + 'foo' => 'options1', |
| 1239 | + ], |
| 1240 | + [ |
| 1241 | + 'as' => 'admin', |
| 1242 | + 'foo' => 'options2', |
| 1243 | + ], |
| 1244 | + ], |
| 1245 | + [ |
| 1246 | + [ |
| 1247 | + 'as' => 'admin', |
| 1248 | + 'foo' => 'options1', |
| 1249 | + ], |
| 1250 | + [ |
| 1251 | + 'as' => 'admin', |
| 1252 | + 'foo' => 'options2', |
| 1253 | + ], |
| 1254 | + ], |
| 1255 | + ]; |
| 1256 | + } |
| 1257 | + |
1192 | 1258 | public function testRoutesOptionsForDifferentVerbs() |
1193 | 1259 | { |
1194 | 1260 | $routes = $this->getCollector(); |
@@ -1460,12 +1526,12 @@ public function testRouteOverwritingTwoRules() |
1460 | 1526 | $routes->setDefaultController('Home'); |
1461 | 1527 | $routes->setDefaultMethod('index'); |
1462 | 1528 |
|
| 1529 | + // The subdomain of the current URL is `doc`, so this route is registered. |
1463 | 1530 | $routes->get('/', '\App\Controllers\Site\CDoc::index', ['subdomain' => 'doc', 'as' => 'doc_index']); |
| 1531 | + // The subdomain route is already registered, so this route is not registered. |
1464 | 1532 | $routes->get('/', 'Home::index'); |
1465 | 1533 |
|
1466 | | - // the second rule applies, so overwrites the first |
1467 | | - $expects = '\\' . Home::class; |
1468 | | - |
| 1534 | + $expects = '\App\Controllers\Site\CDoc'; |
1469 | 1535 | $this->assertSame($expects, $router->handle('/')); |
1470 | 1536 | } |
1471 | 1537 |
|
|
0 commit comments