|
13 | 13 |
|
14 | 14 | namespace CodeIgniter\Router;
|
15 | 15 |
|
| 16 | +use App\Controllers\Home; |
16 | 17 | use App\Controllers\Product;
|
17 | 18 | use CodeIgniter\Config\Services;
|
18 | 19 | use CodeIgniter\controller;
|
@@ -1744,6 +1745,46 @@ public function testRouteOverwritingMatchingHost(): void
|
1744 | 1745 | $this->assertSame($expects, $router->handle('/'));
|
1745 | 1746 | }
|
1746 | 1747 |
|
| 1748 | + public function testRouteMatchingHostMultipleCorrect(): void |
| 1749 | + { |
| 1750 | + service('superglobals')->setServer('HTTP_HOST', 'two.domain.com'); |
| 1751 | + service('request')->setMethod(Method::GET); |
| 1752 | + |
| 1753 | + $routes = $this->getCollector(); |
| 1754 | + $router = new Router($routes, Services::request()); |
| 1755 | + |
| 1756 | + $routes->setDefaultNamespace('App\Controllers'); |
| 1757 | + $routes->setDefaultController('Home'); |
| 1758 | + $routes->setDefaultMethod('index'); |
| 1759 | + |
| 1760 | + $routes->get('/', 'Home::index', ['as' => 'ddd']); |
| 1761 | + $routes->get('/', '\App\Controllers\Site\CDoc::index', ['hostname' => ['one.domain.com', 'two.domain.com', 'three.domain.com']]); |
| 1762 | + |
| 1763 | + $expects = '\App\Controllers\Site\CDoc'; |
| 1764 | + |
| 1765 | + $this->assertSame($expects, $router->handle('/')); |
| 1766 | + } |
| 1767 | + |
| 1768 | + public function testRouteMatchingHostMultipleFail(): void |
| 1769 | + { |
| 1770 | + service('superglobals')->setServer('HTTP_HOST', 'doc.domain.com'); |
| 1771 | + service('request')->setMethod(Method::GET); |
| 1772 | + |
| 1773 | + $routes = $this->getCollector(); |
| 1774 | + $router = new Router($routes, Services::request()); |
| 1775 | + |
| 1776 | + $routes->setDefaultNamespace('App\Controllers'); |
| 1777 | + $routes->setDefaultController('Home'); |
| 1778 | + $routes->setDefaultMethod('index'); |
| 1779 | + |
| 1780 | + $routes->get('/', 'Home::index', ['as' => 'ddd']); |
| 1781 | + $routes->get('/', '\App\Controllers\Site\CDoc::index', ['hostname' => ['one.domain.com', 'two.domain.com', 'three.domain.com']]); |
| 1782 | + |
| 1783 | + $expects = '\\' . Home::class; |
| 1784 | + |
| 1785 | + $this->assertSame($expects, $router->handle('/')); |
| 1786 | + } |
| 1787 | + |
1747 | 1788 | /**
|
1748 | 1789 | * Tests for router DefaultNameSpace issue
|
1749 | 1790 | *
|
|
0 commit comments