Skip to content

Commit

Permalink
Merge pull request #1912 from jim-parry/testing31
Browse files Browse the repository at this point in the history
Additional RouteCollectionTests
  • Loading branch information
jim-parry authored Apr 3, 2019
2 parents 79809d7 + 0d255c0 commit 8653d65
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

}

0 comments on commit 8653d65

Please sign in to comment.