Merge pull request #231 from skipperbent/v3

V3
This commit is contained in:
Simon Sessingø
2017-03-06 02:56:50 +01:00
committed by GitHub
5 changed files with 72 additions and 2 deletions
@@ -91,7 +91,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
/* Match global regular-expression for route */ /* Match global regular-expression for route */
$regexMatch = $this->matchRegex($request, $url); $regexMatch = $this->matchRegex($request, $url);
if ($regexMatch === false || stripos($url, $this->url) !== 0 || strtolower($url) !== strtolower($this->url)) { if ($regexMatch === false || (stripos($url, $this->url) !== 0 && strtolower($url) !== strtolower($this->url))) {
return false; return false;
} }
@@ -84,7 +84,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
/* Match global regular-expression for route */ /* Match global regular-expression for route */
$regexMatch = $this->matchRegex($request, $url); $regexMatch = $this->matchRegex($request, $url);
if ($regexMatch === false) { if ($regexMatch === false || (stripos($url, $this->url) !== 0 && strtolower($url) !== strtolower($this->url))) {
return false; return false;
} }
+15
View File
@@ -17,4 +17,19 @@ class DummyController
echo join(', ', func_get_args()); echo join(', ', func_get_args());
} }
public function getTest()
{
echo 'getTest';
}
public function postTest()
{
echo 'postTest';
}
public function putTest()
{
echo 'putTest';
}
} }
+42
View File
@@ -0,0 +1,42 @@
<?php
require_once 'Dummy/DummyController.php';
require_once 'Helpers/TestRouter.php';
class RouterControllerTest extends PHPUnit_Framework_TestCase
{
public function testGet()
{
// Match normal route on alias
TestRouter::controller('/url', 'DummyController');
$response = TestRouter::debugOutput('/url/test', 'get');
$this->assertEquals('getTest', $response);
}
public function testPost()
{
// Match normal route on alias
TestRouter::controller('/url', 'DummyController');
$response = TestRouter::debugOutput('/url/test', 'post');
$this->assertEquals('postTest', $response);
}
public function testPut()
{
// Match normal route on alias
TestRouter::controller('/url', 'DummyController');
$response = TestRouter::debugOutput('/url/test', 'put');
$this->assertEquals('putTest', $response);
}
}
+13
View File
@@ -8,6 +8,19 @@ require_once 'Helpers/TestRouter.php';
class RouterUrlTest extends PHPUnit_Framework_TestCase class RouterUrlTest extends PHPUnit_Framework_TestCase
{ {
public function testSimularUrls()
{
// Match normal route on alias
TestRouter::resource('/url11', 'DummyController@method1');
TestRouter::resource('/url1', 'DummyController@method1', ['as' => 'match']);
TestRouter::debugNoReset('/url1', 'get');
$this->assertEquals(TestRouter::getUrl('match'), TestRouter::getUrl());
TestRouter::router()->reset();
}
public function testUrls() public function testUrls()
{ {
// Match normal route on alias // Match normal route on alias