mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 19:02:19 +00:00
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user