|
|
@@ -5,6 +5,7 @@ namespace Tools\Test\TestCase\View\Helper;
|
|
|
use Cake\Http\ServerRequest;
|
|
|
use Cake\Routing\RouteBuilder;
|
|
|
use Cake\Routing\Router;
|
|
|
+use Cake\Routing\Route\DashedRoute;
|
|
|
use Cake\View\View;
|
|
|
use Tools\TestSuite\TestCase;
|
|
|
use Tools\View\Helper\UrlHelper;
|
|
|
@@ -32,34 +33,55 @@ class UrlHelperTest extends TestCase {
|
|
|
/**
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testBuildReset() {
|
|
|
- Router::connect('/:controller/:action/*');
|
|
|
+ public function testResetArray() {
|
|
|
+ $result = $this->Url->resetArray(['action' => 'fooBar']);
|
|
|
+ $expected = [
|
|
|
+ 'prefix' => false,
|
|
|
+ 'plugin' => false,
|
|
|
+ 'action' => 'fooBar',
|
|
|
+ ];
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
|
|
|
- $result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
|
|
|
- $expected = '/foobar/test';
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testCompleteArray() {
|
|
|
+ $result = $this->Url->completeArray(['action' => 'fooBar']);
|
|
|
+ $expected = [
|
|
|
+ 'action' => 'fooBar',
|
|
|
+ '?' => [],
|
|
|
+ ];
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testBuildReset() {
|
|
|
+ $result = $this->Url->buildReset(['controller' => 'FooBar', 'action' => 'test']);
|
|
|
+ $expected = '/foo-bar/test';
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
$request = $this->Url->getView()->getRequest();
|
|
|
- $request = $request->withAttribute('here', '/admin/foobar/test')
|
|
|
+ $request = $request->withAttribute('here', '/admin/foo-bar/test')
|
|
|
->withParam('prefix', 'admin');
|
|
|
$this->Url->getView()->setRequest($request);
|
|
|
- Router::reload();
|
|
|
- Router::connect('/:controller/:action/*');
|
|
|
Router::prefix('admin', function (RouteBuilder $routes) {
|
|
|
$routes->fallbacks();
|
|
|
});
|
|
|
Router::pushRequest($this->Url->getView()->getRequest());
|
|
|
|
|
|
- $result = $this->Url->build(['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
|
|
|
- $expected = '/admin/foobar/test';
|
|
|
+ $result = $this->Url->build(['prefix' => 'admin', 'controller' => 'FooBar', 'action' => 'test']);
|
|
|
+ $expected = '/admin/foo-bar/test';
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
- $result = $this->Url->build(['controller' => 'foobar', 'action' => 'test']);
|
|
|
- $expected = '/admin/foobar/test';
|
|
|
+ $result = $this->Url->build(['controller' => 'FooBar', 'action' => 'test']);
|
|
|
+ $expected = '/admin/foo-bar/test';
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
- $result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
|
|
|
- $expected = '/foobar/test';
|
|
|
+ $result = $this->Url->buildReset(['controller' => 'FooBar', 'action' => 'test']);
|
|
|
+ $expected = '/foo-bar/test';
|
|
|
$this->assertSame($expected, $result);
|
|
|
}
|
|
|
|
|
|
@@ -67,10 +89,8 @@ class UrlHelperTest extends TestCase {
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testBuildResetWithPlugin() {
|
|
|
- Router::connect('/:controller/:action/*');
|
|
|
-
|
|
|
- $result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
|
|
|
- $expected = '/foobar/test';
|
|
|
+ $result = $this->Url->buildReset(['controller' => 'FooBar', 'action' => 'test']);
|
|
|
+ $expected = '/foo-bar/test';
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
$request = $this->Url->getView()->getRequest();
|
|
|
@@ -79,22 +99,23 @@ class UrlHelperTest extends TestCase {
|
|
|
->withParam('plugin', 'Foo');
|
|
|
$this->Url->getView()->setRequest($request);
|
|
|
Router::reload();
|
|
|
+ Router::defaultRouteClass(DashedRoute::class);
|
|
|
Router::connect('/:controller/:action/*');
|
|
|
Router::plugin('Foo', function (RouteBuilder $routes) {
|
|
|
- $routes->fallbacks();
|
|
|
+ $routes->fallbacks(DashedRoute::class);
|
|
|
});
|
|
|
Router::prefix('admin', function (RouteBuilder $routes) {
|
|
|
$routes->plugin('Foo', function (RouteBuilder $routes) {
|
|
|
- $routes->fallbacks();
|
|
|
+ $routes->fallbacks(DashedRoute::class);
|
|
|
});
|
|
|
});
|
|
|
Router::pushRequest($this->Url->getView()->getRequest());
|
|
|
|
|
|
- $result = $this->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
|
|
|
+ $result = $this->Url->build(['controller' => 'Bar', 'action' => 'baz', 'x']);
|
|
|
$expected = '/admin/foo/bar/baz/x';
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
- $result = $this->Url->buildReset(['controller' => 'bar', 'action' => 'baz', 'x']);
|
|
|
+ $result = $this->Url->buildReset(['controller' => 'Bar', 'action' => 'baz', 'x']);
|
|
|
$expected = '/bar/baz/x';
|
|
|
$this->assertSame($expected, $result);
|
|
|
}
|
|
|
@@ -105,12 +126,12 @@ class UrlHelperTest extends TestCase {
|
|
|
public function testBuildComplete() {
|
|
|
$this->Url->getView()->setRequest($this->Url->getView()->getRequest()->withQueryParams(['x' => 'y']));
|
|
|
|
|
|
- $result = $this->Url->buildComplete(['action' => 'test']);
|
|
|
- $expected = '/test?x=y';
|
|
|
+ $result = $this->Url->buildComplete(['controller' => 'FooBar', 'action' => 'test']);
|
|
|
+ $expected = '/foo-bar/test?x=y';
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
- $result = $this->Url->buildComplete(['action' => 'test', '?' => ['a' => 'b']]);
|
|
|
- $expected = '/test?a=b&x=y';
|
|
|
+ $result = $this->Url->buildComplete(['controller' => 'FooBar', 'action' => 'test', '?' => ['a' => 'b']]);
|
|
|
+ $expected = '/foo-bar/test?a=b&x=y';
|
|
|
$this->assertSame($expected, $result);
|
|
|
}
|
|
|
|