ソースを参照

Merge pull request #254 from dereuromark/table

Fix some skipped tests.
Mark Sch 6 年 前
コミット
e9a763761a

+ 3 - 3
composer.json

@@ -12,12 +12,12 @@
 			"homepage": "https://www.dereuromark.de"
 		}
 	],
-	"require":{
+	"require": {
 		"php": ">=5.6",
 		"cakephp/cakephp": "^3.7.0",
 		"dereuromark/cakephp-shim": "^1.7.0"
 	},
-	"require-dev":{
+	"require-dev": {
 		"cakephp/chronos": "^1.0.1",
 		"mobiledetect/mobiledetectlib": "^2.8",
 		"fig-r/psr2r-sniffer": "dev-master",
@@ -40,7 +40,7 @@
 	"suggest": {
 		"yangqi/htmldom": "For HtmlDom usage"
 	},
-	"support":{
+	"support": {
 		"source": "https://github.com/dereuromark/cakephp-tools",
 		"issues": "https://github.com/dereuromark/cakephp-tools/issues"
 	},

+ 1 - 2
src/Controller/Component/MobileComponent.php

@@ -135,8 +135,7 @@ class MobileComponent extends Component {
 			$this->setMobile = false;
 		}
 
-		//$urlParams = Router::getParams(true);
-		$urlParams = [];
+		$urlParams = $this->getController()->getRequest()->getAttribute('params');
 		if (!isset($urlParams['pass'])) {
 			$urlParams['pass'] = [];
 		}

+ 8 - 5
src/Model/Table/Table.php

@@ -105,8 +105,6 @@ class Table extends ShimTable {
 	/**
 	 * Get all related entries that have been used so far
 	 *
-	 * @deprecated Must be refactored.
-	 *
 	 * @param string $tableName The related model
 	 * @param string|null $groupField Field to group by
 	 * @param string $type Find type
@@ -115,7 +113,8 @@ class Table extends ShimTable {
 	 */
 	public function getRelatedInUse($tableName, $groupField = null, $type = 'all', $options = []) {
 		if ($groupField === null) {
-			$groupField = $this->belongsTo[$tableName]['foreignKey'];
+			/** @var string $groupField */
+			$groupField = $this->getAssociation($tableName)->getForeignKey();
 		}
 		$defaults = [
 			'contain' => [$tableName],
@@ -123,9 +122,10 @@ class Table extends ShimTable {
 			'order' => isset($this->$tableName->order) ? $this->$tableName->order : [$tableName . '.' . $this->$tableName->getDisplayField() => 'ASC'],
 		];
 		if ($type === 'list') {
+			$propertyName = $this->getAssociation($tableName)->getProperty();
 			$defaults['fields'] = [$tableName . '.' . $this->$tableName->getPrimaryKey(), $tableName . '.' . $this->$tableName->getDisplayField()];
-			$defaults['keyField'] = $tableName . '.' . $this->$tableName->getPrimaryKey();
-			$defaults['valueField'] = $tableName . '.' . $this->$tableName->getDisplayField();
+			$defaults['keyField'] = $propertyName . '.' . $this->$tableName->getPrimaryKey();
+			$defaults['valueField'] = $propertyName . '.' . $this->$tableName->getDisplayField();
 		}
 		$options += $defaults;
 
@@ -147,8 +147,11 @@ class Table extends ShimTable {
 		];
 		if ($type === 'list') {
 			$defaults['fields'] = ['' . $this->getPrimaryKey(), '' . $this->getDisplayField()];
+			$defaults['keyField'] = $this->getPrimaryKey();
+			$defaults['valueField'] = $this->getDisplayField();
 		}
 		$options += $defaults;
+
 		return $this->find($type, $options);
 	}
 

+ 1 - 1
src/Utility/Utility.php

@@ -288,7 +288,7 @@ class Utility {
 	/**
 	 * Parse headers from a specific URL content.
 	 *
-	 * @param string $urlArray
+	 * @param string $url
 	 *
 	 * @return mixed array of headers or FALSE on failure
 	 */

+ 2 - 2
src/View/Helper/UrlHelper.php

@@ -60,7 +60,7 @@ class UrlHelper extends CoreUrlHelper {
 			$url += $this->defaults();
 		}
 
-		return parent::build($url, $full);
+		return $this->build($url, $full);
 	}
 
 	/**
@@ -77,7 +77,7 @@ class UrlHelper extends CoreUrlHelper {
 			$url = $this->addQueryStrings($url);
 		}
 
-		return parent::build($url, $full);
+		return $this->build($url, $full);
 	}
 
 	/**

+ 11 - 10
tests/TestCase/Controller/Component/CommonComponentTest.php

@@ -14,12 +14,12 @@ class CommonComponentTest extends TestCase {
 	/**
 	 * @var \App\Controller\CommonComponentTestController
 	 */
-	public $Controller;
+	protected $Controller;
 
 	/**
 	 * @var \Cake\Http\ServerRequest
 	 */
-	public $request;
+	protected $request;
 
 	/**
 	 * @return void
@@ -138,9 +138,9 @@ class CommonComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testPostRedirect() {
-		$this->Controller->Common->postRedirect(['action' => 'foo']);
+		$this->Controller->Common->postRedirect(['controller' => 'MyController', 'action' => 'foo']);
 		$is = $this->Controller->getResponse()->getHeaderLine('Location');
-		$this->assertSame('http://localhost/foo', $is);
+		$this->assertSame('http://localhost/my-controller/foo', $is);
 		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
@@ -148,9 +148,9 @@ class CommonComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testAutoRedirect() {
-		$this->Controller->Common->autoRedirect(['action' => 'foo']);
+		$this->Controller->Common->autoRedirect(['controller' => 'MyController', 'action' => 'foo']);
 		$is = $this->Controller->getResponse()->getHeaderLine('Location');
-		$this->assertSame('http://localhost/foo', $is);
+		$this->assertSame('http://localhost/my-controller/foo', $is);
 		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
@@ -161,7 +161,7 @@ class CommonComponentTest extends TestCase {
 		$url = 'http://localhost/my-controller/some-referer-action';
 		$this->Controller->setRequest($this->Controller->getRequest()->withEnv('HTTP_REFERER', $url));
 
-		$this->Controller->Common->autoRedirect(['action' => 'foo'], true);
+		$this->Controller->Common->autoRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
 		$is = $this->Controller->getResponse()->getHeaderLine('Location');
 		$this->assertSame($url, $is);
 		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
@@ -171,9 +171,9 @@ class CommonComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testAutoPostRedirect() {
-		$this->Controller->Common->autoPostRedirect(['action' => 'foo'], true);
+		$this->Controller->Common->autoPostRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
 		$is = $this->Controller->getResponse()->getHeaderLine('Location');
-		$this->assertSame('http://localhost/foo', $is);
+		$this->assertSame('http://localhost/my-controller/foo', $is);
 		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
@@ -204,7 +204,8 @@ class CommonComponentTest extends TestCase {
 	public function testAutoPostRedirectRefererNotWhitelisted() {
 		$this->Controller->setRequest($this->Controller->getRequest()->withEnv('HTTP_REFERER', 'http://localhost/my-controller/wrong'));
 
-		$is = $this->Controller->Common->autoPostRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
+		$this->Controller->Common->autoPostRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
+
 		$is = $this->Controller->getResponse()->getHeaderLine('Location');
 		$this->assertSame('http://localhost/my-controller/foo', $is);
 		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());

+ 12 - 6
tests/TestCase/Controller/Component/MobileComponentTest.php

@@ -24,12 +24,12 @@ class MobileComponentTest extends TestCase {
 	/**
 	 * @var \Cake\Event\Event
 	 */
-	public $event;
+	protected $event;
 
 	/**
 	 * @var \App\Controller\MobileComponentTestController
 	 */
-	public $Controller;
+	protected $Controller;
 
 	/**
 	 * SetUp method
@@ -91,7 +91,10 @@ class MobileComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testMobileForceActivated() {
-		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['mobile' => 1]));
+		$request = $this->Controller->getRequest()
+			->withAttribute('params', ['controller' => 'MyController'])
+			->withQueryParams(['mobile' => 1]);
+		$this->Controller->setRequest($request);
 
 		$this->Controller->Mobile->beforeFilter($this->event);
 		$session = $this->Controller->getRequest()->getSession()->read('User');
@@ -102,14 +105,17 @@ class MobileComponentTest extends TestCase {
 
 		$configure = Configure::read('User');
 		$this->assertSame(['isMobile' => 0, 'setMobile' => 1], $configure);
-		$this->assertEquals(['desktopUrl' => '/?mobile=0'], $this->Controller->viewVars);
+		$this->assertEquals(['desktopUrl' => '/my-controller?mobile=0'], $this->Controller->viewVars);
 	}
 
 	/**
 	 * @return void
 	 */
 	public function testMobileForceDeactivated() {
-		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['mobile' => 0]));
+		$request = $this->Controller->getRequest()
+			->withAttribute('params', ['controller' => 'MyController'])
+			->withQueryParams(['mobile' => 0]);
+		$this->Controller->setRequest($request);
 
 		$this->Controller->Mobile->beforeFilter($this->event);
 		$session = $this->Controller->getRequest()->getSession()->read('User');
@@ -118,7 +124,7 @@ class MobileComponentTest extends TestCase {
 		$this->Controller->Mobile->setMobile();
 		$configure = Configure::read('User');
 		$this->assertSame(['isMobile' => 0, 'setMobile' => 0], $configure);
-		$this->assertEquals(['mobileUrl' => '/?mobile=1'], $this->Controller->viewVars);
+		$this->assertEquals(['mobileUrl' => '/my-controller?mobile=1'], $this->Controller->viewVars);
 	}
 
 	/**

+ 2 - 2
tests/TestCase/Controller/Component/RefererRedirectComponentTest.php

@@ -16,12 +16,12 @@ class RefererRedirectComponentTest extends TestCase {
 	/**
 	 * @var \Cake\Event\Event
 	 */
-	public $event;
+	protected $event;
 
 	/**
 	 * @var \App\Controller\RefererRedirectComponentTestController
 	 */
-	public $Controller;
+	protected $Controller;
 
 	/**
 	 * @return void

+ 25 - 23
tests/TestCase/Controller/Component/UrlComponentTest.php

@@ -8,6 +8,7 @@ use Cake\Event\Event;
 use Cake\Http\ServerRequest;
 use Cake\Routing\RouteBuilder;
 use Cake\Routing\Router;
+use Cake\Routing\Route\DashedRoute;
 use Tools\TestSuite\TestCase;
 
 class UrlComponentTest extends TestCase {
@@ -15,12 +16,12 @@ class UrlComponentTest extends TestCase {
 	/**
 	 * @var \Cake\Event\Event
 	 */
-	public $event;
+	protected $event;
 
 	/**
 	 * @var \App\Controller\UrlComponentTestController
 	 */
-	public $Controller;
+	protected $Controller;
 
 	/**
 	 * @return void
@@ -59,12 +60,12 @@ class UrlComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testBuild() {
-		$is = $this->Controller->Url->build(['action' => 'x']);
-		$expected = '/x';
+		$is = $this->Controller->Url->build(['controller' => 'MyController', 'action' => 'x']);
+		$expected = '/my-controller/x';
 		$this->assertSame($expected, $is);
 
-		$is = $this->Controller->Url->build(['action' => 'x'], ['fullBase' => true]);
-		$expected = 'http://localhost/x';
+		$is = $this->Controller->Url->build(['controller' => 'MyController', 'action' => 'x'], ['fullBase' => true]);
+		$expected = 'http://localhost/my-controller/x';
 		$this->assertSame($expected, $is);
 	}
 
@@ -72,9 +73,9 @@ class UrlComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testResetArray() {
-		$result = $this->Controller->Url->resetArray(['controller' => 'foobar', 'action' => 'test']);
+		$result = $this->Controller->Url->resetArray(['controller' => 'FooBar', 'action' => 'test']);
 		$expected = [
-			'controller' => 'foobar',
+			'controller' => 'FooBar',
 			'action' => 'test',
 			'prefix' => false,
 			'plugin' => false,
@@ -88,9 +89,9 @@ class UrlComponentTest extends TestCase {
 	public function testCompleteArray() {
 		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['x' => 'y']));
 
-		$result = $this->Controller->Url->completeArray(['controller' => 'foobar', 'action' => 'test']);
+		$result = $this->Controller->Url->completeArray(['controller' => 'FooBar', 'action' => 'test']);
 		$expected = [
-			'controller' => 'foobar',
+			'controller' => 'FooBar',
 			'action' => 'test',
 			'?' => ['x' => 'y'],
 		];
@@ -101,34 +102,35 @@ class UrlComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testBuildReset() {
-		Router::connect('/:controller/:action/*');
-
-		$result = $this->Controller->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
-		$expected = '/foobar/test';
+		$result = $this->Controller->Url->buildReset(['controller' => 'FooBar', 'action' => 'test']);
+		$expected = '/foo-bar/test';
 		$this->assertSame($expected, $result);
 
 		$request = $this->Controller->getRequest();
 		$request = $request->withAttribute('here', '/admin/foo/bar/baz/test')
+			->withParam('admin', true)
 			->withParam('prefix', 'admin')
 			->withParam('plugin', 'Foo');
 		$this->Controller->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->Controller->getRequest());
 
-		$result = $this->Controller->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
+		$result = $this->Controller->Url->build(['controller' => 'Bar', 'action' => 'baz', 'x']);
 		$expected = '/admin/foo/bar/baz/x';
 		$this->assertSame($expected, $result);
 
-		$result = $this->Controller->Url->buildReset(['controller' => 'bar', 'action' => 'baz', 'x']);
+		$result = $this->Controller->Url->buildReset(['controller' => 'Bar', 'action' => 'baz', 'x']);
 		$expected = '/bar/baz/x';
 		$this->assertSame($expected, $result);
 	}
@@ -139,15 +141,15 @@ class UrlComponentTest extends TestCase {
 	public function testBuildComplete() {
 		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['x' => 'y']));
 
-		$result = $this->Controller->Url->buildComplete(['action' => 'test']);
-		$expected = '/test?x=y';
+		$result = $this->Controller->Url->buildComplete(['controller' => 'MyController', 'action' => 'test']);
+		$expected = '/my-controller/test?x=y';
 		$this->assertSame($expected, $result);
 
-		$result = $this->Controller->Url->buildComplete(['action' => 'test', '?' => ['a' => 'b']]);
-		$expected = '/test?a=b&x=y';
+		$result = $this->Controller->Url->buildComplete(['controller' => 'MyController', 'action' => 'test', '?' => ['a' => 'b']]);
+		$expected = '/my-controller/test?a=b&x=y';
 		$this->assertSame($expected, $result);
 
-		$expected = '/test?a=b&x=y';
+		$expected = '/my-controller/test?a=b&x=y';
 		$this->assertSame($expected, h($result));
 	}
 

+ 27 - 12
tests/TestCase/Model/Table/TableTest.php

@@ -6,6 +6,7 @@ use Cake\Datasource\ConnectionManager;
 use Cake\I18n\Time;
 use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
+use Cake\Utility\Hash;
 use Tools\TestSuite\TestCase;
 
 class TableTest extends TestCase {
@@ -23,7 +24,12 @@ class TableTest extends TestCase {
 	/**
 	 * @var \Tools\Model\Table\Table;
 	 */
-	public $Users;
+	protected $Users;
+
+	/**
+	 * @var \Tools\Model\Table\Table;
+	 */
+	protected $Posts;
 
 	/**
 	 * SetUp method
@@ -173,30 +179,39 @@ class TableTest extends TestCase {
 	}
 
 	/**
-	 * TableTest::testGetRelatedInUse()
-	 *
 	 * @return void
 	 */
 	public function testGetRelatedInUse() {
-		$this->skipIf(true, 'TODO');
 		$results = $this->Posts->getRelatedInUse('Authors', 'author_id', 'list');
 		$expected = [1 => 'mariano', 3 => 'larry'];
 		$this->assertEquals($expected, $results->toArray());
+
+		$results = $this->Posts->getRelatedInUse('Authors', null, 'list');
+		$expected = [1 => 'mariano', 3 => 'larry'];
+		$this->assertEquals($expected, $results->toArray());
 	}
 
 	/**
-	 * TableTest::testGetFieldInUse()
-	 *
 	 * @return void
 	 */
 	public function testGetFieldInUse() {
-		$this->skipIf(true, 'TODO');
-		$this->db = ConnectionManager::get('test');
-		$this->skipIf(!($this->db instanceof Mysql), 'The test is only compatible with Mysql.');
-
-		$results = $this->Posts->getFieldInUse('author_id', 'list');
-		$expected = [1 => 'First Post', 2 => 'Second Post'];
+		$results = $this->Posts->getFieldInUse('author_id', 'list')->toArray();
+		/*
+		$expected = [2 => 'Second Post', 3 => 'Third Post'];
 		$this->assertEquals($expected, $results);
+		*/
+		$this->assertCount(2, $results);
+
+		$results = $this->Posts->getFieldInUse('author_id')->toArray();
+		/*
+		$expected = ['Second Post', 'Third Post'];
+		$this->assertEquals($expected, Hash::extract($results, '{n}.title'));
+		*/
+
+		$ids = Hash::extract($results, '{n}.author_id');
+		sort($ids);
+		$expected = [1, 3];
+		$this->assertEquals($expected, $ids);
 	}
 
 	/**

+ 5 - 5
tests/TestCase/Model/Table/TokensTableTest.php

@@ -8,11 +8,6 @@ use Tools\TestSuite\TestCase;
 class TokensTableTest extends TestCase {
 
 	/**
-	 * @var \Tools\Model\Table\TokensTable;
-	 */
-	public $Tokens;
-
-	/**
 	 * @var array
 	 */
 	public $fixtures = [
@@ -20,6 +15,11 @@ class TokensTableTest extends TestCase {
 	];
 
 	/**
+	 * @var \Tools\Model\Table\TokensTable;
+	 */
+	protected $Tokens;
+
+	/**
 	 * @return void
 	 */
 	public function setUp() {

+ 0 - 12
tests/TestCase/Utility/TimeTest.php

@@ -714,18 +714,6 @@ class TimeTest extends TestCase {
 	}
 
 	/**
-	 * TimeTest::testTimezoneByCoordinates()
-	 *
-	 * @return void
-	 */
-	public function testTimezoneByCoordinates() {
-		$this->skipIf(true);
-
-		$result = $this->Time->timezoneByCoordinates(48, 11);
-		$this->assertEquals('Europe/Vaduz', $result);
-	}
-
-	/**
 	 * @return void
 	 */
 	public function testCweeks() {

+ 0 - 2
tests/TestCase/View/Helper/CommonHelperTest.php

@@ -2,7 +2,6 @@
 
 namespace Tools\Test\TestCase\View\Helper;
 
-use Cake\Routing\Router;
 use Cake\View\View;
 use Tools\TestSuite\TestCase;
 use Tools\View\Helper\CommonHelper;
@@ -23,7 +22,6 @@ class CommonHelperTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		Router::reload();
 		$View = new View(null);
 		$this->Common = new CommonHelper($View);
 	}

+ 12 - 9
tests/TestCase/View/Helper/FormatHelperTest.php

@@ -309,15 +309,15 @@ class FormatHelperTest extends TestCase {
 			'next' => ['id' => 2, 'foo' => 'My FooBaz'],
 		];
 
-		$result = $this->Format->neighbors($neighbors, 'foo', ['slug' => true]);
+		// Only needed for fake requests (tests)
+		$url = ['controller' => 'MyController', 'action' => 'myAction'];
+		$result = $this->Format->neighbors($neighbors, 'foo', ['slug' => true, 'url' => $url]);
 
-		$expected = '<div class="next-prev-navi nextPrevNavi"><a href="/index/1/My-Foo" title="My Foo"><i class="icon icon-prev fa fa-prev" title="Prev" data-placement="bottom" data-toggle="tooltip"></i>&nbsp;prevRecord</a>&nbsp;&nbsp;<a href="/index/2/My-FooBaz" title="My FooBaz"><i class="icon icon-next fa fa-next" title="Next" data-placement="bottom" data-toggle="tooltip"></i>&nbsp;nextRecord</a></div>';
+		$expected = '<div class="next-prev-navi nextPrevNavi"><a href="/my-controller/my-action/1/My-Foo" title="My Foo"><i class="icon icon-prev fa fa-prev" title="Prev" data-placement="bottom" data-toggle="tooltip"></i>&nbsp;prevRecord</a>&nbsp;&nbsp;<a href="/my-controller/my-action/2/My-FooBaz" title="My FooBaz"><i class="icon icon-next fa fa-next" title="Next" data-placement="bottom" data-toggle="tooltip"></i>&nbsp;nextRecord</a></div>';
 		$this->assertEquals($expected, $result);
 	}
 
 	/**
-	 * FormatHelperTest::testTab2space()
-	 *
 	 * @return void
 	 */
 	public function testTab2space() {
@@ -325,14 +325,17 @@ class FormatHelperTest extends TestCase {
 		$text .= "fooo\t\tbar\t\tbla\n";
 		$text .= "foooo\t\tbar\t\tbla\n";
 		$result = $this->Format->tab2space($text);
-		//echo "<pre>" . $text . "</pre>";
-		//echo'becomes';
-		//echo "<pre>" . $result . "</pre>";
+
+		$expected = <<<TXT
+foo          foobar        bla
+fooo         bar           bla
+foooo        bar           bla
+
+TXT;
+		$this->assertTextEquals($expected, $result);
 	}
 
 	/**
-	 * FormatHelperTest::testArray2table()
-	 *
 	 * @return void
 	 */
 	public function testArray2table() {

+ 17 - 20
tests/TestCase/View/Helper/HtmlHelperTest.php

@@ -6,6 +6,7 @@ use Cake\Core\Plugin;
 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\HtmlHelper;
@@ -48,34 +49,30 @@ class HtmlHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testLinkReset() {
-		Router::connect('/:controller/:action/*');
-
-		$result = $this->Html->linkReset('Foo', ['controller' => 'foobar', 'action' => 'test']);
-		$expected = '<a href="/foobar/test">Foo</a>';
+		$result = $this->Html->linkReset('Foo', ['controller' => 'FooBar', 'action' => 'test']);
+		$expected = '<a href="/foo-bar/test">Foo</a>';
 		$this->assertEquals($expected, $result);
 
 		$request = $this->Html->getView()->getRequest();
-		$request = $request->withAttribute('here', '/admin/foobar/test')
+		$request = $request->withAttribute('here', '/admin/foo-bar/test')
 			->withParam('admin', true)
 			->withParam('prefix', 'admin');
 		$this->Html->getView()->setRequest($request);
-		Router::reload();
-		Router::connect('/:controller/:action/*');
 		Router::prefix('admin', function (RouteBuilder $routes) {
-			$routes->connect('/:controller/:action/*');
+			$routes->fallbacks(DashedRoute::class);
 		});
+		Router::pushRequest($request);
 
-		$result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
-		$expected = '<a href="/admin/foobar/test">Foo</a>';
+		$result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'FooBar', 'action' => 'test']);
+		$expected = '<a href="/admin/foo-bar/test">Foo</a>';
 		$this->assertEquals($expected, $result);
 
-		$result = $this->Html->link('Foo', ['controller' => 'foobar', 'action' => 'test']);
-		$expected = '<a href="/admin/foobar/test">Foo</a>';
-		//debug($result);
-		//$this->assertEquals($expected, $result);
+		$result = $this->Html->link('Foo', ['controller' => 'FooBar', 'action' => 'test']);
+		$expected = '<a href="/admin/foo-bar/test">Foo</a>';
+		$this->assertEquals($expected, $result);
 
-		$result = $this->Html->linkReset('Foo', ['controller' => 'foobar', 'action' => 'test']);
-		$expected = '<a href="/foobar/test">Foo</a>';
+		$result = $this->Html->linkReset('Foo', ['controller' => 'FooBar', 'action' => 'test']);
+		$expected = '<a href="/foo-bar/test">Foo</a>';
 		$this->assertEquals($expected, $result);
 	}
 
@@ -87,12 +84,12 @@ class HtmlHelperTest extends TestCase {
 	public function testLinkComplete() {
 		$this->Html->getView()->setRequest($this->Html->getView()->getRequest()->withQueryParams(['x' => 'y']));
 
-		$result = $this->Html->linkComplete('Foo', ['action' => 'test']);
-		$expected = '<a href="/test?x=y">Foo</a>';
+		$result = $this->Html->linkComplete('Foo', ['controller' => 'FooBar', 'action' => 'test']);
+		$expected = '<a href="/foo-bar/test?x=y">Foo</a>';
 		$this->assertEquals($expected, $result);
 
-		$result = $this->Html->linkComplete('Foo', ['action' => 'test', '?' => ['a' => 'b']]);
-		$expected = '<a href="/test?a=b&amp;x=y">Foo</a>';
+		$result = $this->Html->linkComplete('Foo', ['controller' => 'FooBar', 'action' => 'test', '?' => ['a' => 'b']]);
+		$expected = '<a href="/foo-bar/test?a=b&amp;x=y">Foo</a>';
 		$this->assertEquals($expected, $result);
 	}
 

+ 2 - 3
tests/TestCase/View/Helper/TimeHelperTest.php

@@ -62,12 +62,11 @@ class TimeHelperTest extends TestCase {
 	 */
 	public function testTimeAgoInWords() {
 		$res = $this->Time->timeAgoInWords(date(FORMAT_DB_DATETIME, time() - 4 * DAY - 5 * HOUR));
-		$this->debug($res);
+
+		$this->assertNotEmpty($res);
 	}
 
 	/**
-	 * DatetimeHelperTest::testPublished()
-	 *
 	 * @return void
 	 */
 	public function testPublished() {

+ 46 - 25
tests/TestCase/View/Helper/UrlHelperTest.php

@@ -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&amp;x=y';
+		$result = $this->Url->buildComplete(['controller' => 'FooBar', 'action' => 'test', '?' => ['a' => 'b']]);
+		$expected = '/foo-bar/test?a=b&amp;x=y';
 		$this->assertSame($expected, $result);
 	}
 

+ 2 - 0
tests/config/bootstrap.php

@@ -0,0 +1,2 @@
+<?php
+require ROOT . DS . 'config' . DS . 'bootstrap.php';

+ 0 - 1
tests/phpstan.neon

@@ -6,7 +6,6 @@ parameters:
 		- %rootDir%/../../../src/View/Helper/TreeHelper
 		- %rootDir%/../../../src/Utility/Mime
 	ignoreErrors:
-		- '#Access to an undefined property .+Table::\$belongsTo#'
 		- '#Call to an undefined method .+TimeHelper::.+\(\)#'
 		- '#Access to protected property .+ServerRequest::\$.+#'
 		- '#Return type \(bool\) of method .+Email::send\(\) should be compatible with return type \(array\) of method .+Email::send\(\)#'