|
|
@@ -139,7 +139,6 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::mapResources('Posts');
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -147,10 +146,9 @@ class RouterTest extends TestCase
|
|
|
'action' => 'index',
|
|
|
'_method' => 'GET',
|
|
|
];
|
|
|
- $result = Router::parse('/posts');
|
|
|
+ $result = Router::parse('/posts', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
$expected = [
|
|
|
'pass' => ['13'],
|
|
|
'plugin' => null,
|
|
|
@@ -159,10 +157,9 @@ class RouterTest extends TestCase
|
|
|
'id' => '13',
|
|
|
'_method' => 'GET',
|
|
|
];
|
|
|
- $result = Router::parse('/posts/13');
|
|
|
+ $result = Router::parse('/posts/13', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -170,10 +167,9 @@ class RouterTest extends TestCase
|
|
|
'action' => 'add',
|
|
|
'_method' => 'POST',
|
|
|
];
|
|
|
- $result = Router::parse('/posts');
|
|
|
+ $result = Router::parse('/posts', 'POST');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
$expected = [
|
|
|
'pass' => ['13'],
|
|
|
'plugin' => null,
|
|
|
@@ -182,7 +178,7 @@ class RouterTest extends TestCase
|
|
|
'id' => '13',
|
|
|
'_method' => ['PUT', 'PATCH'],
|
|
|
];
|
|
|
- $result = Router::parse('/posts/13');
|
|
|
+ $result = Router::parse('/posts/13', 'PUT');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
$expected = [
|
|
|
@@ -193,10 +189,9 @@ class RouterTest extends TestCase
|
|
|
'id' => '475acc39-a328-44d3-95fb-015000000000',
|
|
|
'_method' => ['PUT', 'PATCH'],
|
|
|
];
|
|
|
- $result = Router::parse('/posts/475acc39-a328-44d3-95fb-015000000000');
|
|
|
+ $result = Router::parse('/posts/475acc39-a328-44d3-95fb-015000000000', 'PUT');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'DELETE';
|
|
|
$expected = [
|
|
|
'pass' => ['13'],
|
|
|
'plugin' => null,
|
|
|
@@ -205,13 +200,12 @@ class RouterTest extends TestCase
|
|
|
'id' => '13',
|
|
|
'_method' => 'DELETE',
|
|
|
];
|
|
|
- $result = Router::parse('/posts/13');
|
|
|
+ $result = Router::parse('/posts/13', 'DELETE');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
Router::reload();
|
|
|
Router::mapResources('Posts', ['id' => '[a-z0-9_]+']);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
$expected = [
|
|
|
'pass' => ['add'],
|
|
|
'plugin' => null,
|
|
|
@@ -220,10 +214,9 @@ class RouterTest extends TestCase
|
|
|
'id' => 'add',
|
|
|
'_method' => 'GET',
|
|
|
];
|
|
|
- $result = Router::parse('/posts/add');
|
|
|
+ $result = Router::parse('/posts/add', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
$expected = [
|
|
|
'pass' => ['name'],
|
|
|
'plugin' => null,
|
|
|
@@ -232,7 +225,7 @@ class RouterTest extends TestCase
|
|
|
'id' => 'name',
|
|
|
'_method' => ['PUT', 'PATCH'],
|
|
|
];
|
|
|
- $result = Router::parse('/posts/name');
|
|
|
+ $result = Router::parse('/posts/name', 'PUT');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
}
|
|
|
|
|
|
@@ -245,8 +238,7 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::mapResources('TestPlugin.TestPlugin');
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
- $result = Router::parse('/test_plugin/test_plugin');
|
|
|
+ $result = Router::parse('/test_plugin/test_plugin', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => 'TestPlugin',
|
|
|
@@ -256,8 +248,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
- $result = Router::parse('/test_plugin/test_plugin/13');
|
|
|
+ $result = Router::parse('/test_plugin/test_plugin/13', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => ['13'],
|
|
|
'plugin' => 'TestPlugin',
|
|
|
@@ -278,8 +269,7 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::mapResources('Posts', ['prefix' => 'api']);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
- $result = Router::parse('/api/posts');
|
|
|
+ $result = Router::parse('/api/posts', 'GET');
|
|
|
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
@@ -300,9 +290,7 @@ class RouterTest extends TestCase
|
|
|
public function testMapResourcesWithExtension()
|
|
|
{
|
|
|
Router::extensions(['json', 'xml'], false);
|
|
|
-
|
|
|
Router::mapResources('Posts', ['_ext' => 'json']);
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
@@ -312,14 +300,14 @@ class RouterTest extends TestCase
|
|
|
'_method' => 'GET',
|
|
|
];
|
|
|
|
|
|
- $result = Router::parse('/posts');
|
|
|
+ $result = Router::parse('/posts', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/posts.json');
|
|
|
+ $result = Router::parse('/posts.json', 'GET');
|
|
|
$expected['_ext'] = 'json';
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/posts.xml');
|
|
|
+ $result = Router::parse('/posts.xml', 'GET');
|
|
|
$this->assertArrayNotHasKey('_method', $result, 'Not an extension/resource route.');
|
|
|
}
|
|
|
|
|
|
@@ -350,8 +338,7 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::mapResources('TestPlugin.TestPlugin', ['prefix' => 'api']);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
- $result = Router::parse('/api/test_plugin/test_plugin');
|
|
|
+ $result = Router::parse('/api/test_plugin/test_plugin', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => 'TestPlugin',
|
|
|
@@ -364,8 +351,7 @@ class RouterTest extends TestCase
|
|
|
|
|
|
$resources = Router::mapResources('Posts', ['prefix' => 'api']);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
- $result = Router::parse('/api/posts');
|
|
|
+ $result = Router::parse('/api/posts', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -386,8 +372,7 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::connect('/:controller', ['action' => 'index', '_method' => ['GET', 'POST']]);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
- $result = Router::parse('/posts');
|
|
|
+ $result = Router::parse('/posts', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -397,8 +382,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
- $result = Router::parse('/posts');
|
|
|
+ $result = Router::parse('/posts', 'POST');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -578,10 +562,10 @@ class RouterTest extends TestCase
|
|
|
'action' => 'index',
|
|
|
'pass' => ['0'],
|
|
|
];
|
|
|
- $result = Router::parse('/0');
|
|
|
+ $result = Router::parse('/0', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('0');
|
|
|
+ $result = Router::parse('0', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
}
|
|
|
|
|
|
@@ -1313,7 +1297,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'Posts', 'action' => 'view'],
|
|
|
['value', 'somevalue', 'othervalue']
|
|
|
);
|
|
|
- $result = Router::parse('/posts/2007/08/01/title-of-post-here');
|
|
|
+ $result = Router::parse('/posts/2007/08/01/title-of-post-here', 'GET');
|
|
|
$expected = [
|
|
|
'value' => '2007',
|
|
|
'somevalue' => '08',
|
|
|
@@ -1331,7 +1315,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'posts', 'action' => 'view'],
|
|
|
['year' => $Year, 'month' => $Month, 'day' => $Day]
|
|
|
);
|
|
|
- $result = Router::parse('/posts/2007/08/01/title-of-post-here');
|
|
|
+ $result = Router::parse('/posts/2007/08/01/title-of-post-here', 'GET');
|
|
|
$expected = [
|
|
|
'year' => '2007',
|
|
|
'month' => '08',
|
|
|
@@ -1349,7 +1333,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'posts', 'action' => 'view'],
|
|
|
['year' => $Year, 'month' => $Month, 'day' => $Day]
|
|
|
);
|
|
|
- $result = Router::parse('/posts/01/2007/08/title-of-post-here');
|
|
|
+ $result = Router::parse('/posts/01/2007/08/title-of-post-here', 'GET');
|
|
|
$expected = [
|
|
|
'day' => '01',
|
|
|
'year' => '2007',
|
|
|
@@ -1367,7 +1351,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'posts', 'action' => 'view'],
|
|
|
['year' => $Year, 'month' => $Month, 'day' => $Day]
|
|
|
);
|
|
|
- $result = Router::parse('/posts/08/01/2007/title-of-post-here');
|
|
|
+ $result = Router::parse('/posts/08/01/2007/title-of-post-here', 'GET');
|
|
|
$expected = [
|
|
|
'month' => '08',
|
|
|
'day' => '01',
|
|
|
@@ -1384,7 +1368,7 @@ class RouterTest extends TestCase
|
|
|
'/posts/:year/:month/:day/*',
|
|
|
['controller' => 'posts', 'action' => 'view']
|
|
|
);
|
|
|
- $result = Router::parse('/posts/2007/08/01/title-of-post-here');
|
|
|
+ $result = Router::parse('/posts/2007/08/01/title-of-post-here', 'GET');
|
|
|
$expected = [
|
|
|
'year' => '2007',
|
|
|
'month' => '08',
|
|
|
@@ -1398,7 +1382,7 @@ class RouterTest extends TestCase
|
|
|
|
|
|
Router::reload();
|
|
|
$this->_connectDefaultRoutes();
|
|
|
- $result = Router::parse('/pages/display/home');
|
|
|
+ $result = Router::parse('/pages/display/home', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
'pass' => ['home'],
|
|
|
@@ -1407,15 +1391,15 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('pages/display/home/');
|
|
|
+ $result = Router::parse('pages/display/home/', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('pages/display/home');
|
|
|
+ $result = Router::parse('pages/display/home', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/page/*', ['controller' => 'test']);
|
|
|
- $result = Router::parse('/page/my-page');
|
|
|
+ $result = Router::parse('/page/my-page', 'GET');
|
|
|
$expected = ['pass' => ['my-page'], 'plugin' => null, 'controller' => 'test', 'action' => 'index'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
@@ -1425,7 +1409,7 @@ class RouterTest extends TestCase
|
|
|
['language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'],
|
|
|
['language' => '[a-z]{3}']
|
|
|
);
|
|
|
- $result = Router::parse('/eng/contact');
|
|
|
+ $result = Router::parse('/eng/contact', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'language' => 'eng',
|
|
|
@@ -1442,7 +1426,7 @@ class RouterTest extends TestCase
|
|
|
['month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}']
|
|
|
);
|
|
|
|
|
|
- $result = Router::parse('/forestillinger/10/2007/min-forestilling');
|
|
|
+ $result = Router::parse('/forestillinger/10/2007/min-forestilling', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => ['min-forestilling'],
|
|
|
'plugin' => 'shows',
|
|
|
@@ -1456,11 +1440,11 @@ class RouterTest extends TestCase
|
|
|
Router::reload();
|
|
|
Router::connect('/:controller/:action/*');
|
|
|
Router::connect('/', ['plugin' => 'pages', 'controller' => 'pages', 'action' => 'display']);
|
|
|
- $result = Router::parse('/');
|
|
|
+ $result = Router::parse('/', 'GET');
|
|
|
$expected = ['pass' => [], 'controller' => 'pages', 'action' => 'display', 'plugin' => 'pages'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/posts/edit/0');
|
|
|
+ $result = Router::parse('/posts/edit/0', 'GET');
|
|
|
$expected = ['pass' => [0], 'controller' => 'posts', 'action' => 'edit', 'plugin' => null];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
@@ -1470,7 +1454,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'posts', 'action' => 'view'],
|
|
|
['pass' => ['id', 'url_title'], 'id' => '[\d]+']
|
|
|
);
|
|
|
- $result = Router::parse('/posts/5:sample-post-title');
|
|
|
+ $result = Router::parse('/posts/5:sample-post-title', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => ['5', 'sample-post-title'],
|
|
|
'id' => 5,
|
|
|
@@ -1487,7 +1471,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'posts', 'action' => 'view'],
|
|
|
['pass' => ['id', 'url_title'], 'id' => '[\d]+']
|
|
|
);
|
|
|
- $result = Router::parse('/posts/5:sample-post-title/other/params/4');
|
|
|
+ $result = Router::parse('/posts/5:sample-post-title/other/params/4', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => ['5', 'sample-post-title', 'other', 'params', '4'],
|
|
|
'id' => 5,
|
|
|
@@ -1500,7 +1484,7 @@ class RouterTest extends TestCase
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/posts/view/*', ['controller' => 'posts', 'action' => 'view']);
|
|
|
- $result = Router::parse('/posts/view/10?id=123&tab=abc');
|
|
|
+ $result = Router::parse('/posts/view/10?id=123&tab=abc', 'GET');
|
|
|
$expected = ['pass' => [10], 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '?' => ['id' => '123', 'tab' => 'abc']];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
@@ -1510,7 +1494,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'posts', 'action' => 'view'],
|
|
|
['pass' => ['id', 'url_title'], 'id' => $UUID]
|
|
|
);
|
|
|
- $result = Router::parse('/posts/sample-post-title-(uuid:47fc97a9-019c-41d1-a058-1fa3cbdd56cb)');
|
|
|
+ $result = Router::parse('/posts/sample-post-title-(uuid:47fc97a9-019c-41d1-a058-1fa3cbdd56cb)', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => ['47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'sample-post-title'],
|
|
|
'id' => '47fc97a9-019c-41d1-a058-1fa3cbdd56cb',
|
|
|
@@ -1523,7 +1507,7 @@ class RouterTest extends TestCase
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/posts/view/*', ['controller' => 'posts', 'action' => 'view']);
|
|
|
- $result = Router::parse('/posts/view/foo:bar/routing:fun');
|
|
|
+ $result = Router::parse('/posts/view/foo:bar/routing:fun', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => ['foo:bar', 'routing:fun'],
|
|
|
'plugin' => null,
|
|
|
@@ -1545,7 +1529,7 @@ class RouterTest extends TestCase
|
|
|
['controller' => 'subjects', 'action' => 'add'],
|
|
|
['category_id' => '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}']
|
|
|
);
|
|
|
- $result = Router::parse('/subjects/add/4795d601-19c8-49a6-930e-06a8b01d17b7');
|
|
|
+ $result = Router::parse('/subjects/add/4795d601-19c8-49a6-930e-06a8b01d17b7', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'category_id' => '4795d601-19c8-49a6-930e-06a8b01d17b7',
|
|
|
@@ -1569,7 +1553,7 @@ class RouterTest extends TestCase
|
|
|
["extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+', "action" => 'view']
|
|
|
);
|
|
|
|
|
|
- $result = Router::parse('/some_extra/page/this_is_the_slug');
|
|
|
+ $result = Router::parse('/some_extra/page/this_is_the_slug', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -1580,7 +1564,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/page/this_is_the_slug');
|
|
|
+ $result = Router::parse('/page/this_is_the_slug', 'GET');
|
|
|
$expected = [
|
|
|
'pass' => [],
|
|
|
'plugin' => null,
|
|
|
@@ -1629,7 +1613,20 @@ class RouterTest extends TestCase
|
|
|
public function testParseError()
|
|
|
{
|
|
|
Router::connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
|
|
|
- Router::parse('/nope');
|
|
|
+ Router::parse('/nope', 'GET');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test deprecated behavior
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testParseMethodCondition()
|
|
|
+ {
|
|
|
+ Router::connect('/posts', ['controller' => 'Posts', '_method' => 'POST']);
|
|
|
+
|
|
|
+ $_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
+ $this->assertNotEmpty(Router::parse('/posts'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1641,7 +1638,7 @@ class RouterTest extends TestCase
|
|
|
public function testParseReverseSymmetry($url)
|
|
|
{
|
|
|
$this->_connectDefaultRoutes();
|
|
|
- $this->assertSame($url, Router::reverse(Router::parse($url) + ['url' => []]));
|
|
|
+ $this->assertSame($url, Router::reverse(Router::parse($url, 'GET') + ['url' => []]));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1671,10 +1668,10 @@ class RouterTest extends TestCase
|
|
|
|
|
|
$this->_connectDefaultRoutes();
|
|
|
|
|
|
- $result = Router::parse('/posts.rss');
|
|
|
+ $result = Router::parse('/posts.rss', 'GET');
|
|
|
$this->assertEquals('rss', $result['_ext']);
|
|
|
|
|
|
- $result = Router::parse('/posts.xml');
|
|
|
+ $result = Router::parse('/posts.xml', 'GET');
|
|
|
$this->assertFalse(isset($result['_ext']));
|
|
|
|
|
|
Router::extensions(['xml']);
|
|
|
@@ -1743,7 +1740,7 @@ class RouterTest extends TestCase
|
|
|
Router::extensions('rss', false);
|
|
|
$this->_connectDefaultRoutes();
|
|
|
|
|
|
- $result = Router::parse('/posts.rss');
|
|
|
+ $result = Router::parse('/posts.rss', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
'controller' => 'Posts',
|
|
|
@@ -1753,7 +1750,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/posts/view/1.rss');
|
|
|
+ $result = Router::parse('/posts/view/1.rss', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
'controller' => 'Posts',
|
|
|
@@ -1763,7 +1760,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/posts/view/1.rss?query=test');
|
|
|
+ $result = Router::parse('/posts/view/1.rss?query=test', 'GET');
|
|
|
$expected['?'] = ['query' => 'test'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
@@ -1771,7 +1768,7 @@ class RouterTest extends TestCase
|
|
|
Router::extensions(['rss', 'xml'], false);
|
|
|
$this->_connectDefaultRoutes();
|
|
|
|
|
|
- $result = Router::parse('/posts.xml');
|
|
|
+ $result = Router::parse('/posts.xml', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
'controller' => 'Posts',
|
|
|
@@ -1781,7 +1778,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/posts.atom?hello=goodbye');
|
|
|
+ $result = Router::parse('/posts.atom?hello=goodbye', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
'controller' => 'Posts.atom',
|
|
|
@@ -1793,13 +1790,13 @@ class RouterTest extends TestCase
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/controller/action', ['controller' => 'controller', 'action' => 'action', '_ext' => 'rss']);
|
|
|
- $result = Router::parse('/controller/action');
|
|
|
+ $result = Router::parse('/controller/action', 'GET');
|
|
|
$expected = ['controller' => 'controller', 'action' => 'action', 'plugin' => null, '_ext' => 'rss', 'pass' => []];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/controller/action', ['controller' => 'controller', 'action' => 'action', '_ext' => 'rss']);
|
|
|
- $result = Router::parse('/controller/action');
|
|
|
+ $result = Router::parse('/controller/action', 'GET');
|
|
|
$expected = [
|
|
|
'controller' => 'controller',
|
|
|
'action' => 'action',
|
|
|
@@ -1812,7 +1809,7 @@ class RouterTest extends TestCase
|
|
|
Router::reload();
|
|
|
Router::extensions('rss', false);
|
|
|
Router::connect('/controller/action', ['controller' => 'controller', 'action' => 'action', '_ext' => 'rss']);
|
|
|
- $result = Router::parse('/controller/action');
|
|
|
+ $result = Router::parse('/controller/action', 'GET');
|
|
|
$expected = [
|
|
|
'controller' => 'controller',
|
|
|
'action' => 'action',
|
|
|
@@ -2100,25 +2097,25 @@ class RouterTest extends TestCase
|
|
|
Router::connect('/', ['controller' => 'pages', 'action' => 'display', 'home']);
|
|
|
Router::connect('/pages/*', ['controller' => 'pages', 'action' => 'display']);
|
|
|
|
|
|
- $result = Router::parse('/');
|
|
|
+ $result = Router::parse('/', 'GET');
|
|
|
$expected = ['pass' => ['home'], 'plugin' => null, 'controller' => 'pages', 'action' => 'display'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/pages/home/');
|
|
|
+ $result = Router::parse('/pages/home/', 'GET');
|
|
|
$expected = ['pass' => ['home'], 'plugin' => null, 'controller' => 'pages', 'action' => 'display'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/', ['controller' => 'pages', 'action' => 'display', 'home']);
|
|
|
|
|
|
- $result = Router::parse('/');
|
|
|
+ $result = Router::parse('/', 'GET');
|
|
|
$expected = ['pass' => ['home'], 'plugin' => null, 'controller' => 'pages', 'action' => 'display'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
Router::reload();
|
|
|
Router::connect('/', ['controller' => 'posts', 'action' => 'index']);
|
|
|
Router::connect('/pages/*', ['controller' => 'pages', 'action' => 'display']);
|
|
|
- $result = Router::parse('/pages/contact/');
|
|
|
+ $result = Router::parse('/pages/contact/', 'GET');
|
|
|
|
|
|
$expected = ['pass' => ['contact'], 'plugin' => null, 'controller' => 'pages', 'action' => 'display'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
@@ -2133,10 +2130,10 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::reload();
|
|
|
Router::connect('/:controller/:action/*');
|
|
|
- $result = Router::parse('/posts/view/something.');
|
|
|
+ $result = Router::parse('/posts/view/something.', 'GET');
|
|
|
$this->assertEquals('something.', $result['pass'][0], 'Period was chopped off %s');
|
|
|
|
|
|
- $result = Router::parse('/posts/view/something. . .');
|
|
|
+ $result = Router::parse('/posts/view/something. . .', 'GET');
|
|
|
$this->assertEquals('something. . .', $result['pass'][0], 'Period was chopped off %s');
|
|
|
}
|
|
|
|
|
|
@@ -2151,10 +2148,10 @@ class RouterTest extends TestCase
|
|
|
Router::connect('/:controller/:action/*');
|
|
|
Router::extensions('json', false);
|
|
|
|
|
|
- $result = Router::parse('/posts/view/something.');
|
|
|
+ $result = Router::parse('/posts/view/something.', 'GET');
|
|
|
$this->assertEquals('something.', $result['pass'][0], 'Period was chopped off %s');
|
|
|
|
|
|
- $result = Router::parse('/posts/view/something. . .');
|
|
|
+ $result = Router::parse('/posts/view/something. . .', 'GET');
|
|
|
$this->assertEquals('something. . .', $result['pass'][0], 'Period was chopped off %s');
|
|
|
}
|
|
|
|
|
|
@@ -2172,7 +2169,7 @@ class RouterTest extends TestCase
|
|
|
['action' => 'other|actions']
|
|
|
);
|
|
|
|
|
|
- $result = Router::parse('/blog/other');
|
|
|
+ $result = Router::parse('/blog/other', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => null,
|
|
|
'controller' => 'blog_posts',
|
|
|
@@ -2181,7 +2178,7 @@ class RouterTest extends TestCase
|
|
|
];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- Router::parse('/blog/foobar');
|
|
|
+ Router::parse('/blog/foobar', 'GET');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2228,11 +2225,11 @@ class RouterTest extends TestCase
|
|
|
])
|
|
|
);
|
|
|
|
|
|
- $result = Router::parse('/admin/posts/');
|
|
|
+ $result = Router::parse('/admin/posts/', 'GET');
|
|
|
$expected = ['pass' => [], 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = Router::parse('/admin/posts');
|
|
|
+ $result = Router::parse('/admin/posts', 'GET');
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
$result = Router::url(['prefix' => 'admin', 'controller' => 'posts']);
|
|
|
@@ -2257,7 +2254,7 @@ class RouterTest extends TestCase
|
|
|
])
|
|
|
);
|
|
|
|
|
|
- $result = Router::parse('/members/posts/index');
|
|
|
+ $result = Router::parse('/members/posts/index', 'GET');
|
|
|
$expected = ['pass' => [], 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'index'];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
@@ -2361,7 +2358,7 @@ class RouterTest extends TestCase
|
|
|
{
|
|
|
Router::connect('/:locale/:controller/:action/*', [], ['locale' => 'dan|eng']);
|
|
|
|
|
|
- $result = Router::parse('/eng/test/test_action');
|
|
|
+ $result = Router::parse('/eng/test/test_action', 'GET');
|
|
|
$expected = ['pass' => [], 'locale' => 'eng', 'controller' => 'test', 'action' => 'test_action', 'plugin' => null];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
}
|
|
|
@@ -2375,7 +2372,7 @@ class RouterTest extends TestCase
|
|
|
public function testRegexRouteMatchingError()
|
|
|
{
|
|
|
Router::connect('/:locale/:controller/:action/*', [], ['locale' => 'dan|eng']);
|
|
|
- Router::parse('/badness/test/test_action');
|
|
|
+ Router::parse('/badness/test/test_action', 'GET');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2424,7 +2421,7 @@ class RouterTest extends TestCase
|
|
|
['plugin' => 'TestPlugin', 'action' => 'index'],
|
|
|
['routeClass' => 'PluginShortRoute', 'slug' => '[a-z_-]+']
|
|
|
);
|
|
|
- $result = Router::parse('/the-best');
|
|
|
+ $result = Router::parse('/the-best', 'GET');
|
|
|
$expected = [
|
|
|
'plugin' => 'TestPlugin',
|
|
|
'controller' => 'TestPlugin',
|
|
|
@@ -2730,11 +2727,11 @@ class RouterTest extends TestCase
|
|
|
$result = $route->match(['controller' => 'blog_posts', 'action' => 'actions']);
|
|
|
$this->assertEquals('/blog/actions/', $result);
|
|
|
|
|
|
- $result = $route->parse('/blog/other');
|
|
|
+ $result = $route->parse('/blog/other', 'GET');
|
|
|
$expected = ['controller' => 'blog_posts', 'action' => 'other', 'pass' => []];
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result = $route->parse('/blog/foobar');
|
|
|
+ $result = $route->parse('/blog/foobar', 'GET');
|
|
|
$this->assertFalse($result);
|
|
|
}
|
|
|
|