浏览代码

Merge pull request #223 from challgren/cake37-tests

Fixing deprecations in TestCases
Mark Sch 7 年之前
父节点
当前提交
afc8e87b19
共有 25 个文件被更改,包括 238 次插入140 次删除
  1. 8 20
      tests/TestCase/Auth/MultiColumnAuthenticateTest.php
  2. 143 26
      tests/TestCase/Controller/Component/CommonComponentTest.php
  3. 9 9
      tests/TestCase/Controller/Component/MobileComponentTest.php
  4. 8 8
      tests/TestCase/Controller/Component/UrlComponentTest.php
  5. 1 1
      tests/TestCase/Controller/ControllerTest.php
  6. 1 2
      tests/TestCase/Form/ContactFormTest.php
  7. 28 35
      tests/TestCase/Mailer/EmailTest.php
  8. 1 1
      tests/TestCase/Model/Behavior/BitmaskedBehaviorTest.php
  9. 3 3
      tests/TestCase/Model/Behavior/ConfirmableBehaviorTest.php
  10. 1 1
      tests/TestCase/Model/Behavior/JsonableBehaviorTest.php
  11. 1 1
      tests/TestCase/Model/Behavior/NeighborBehaviorTest.php
  12. 1 1
      tests/TestCase/Model/Behavior/PasswordableBehaviorTest.php
  13. 1 1
      tests/TestCase/Model/Behavior/ResetBehaviorTest.php
  14. 1 1
      tests/TestCase/Model/Behavior/SluggedBehaviorTest.php
  15. 1 1
      tests/TestCase/Model/Behavior/StringBehaviorTest.php
  16. 1 1
      tests/TestCase/Model/Behavior/ToggleBehaviorTest.php
  17. 1 1
      tests/TestCase/Model/Behavior/TypeMapBehaviorTest.php
  18. 1 1
      tests/TestCase/Model/Behavior/TypographicBehaviorTest.php
  19. 1 1
      tests/TestCase/Model/Entity/EntityTest.php
  20. 3 3
      tests/TestCase/Model/Table/TableTest.php
  21. 1 1
      tests/TestCase/Model/Table/TokensTableTest.php
  22. 7 7
      tests/TestCase/View/Helper/HtmlHelperTest.php
  23. 1 1
      tests/TestCase/View/Helper/TreeHelperTest.php
  24. 13 12
      tests/TestCase/View/Helper/UrlHelperTest.php
  25. 1 1
      tests/bootstrap.php

+ 8 - 20
tests/TestCase/Auth/MultiColumnAuthenticateTest.php

@@ -45,7 +45,7 @@ class MultiColumnAuthenticateTest extends TestCase {
 		]);
 
 		$password = password_hash('password', PASSWORD_DEFAULT);
-		$MultiColumnUsers = TableRegistry::get('MultiColumnUsers');
+		$MultiColumnUsers = TableRegistry::getTableLocator()->get('MultiColumnUsers');
 		$MultiColumnUsers->updateAll(['password' => $password], []);
 
 		$this->response = $this->getMockBuilder('Cake\Http\Response')->getMock();
@@ -65,17 +65,11 @@ class MultiColumnAuthenticateTest extends TestCase {
 			'updated' => new Time('2007-03-17 01:18:31')
 		];
 
-		$request->data = [
-			'user_name' => 'mariano',
-			'password' => 'password'
-		];
+		$request = $request->withData('user_name', 'mariano')->withData('password', 'password');
 		$result = $this->auth->authenticate($request, $this->response);
 		$this->assertEquals($expected, $result);
 
-		$request->data = [
-			'user_name' => 'mariano@example.com',
-			'password' => 'password'
-		];
+		$request = $request->withData('user_name', 'mariano@example.com')->withData('password', 'password');
 		$result = $this->auth->authenticate($request, $this->response);
 		$this->assertEquals($expected, $result);
 	}
@@ -84,7 +78,7 @@ class MultiColumnAuthenticateTest extends TestCase {
 	 */
 	public function testAuthenticateNoUsername() {
 		$request = new ServerRequest('posts/index');
-		$request->data = ['password' => 'foobar'];
+		$request = $request->withData('password', 'foobar');
 		$this->assertFalse($this->auth->authenticate($request, $this->response));
 	}
 
@@ -93,10 +87,10 @@ class MultiColumnAuthenticateTest extends TestCase {
 	 */
 	public function testAuthenticateNoPassword() {
 		$request = new ServerRequest('posts/index');
-		$request->data = ['user_name' => 'mariano'];
+		$request = $request->withData('user_name', 'mariano');
 		$this->assertFalse($this->auth->authenticate($request, $this->response));
 
-		$request->data = ['user_name' => 'mariano@example.com'];
+		$request = $request->withData('user_name', 'mariano@example.com');
 		$this->assertFalse($this->auth->authenticate($request, $this->response));
 	}
 
@@ -105,10 +99,7 @@ class MultiColumnAuthenticateTest extends TestCase {
 	 */
 	public function testAuthenticateInjection() {
 		$request = new ServerRequest('posts/index');
-		$request->data = [
-			'user_name' => '> 1',
-			'password' => "' OR 1 = 1"
-		];
+		$request = $request->withData('user_name', '> 1')->withData('password', "' OR 1 = 1");
 		$this->assertFalse($this->auth->authenticate($request, $this->response));
 	}
 
@@ -120,10 +111,7 @@ class MultiColumnAuthenticateTest extends TestCase {
 	public function testAuthenticateScopeFail() {
 		$this->auth->setConfig('scope', ['user_name' => 'nate']);
 		$request = new ServerRequest('posts/index');
-		$request->data = [
-			'user_name' => 'mariano',
-			'password' => 'password'
-		];
+		$request = $request->withData('user_name', 'mariano')->withData('password', 'password');
 
 		$this->assertFalse($this->auth->authenticate($request, $this->response));
 	}

+ 143 - 26
tests/TestCase/Controller/Component/CommonComponentTest.php

@@ -4,7 +4,9 @@ namespace Tools\Test\TestCase\Controller\Component;
 
 use App\Controller\CommonComponentTestController;
 use Cake\Core\Configure;
+use Cake\Event\Event;
 use Cake\Http\ServerRequest;
+use Tools\Controller\Component\CommonComponent;
 use Tools\TestSuite\TestCase;
 
 /**
@@ -30,8 +32,8 @@ class CommonComponentTest extends TestCase {
 		Configure::write('App.fullBaseUrl', 'http://localhost');
 
 		$this->request = new ServerRequest('/my_controller/foo');
-		$this->request->params['controller'] = 'MyController';
-		$this->request->params['action'] = 'foo';
+		$this->request = $this->request->withParam('controller', 'MyController')
+			->withParam('action', 'foo');
 		$this->Controller = new CommonComponentTestController($this->request);
 		$this->Controller->startupProcess();
 	}
@@ -42,7 +44,6 @@ class CommonComponentTest extends TestCase {
 	public function tearDown() {
 		parent::tearDown();
 
-		unset($this->Controller->Common);
 		unset($this->Controller);
 	}
 
@@ -130,26 +131,29 @@ class CommonComponentTest extends TestCase {
 		$ref = '';
 		$is = $this->Controller->Common->isForeignReferer($ref);
 		$this->assertFalse($is);
+
+		$is = $this->Controller->Common->isForeignReferer();
+		$this->assertFalse($is);
 	}
 
 	/**
 	 * @return void
 	 */
 	public function testPostRedirect() {
-		$is = $this->Controller->Common->postRedirect(['action' => 'foo']);
-		$is = $this->Controller->response->header();
-		$this->assertSame('http://localhost/foo', $is['Location']);
-		$this->assertSame(302, $this->Controller->response->getStatusCode());
+		$this->Controller->Common->postRedirect(['action' => 'foo']);
+		$is = $this->Controller->getResponse()->getHeaderLine('Location');
+		$this->assertSame('http://localhost/foo', $is);
+		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
 	/**
 	 * @return void
 	 */
 	public function testAutoRedirect() {
-		$is = $this->Controller->Common->autoRedirect(['action' => 'foo']);
-		$is = $this->Controller->response->header();
-		$this->assertSame('http://localhost/foo', $is['Location']);
-		$this->assertSame(302, $this->Controller->response->getStatusCode());
+		$this->Controller->Common->autoRedirect(['action' => 'foo']);
+		$is = $this->Controller->getResponse()->getHeaderLine('Location');
+		$this->assertSame('http://localhost/foo', $is);
+		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
 	/**
@@ -157,12 +161,12 @@ class CommonComponentTest extends TestCase {
 	 */
 	public function testAutoRedirectReferer() {
 		$url = 'http://localhost/my_controller/some-referer-action';
-		$this->Controller->setRequest($this->request->withEnv('HTTP_REFERER', $url));
+		$this->Controller->setRequest($this->Controller->getRequest()->withEnv('HTTP_REFERER', $url));
 
 		$this->Controller->Common->autoRedirect(['action' => 'foo'], true);
-		$headers = $this->Controller->response->getHeaders();
-		$this->assertSame([$url], $headers['Location']);
-		$this->assertSame(302, $this->Controller->response->getStatusCode());
+		$is = $this->Controller->getResponse()->getHeaderLine('Location');
+		$this->assertSame($url, $is);
+		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
 	/**
@@ -170,9 +174,9 @@ class CommonComponentTest extends TestCase {
 	 */
 	public function testAutoPostRedirect() {
 		$this->Controller->Common->autoPostRedirect(['action' => 'foo'], true);
-		$is = $this->Controller->response->header();
-		$this->assertSame('http://localhost/foo', $is['Location']);
-		$this->assertSame(302, $this->Controller->response->getStatusCode());
+		$is = $this->Controller->getResponse()->getHeaderLine('Location');
+		$this->assertSame('http://localhost/foo', $is);
+		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
 	/**
@@ -180,12 +184,12 @@ class CommonComponentTest extends TestCase {
 	 */
 	public function testAutoPostRedirectReferer() {
 		$url = 'http://localhost/my_controller/allowed';
-		$this->Controller->setRequest($this->request->withEnv('HTTP_REFERER', $url));
+		$this->Controller->setRequest($this->Controller->getRequest()->withEnv('HTTP_REFERER', $url));
 
 		$this->Controller->Common->autoPostRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
-		$headers = $this->Controller->response->getHeaders();
-		$this->assertSame([$url], $headers['Location']);
-		$this->assertSame(302, $this->Controller->response->getStatusCode());
+		$is = $this->Controller->getResponse()->getHeaderLine('Location');
+		$this->assertSame($url, $is);
+		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
 	/**
@@ -200,12 +204,12 @@ class CommonComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testAutoPostRedirectRefererNotWhitelisted() {
-		$this->request->env('HTTP_REFERER', 'http://localhost/my_controller/wrong');
+		$this->Controller->setRequest($this->Controller->getRequest()->withEnv('HTTP_REFERER', 'http://localhost/my_controller/wrong'));
 
 		$is = $this->Controller->Common->autoPostRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
-		$is = $this->Controller->response->header();
-		$this->assertSame('http://localhost/my_controller/foo', $is['Location']);
-		$this->assertSame(302, $this->Controller->response->getStatusCode());
+		$is = $this->Controller->getResponse()->getHeaderLine('Location');
+		$this->assertSame('http://localhost/my_controller/foo', $is);
+		$this->assertSame(302, $this->Controller->getResponse()->getStatusCode());
 	}
 
 	/**
@@ -228,4 +232,117 @@ class CommonComponentTest extends TestCase {
 		$this->assertSame(['action' => 'default'], $result);
 	}
 
+	/**
+	 * @return void
+	 */
+	public function testIsPosted() {
+		$this->Controller->setRequest($this->Controller->getRequest()->withMethod('POST'));
+		$this->assertTrue($this->Controller->Common->isPosted());
+		$this->Controller->setRequest($this->Controller->getRequest()->withMethod('PUT'));
+		$this->assertTrue($this->Controller->Common->isPosted());
+		$this->Controller->setRequest($this->Controller->getRequest()->withMethod('PATCH'));
+		$this->assertTrue($this->Controller->Common->isPosted());
+	}
+	/**
+	 * @return void
+	 */
+	public function testLoadHelper() {
+		$this->Controller->Common->loadHelper('Tester');
+		$helpers = $this->Controller->viewBuilder()->getHelpers();
+		$this->assertEquals(['Tester'], $helpers);
+		$this->Controller->Common->loadHelper(['Tester123']);
+		$helpers = $this->Controller->viewBuilder()->getHelpers();
+		$this->assertEquals(['Tester', 'Tester123'], $helpers);
+	}
+	/**
+	 * @return void
+	 */
+	public function testDefaultUrlParams() {
+		Configure::write('Routing.prefixes', ['admin', 'tests']);
+		$result = CommonComponent::defaultUrlParams();
+		$expected = [
+			'plugin' => false,
+			'admin' => false,
+			'tests' => false,
+		];
+		$this->assertEquals($expected, $result);
+		Configure::write('Routing.prefixes', 'admin');
+		$result = CommonComponent::defaultUrlParams();
+		$expected = [
+			'plugin' => false,
+			'admin' => false,
+		];
+		$this->assertEquals($expected, $result);
+	}
+	/**
+	 * @return void
+	 */
+	public function testForceCache() {
+		$this->Controller->Common->forceCache();
+		$cache_control = $this->Controller->getResponse()->getHeaderLine('Cache-Control');
+		$this->assertEquals('public, max-age=' . HOUR, $cache_control);
+	}
+	/**
+	 * @return void
+	 */
+	public function testTrimQuery() {
+		Configure::write('DataPreparation.notrim', false);
+		$request = $this->Controller->getRequest();
+		$request = $request->withQueryParams([
+			'a' => [
+				'b' => [
+					' c '
+				]
+			],
+			' d ',
+			' e',
+			'f '
+		]);
+		$this->Controller->setRequest($request);
+		$this->Controller->Common->startup(new Event('Test'));
+		$query = $this->Controller->getRequest()->getQuery();
+		$expected = [
+			'a' => [
+				'b' => [
+					'c'
+				]
+			],
+			'd',
+			'e',
+			'f'
+		];
+		$this->assertSame($expected, $query);
+	}
+	/**
+	 * @return void
+	 */
+	public function testTrimPass() {
+		Configure::write('DataPreparation.notrim', false);
+		$request = $this->Controller->getRequest();
+		$request = $request->withParam('pass', [
+			'a' => [
+				'b' => [
+					' c '
+				]
+			],
+			' d ',
+			' e',
+			'f '
+		]);
+		$this->Controller->setRequest($request);
+		$this->Controller->Common->startup(new Event('Test'));
+		$pass = $this->Controller->getRequest()->getParam('pass');
+		$expected = [
+			'a' => [
+				'b' => [
+					'c'
+				]
+			],
+			'd',
+			'e',
+			'f'
+		];
+		$this->assertSame($expected, $pass);
+	}
+
 }

+ 9 - 9
tests/TestCase/Controller/Component/MobileComponentTest.php

@@ -51,7 +51,7 @@ class MobileComponentTest extends TestCase {
 		$this->event = new Event('Controller.beforeFilter');
 		$this->Controller = new MobileComponentTestController(new ServerRequest());
 
-		$this->Controller->request->getSession()->delete('User');
+		$this->Controller->getRequest()->getSession()->delete('User');
 		Configure::delete('User');
 	}
 
@@ -73,7 +73,7 @@ class MobileComponentTest extends TestCase {
 		$is = $this->Controller->Mobile->detect();
 		$this->assertFalse($is);
 
-		$this->Controller->request->env('HTTP_ACCEPT', 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*');
+		$this->Controller->setRequest($this->Controller->getRequest()->withEnv('HTTP_ACCEPT', 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*'));
 		$is = $this->Controller->Mobile->detect();
 		$this->assertTrue($is);
 	}
@@ -91,10 +91,10 @@ class MobileComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testMobileForceActivated() {
-		$this->Controller->request->query['mobile'] = 1;
+		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['mobile' => 1]));
 
 		$this->Controller->Mobile->beforeFilter($this->event);
-		$session = $this->Controller->request->getSession()->read('User');
+		$session = $this->Controller->getRequest()->getSession()->read('User');
 		$this->assertSame(['mobile' => 1], $session);
 
 		$this->Controller->Mobile->setMobile();
@@ -109,10 +109,10 @@ class MobileComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testMobileForceDeactivated() {
-		$this->Controller->request->query['mobile'] = 0;
+		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['mobile' => 0]));
 
 		$this->Controller->Mobile->beforeFilter($this->event);
-		$session = $this->Controller->request->getSession()->read('User');
+		$session = $this->Controller->getRequest()->getSession()->read('User');
 		$this->assertSame(['mobile' => 0], $session);
 
 		$this->Controller->Mobile->setMobile();
@@ -139,11 +139,11 @@ class MobileComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testMobileFakeMobileForceDeactivated() {
-		$this->Controller->request->query['mobile'] = 0;
+		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['mobile' => 0]));
 		$_SERVER['HTTP_USER_AGENT'] = 'Some Android device';
 
 		$this->Controller->Mobile->beforeFilter($this->event);
-		$session = $this->Controller->request->getSession()->read('User');
+		$session = $this->Controller->getRequest()->getSession()->read('User');
 		$this->assertSame(['mobile' => 0], $session);
 
 		$this->assertTrue($this->Controller->Mobile->isMobile);
@@ -178,7 +178,7 @@ class MobileComponentTest extends TestCase {
 		$_SERVER['HTTP_USER_AGENT'] = 'Some Android device';
 
 		$this->Controller->Mobile->beforeFilter($this->event);
-		$session = $this->Controller->request->getSession()->read('User');
+		$session = $this->Controller->getRequest()->getSession()->read('User');
 		$this->assertTrue($this->Controller->Mobile->isMobile);
 	}
 

+ 8 - 8
tests/TestCase/Controller/Component/UrlComponentTest.php

@@ -4,7 +4,6 @@ namespace Tools\Test\TestCase\Controller\Component;
 
 use App\Controller\UrlComponentTestController;
 use Cake\Core\Configure;
-use Cake\Core\Plugin;
 use Cake\Event\Event;
 use Cake\Http\ServerRequest;
 use Cake\Routing\RouteBuilder;
@@ -89,7 +88,7 @@ class UrlComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testCompleteArray() {
-		$this->Controller->Url->request->query['x'] = 'y';
+		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['x' => 'y']));
 
 		$result = $this->Controller->Url->completeArray(['controller' => 'foobar', 'action' => 'test']);
 		$expected = [
@@ -110,9 +109,11 @@ class UrlComponentTest extends TestCase {
 		$expected = '/foobar/test';
 		$this->assertSame($expected, $result);
 
-		$this->Controller->Url->request->here = '/admin/foo/bar/baz/test';
-		$this->Controller->Url->request->params['prefix'] = 'admin';
-		$this->Controller->Url->request->params['plugin'] = 'Foo';
+		$request = $this->Controller->getRequest();
+		$request = $request->withAttribute('here', '/admin/foo/bar/baz/test')
+			->withParam('prefix', 'admin')
+			->withParam('plugin', 'Foo');
+		$this->Controller->setRequest($request);
 		Router::reload();
 		Router::connect('/:controller/:action/*');
 		Router::plugin('Foo', function (RouteBuilder $routes) {
@@ -123,8 +124,7 @@ class UrlComponentTest extends TestCase {
 				$routes->fallbacks();
 			});
 		});
-		Plugin::routes();
-		Router::pushRequest($this->Controller->Url->request);
+		Router::pushRequest($this->Controller->getRequest());
 
 		$result = $this->Controller->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
 		$expected = '/admin/foo/bar/baz/x';
@@ -139,7 +139,7 @@ class UrlComponentTest extends TestCase {
 	 * @return void
 	 */
 	public function testBuildComplete() {
-		$this->Controller->Url->request->query['x'] = 'y';
+		$this->Controller->setRequest($this->Controller->getRequest()->withQueryParams(['x' => 'y']));
 
 		$result = $this->Controller->Url->buildComplete(['action' => 'test']);
 		$expected = '/test?x=y';

+ 1 - 1
tests/TestCase/Controller/ControllerTest.php

@@ -46,7 +46,7 @@ class ControllerTest extends TestCase {
 	public function testPaginate() {
 		Configure::write('Paginator.limit', 2);
 
-		$ToolsUser = TableRegistry::get('ToolsUsers');
+		$ToolsUser = TableRegistry::getTableLocator()->get('ToolsUsers');
 
 		$count = $ToolsUser->find('count');
 		$this->assertTrue($count > 3);

+ 1 - 2
tests/TestCase/Form/ContactFormTest.php

@@ -2,7 +2,6 @@
 
 namespace Tools\Form;
 
-use Tools\Form\ContactForm;
 use Tools\TestSuite\TestCase;
 
 class ContactFormTest extends TestCase {
@@ -48,7 +47,7 @@ class ContactFormTest extends TestCase {
 		$result = $this->Form->validate($requestData);
 		$this->assertFalse($result);
 
-		$errors = $this->Form->errors();
+		$errors = $this->Form->getErrors();
 		$this->assertSame(['email', 'subject'], array_keys($errors));
 
 		$requestData = [

+ 28 - 35
tests/TestCase/Mailer/EmailTest.php

@@ -6,6 +6,7 @@ use App\Mailer\TestEmail;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
 use Cake\Log\Log;
+use Cake\Mailer\TransportFactory;
 use Tools\Mailer\Email;
 use Tools\TestSuite\TestCase;
 
@@ -28,7 +29,7 @@ class EmailTest extends TestCase {
 		parent::setUp();
 		$this->Email = new TestEmail();
 
-		Email::configTransport('debug', [
+		TransportFactory::setConfig('debug', [
 			'className' => 'Debug'
 		]);
 
@@ -44,8 +45,8 @@ class EmailTest extends TestCase {
 		parent::tearDown();
 		Log::drop('email');
 		Email::drop('test');
-		Email::dropTransport('debug');
-		Email::dropTransport('test_smtp');
+		TransportFactory::drop('debug');
+		TransportFactory::drop('test_smtp');
 
 		Configure::delete('Config.xMailer');
 	}
@@ -66,21 +67,21 @@ class EmailTest extends TestCase {
 	 * @return void
 	 */
 	public function testFrom() {
-		$this->assertSame(['test@example.com' => 'Mark'], $this->Email->from());
+		$this->assertSame(['test@example.com' => 'Mark'], $this->Email->getFrom());
 
-		$this->Email->from('cake@cakephp.org');
+		$this->Email->setFrom('cake@cakephp.org');
 		$expected = ['cake@cakephp.org' => 'cake@cakephp.org'];
-		$this->assertSame($expected, $this->Email->from());
+		$this->assertSame($expected, $this->Email->getFrom());
 
-		$this->Email->from(['cake@cakephp.org']);
-		$this->assertSame($expected, $this->Email->from());
+		$this->Email->setFrom(['cake@cakephp.org']);
+		$this->assertSame($expected, $this->Email->getFrom());
 
-		$this->Email->from('cake@cakephp.org', 'CakePHP');
+		$this->Email->setFrom('cake@cakephp.org', 'CakePHP');
 		$expected = ['cake@cakephp.org' => 'CakePHP'];
-		$this->assertSame($expected, $this->Email->from());
+		$this->assertSame($expected, $this->Email->getFrom());
 
-		$result = $this->Email->from(['cake@cakephp.org' => 'CakePHP']);
-		$this->assertSame($expected, $this->Email->from());
+		$result = $this->Email->setFrom(['cake@cakephp.org' => 'CakePHP']);
+		$this->assertSame($expected, $this->Email->getFrom());
 		$this->assertSame($this->Email, $result);
 	}
 
@@ -89,7 +90,7 @@ class EmailTest extends TestCase {
 	 * @return void
 	 */
 	public function testFromExecption() {
-		$this->Email->from(['cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address']);
+		$this->Email->setFrom(['cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address']);
 	}
 
 	/**
@@ -126,18 +127,14 @@ class EmailTest extends TestCase {
 		$file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png';
 		$this->assertTrue(file_exists($file));
 
-		$this->Email->to(Configure::read('Config.adminEmail'));
+		$this->Email->setTo(Configure::read('Config.adminEmail'));
 		$this->Email->addAttachment($file);
-		$res = $this->Email->send('test_default', 'default');
-		$error = $this->Email->getError();
-		if ($error) {
-			$this->out($error);
-		}
+		$res = $this->Email->send('test_default');
 		$this->assertEquals('', $this->Email->getError());
 		$this->assertTrue((bool)$res);
 
 		$this->Email->reset();
-		$this->Email->to(Configure::read('Config.adminEmail'));
+		$this->Email->setTo(Configure::read('Config.adminEmail'));
 		$this->Email->addAttachment($file, 'x.jpg');
 		$res = $this->Email->send('test_custom_filename');
 
@@ -219,7 +216,7 @@ class EmailTest extends TestCase {
 		$this->assertTrue(file_exists($file));
 
 		$this->Email = new TestEmail();
-		$this->Email->emailFormat('both');
+		$this->Email->setEmailFormat('both');
 
 		$cid = $this->Email->addEmbeddedAttachment($file);
 		$cid2 = $this->Email->addEmbeddedAttachment($file);
@@ -248,8 +245,8 @@ class EmailTest extends TestCase {
 
 		Configure::write('debug', 0);
 		$this->Email = new TestEmail();
-		$this->Email->emailFormat('both');
-		$this->Email->to(Configure::read('Config.adminEmail'));
+		$this->Email->setEmailFormat('both');
+		$this->Email->setTo(Configure::read('Config.adminEmail'));
 		$cid = $this->Email->addEmbeddedAttachment($file);
 
 		$cid2 = $this->Email->addEmbeddedAttachment($file);
@@ -269,11 +266,10 @@ html-part
 </body>
 </html>';
 		$text = trim(strip_tags($html));
-		$this->Email->viewVars(compact('text', 'html'));
+		$this->Email->setViewVars(compact('text', 'html'));
 
 		$res = $this->Email->send();
 		Configure::write('debug', 2);
-		$error = $this->Email->getError();
 
 		$this->assertEquals('', $this->Email->getError());
 		$this->assertTrue((bool)$res);
@@ -287,9 +283,8 @@ html-part
 		$this->assertTrue(file_exists($file));
 
 		$this->Email = new TestEmail();
-		$this->Email->emailFormat('both');
+		$this->Email->setEmailFormat('both');
 		$cid = $this->Email->addEmbeddedBlobAttachment(file_get_contents($file), 'my_hotel.png');
-		$cid2 = $this->Email->addEmbeddedBlobAttachment(file_get_contents($file), 'my_hotel.png');
 
 		$this->assertContains('@' . env('HTTP_HOST'), $cid);
 
@@ -331,15 +326,15 @@ html-part
 	 */
 	public function testValidates() {
 		$this->Email = new TestEmail();
-		$this->Email->transport('debug');
+		$this->Email->setTransport('debug');
 		$res = $this->Email->validates();
 		$this->assertFalse($res);
 
-		$this->Email->subject('foo');
+		$this->Email->setSubject('foo');
 		$res = $this->Email->validates();
 		$this->assertFalse($res);
 
-		$this->Email->to('some@web.de');
+		$this->Email->setTo('some@web.de');
 		$res = $this->Email->validates();
 		$this->assertTrue($res);
 	}
@@ -353,8 +348,8 @@ html-part
 		$file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png';
 
 		$this->Email = new TestEmail();
-		$this->Email->emailFormat('both');
-		$this->Email->to(Configure::read('Config.adminEmail'));
+		$this->Email->setEmailFormat('both');
+		$this->Email->setTo(Configure::read('Config.adminEmail'));
 		$cid = $this->Email->addEmbeddedBlobAttachment(file_get_contents($file), 'my_hotel.png', 'image/png');
 
 		$this->assertContains('@' . env('HTTP_HOST'), $cid);
@@ -371,12 +366,10 @@ html-part
 </body>
 </html>';
 		$text = trim(strip_tags($html));
-		$this->Email->viewVars(compact('text', 'html'));
+		$this->Email->setViewVars(compact('text', 'html'));
 
 		$res = $this->Email->send();
 
-		$error = $this->Email->getError();
-
 		$this->assertEquals('', $this->Email->getError());
 		$this->assertTrue((bool)$res);
 	}

+ 1 - 1
tests/TestCase/Model/Behavior/BitmaskedBehaviorTest.php

@@ -26,7 +26,7 @@ class BitmaskedBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Comments = TableRegistry::get('BitmaskedComments');
+		$this->Comments = TableRegistry::getTableLocator()->get('BitmaskedComments');
 		$this->Comments->addBehavior('Tools.Bitmasked', ['mappedField' => 'statuses']);
 	}
 

+ 3 - 3
tests/TestCase/Model/Behavior/ConfirmableBehaviorTest.php

@@ -32,7 +32,7 @@ class ConfirmableBehaviorTest extends TestCase {
 	 * @return void
 	 */
 	public function testBasicValidation() {
-		$this->Articles = TableRegistry::get('SluggedArticles');
+		$this->Articles = TableRegistry::getTableLocator()->get('SluggedArticles');
 		$this->Articles->addBehavior('Tools.Confirmable');
 
 		$animal = $this->Articles->newEntity();
@@ -57,7 +57,7 @@ class ConfirmableBehaviorTest extends TestCase {
 	 * @return void
 	 */
 	public function testValidationThatHasBeenModifiedBefore() {
-		$this->Articles = TableRegistry::get('SluggedArticles');
+		$this->Articles = TableRegistry::getTableLocator()->get('SluggedArticles');
 		/*
 		$this->Articles->validator()->add('confirm', 'notBlank', [
 				'rule' => function ($value, $context) {
@@ -96,7 +96,7 @@ class ConfirmableBehaviorTest extends TestCase {
 	 * @return void
 	 */
 	public function testValidationFieldMissing() {
-		$this->Articles = TableRegistry::get('SluggedArticles');
+		$this->Articles = TableRegistry::getTableLocator()->get('SluggedArticles');
 		$this->Articles->addBehavior('Tools.Confirmable');
 
 		$animal = $this->Articles->newEntity();

+ 1 - 1
tests/TestCase/Model/Behavior/JsonableBehaviorTest.php

@@ -26,7 +26,7 @@ class JsonableBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Comments = TableRegistry::get('JsonableComments');
+		$this->Comments = TableRegistry::getTableLocator()->get('JsonableComments');
 		$this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details']]);
 	}
 

+ 1 - 1
tests/TestCase/Model/Behavior/NeighborBehaviorTest.php

@@ -26,7 +26,7 @@ class NeighborBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Table = TableRegistry::get('Stories');
+		$this->Table = TableRegistry::getTableLocator()->get('Stories');
 		$this->Table->addBehavior('Tools.Neighbor');
 	}
 

+ 1 - 1
tests/TestCase/Model/Behavior/PasswordableBehaviorTest.php

@@ -35,7 +35,7 @@ class PasswordableBehaviorTest extends TestCase {
 		Configure::delete('Passwordable');
 		Configure::write('Passwordable.auth', 'AuthTest');
 
-		$this->Users = TableRegistry::get('ToolsUsers');
+		$this->Users = TableRegistry::getTableLocator()->get('ToolsUsers');
 
 		$this->hasher = PasswordHasherFactory::build('Default');
 

+ 1 - 1
tests/TestCase/Model/Behavior/ResetBehaviorTest.php

@@ -31,7 +31,7 @@ class ResetBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Table = TableRegistry::get('ResetComments');
+		$this->Table = TableRegistry::getTableLocator()->get('ResetComments');
 		$this->Table->addBehavior('Tools.Reset');
 	}
 

+ 1 - 1
tests/TestCase/Model/Behavior/SluggedBehaviorTest.php

@@ -37,7 +37,7 @@ class SluggedBehaviorTest extends TestCase {
 		//$this->connection = ConnectionManager::get('test');
 
 		$options = ['alias' => 'Articles'];
-		$this->articles = TableRegistry::get('SluggedArticles', $options);
+		$this->articles = TableRegistry::getTableLocator()->get('SluggedArticles', $options);
 		Configure::delete('Slugged');
 
 		$this->articles->addBehavior('Tools.Slugged');

+ 1 - 1
tests/TestCase/Model/Behavior/StringBehaviorTest.php

@@ -25,7 +25,7 @@ class StringBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Comments = TableRegistry::get('StringComments');
+		$this->Comments = TableRegistry::getTableLocator()->get('StringComments');
 		$this->Comments->addBehavior('Tools.String', ['fields' => ['title'], 'input' => ['ucfirst']]);
 	}
 

+ 1 - 1
tests/TestCase/Model/Behavior/ToggleBehaviorTest.php

@@ -25,7 +25,7 @@ class ToggleBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Addresses = TableRegistry::get('ToggleAddresses');
+		$this->Addresses = TableRegistry::getTableLocator()->get('ToggleAddresses');
 		$this->Addresses->addBehavior('Tools.Toggle', ['scopeFields' => 'category_id']);
 	}
 

+ 1 - 1
tests/TestCase/Model/Behavior/TypeMapBehaviorTest.php

@@ -37,7 +37,7 @@ class TypeMapBehaviorTest extends TestCase {
 	 * @return void
 	 */
 	public function testFields() {
-		$this->Table = TableRegistry::get('Data');
+		$this->Table = TableRegistry::getTableLocator()->get('Data');
 		$this->Table->addBehavior('Tools.Jsonable', ['fields' => ['data_array']]);
 
 		$entity = $this->Table->newEntity();

+ 1 - 1
tests/TestCase/Model/Behavior/TypographicBehaviorTest.php

@@ -25,7 +25,7 @@ class TypographicBehaviorTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Model = TableRegistry::get('Articles');
+		$this->Model = TableRegistry::getTableLocator()->get('Articles');
 		$this->Model->addBehavior('Tools.Typographic', ['fields' => ['body'], 'before' => 'marshal']);
 	}
 

+ 1 - 1
tests/TestCase/Model/Entity/EntityTest.php

@@ -26,7 +26,7 @@ class EntityTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Users = TableRegistry::get('ToolsUsers');
+		$this->Users = TableRegistry::getTableLocator()->get('ToolsUsers');
 	}
 
 	/**

+ 3 - 3
tests/TestCase/Model/Table/TableTest.php

@@ -32,9 +32,9 @@ class TableTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Users = TableRegistry::get('ToolsUsers');
+		$this->Users = TableRegistry::getTableLocator()->get('ToolsUsers');
 
-		$this->Posts = TableRegistry::get('Posts');
+		$this->Posts = TableRegistry::getTableLocator()->get('Posts');
 		$this->Posts->belongsTo('Authors');
 	}
 
@@ -78,7 +78,7 @@ class TableTest extends TestCase {
 	 * @return void
 	 */
 	public function testTimestamp() {
-		$this->Roles = TableRegistry::get('Roles');
+		$this->Roles = TableRegistry::getTableLocator()->get('Roles');
 		$entity = $this->Roles->newEntity(['name' => 'Foo', 'alias' => 'foo']);
 		$result = $this->Roles->save($entity);
 		$this->assertTrue(!empty($result['created']));

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

@@ -25,7 +25,7 @@ class TokensTableTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Tokens = TableRegistry::get('Tools.Tokens');
+		$this->Tokens = TableRegistry::getTableLocator()->get('Tools.Tokens');
 	}
 
 	/**

+ 7 - 7
tests/TestCase/View/Helper/HtmlHelperTest.php

@@ -27,9 +27,7 @@ class HtmlHelperTest extends TestCase {
 		parent::setUp();
 
 		$this->Html = new HtmlHelper(new View(null));
-		$this->Html->request = new ServerRequest();
-		$this->Html->request->webroot = '';
-		$this->Html->Url->request = $this->Html->request;
+		$this->Html->getView()->setRequest(new ServerRequest(['webroot' => '']));
 	}
 
 	/**
@@ -56,9 +54,11 @@ class HtmlHelperTest extends TestCase {
 		$expected = '<a href="/foobar/test">Foo</a>';
 		$this->assertEquals($expected, $result);
 
-		$this->Html->request->here = '/admin/foobar/test';
-		$this->Html->request->params['admin'] = true;
-		$this->Html->request->params['prefix'] = 'admin';
+		$request = $this->Html->getView()->getRequest();
+		$request = $request->withAttribute('here', '/admin/foobar/test')
+			->withParam('admin', true)
+			->withParam('prefix', 'admin');
+		$this->Html->getView()->setRequest($request);
 		Router::reload();
 		Router::connect('/:controller/:action/*');
 		Router::prefix('admin', function (RouteBuilder $routes) {
@@ -85,7 +85,7 @@ class HtmlHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testLinkComplete() {
-		$this->Html->request->query['x'] = 'y';
+		$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>';

+ 1 - 1
tests/TestCase/View/Helper/TreeHelperTest.php

@@ -47,7 +47,7 @@ class TreeHelperTest extends TestCase {
 		parent::setUp();
 
 		$this->Tree = new TreeHelper(new View(null));
-		$this->Table = TableRegistry::get('AfterTrees');
+		$this->Table = TableRegistry::getTableLocator()->get('AfterTrees');
 		$this->Table->addBehavior('Tree');
 
 		$connection = ConnectionManager::get('test');

+ 13 - 12
tests/TestCase/View/Helper/UrlHelperTest.php

@@ -2,7 +2,6 @@
 
 namespace Tools\Test\TestCase\View\Helper;
 
-use Cake\Core\Plugin;
 use Cake\Http\ServerRequest;
 use Cake\Routing\RouteBuilder;
 use Cake\Routing\Router;
@@ -27,8 +26,7 @@ class UrlHelperTest extends TestCase {
 		parent::setUp();
 
 		$this->Url = new UrlHelper(new View(null));
-		$this->Url->request = new ServerRequest();
-		$this->Url->request->webroot = '';
+		$this->Url->getView()->setRequest(new ServerRequest(['webroot' => '']));
 	}
 
 	/**
@@ -41,14 +39,16 @@ class UrlHelperTest extends TestCase {
 		$expected = '/foobar/test';
 		$this->assertSame($expected, $result);
 
-		$this->Url->request->here = '/admin/foobar/test';
-		$this->Url->request->params['prefix'] = 'admin';
+		$request = $this->Url->getView()->getRequest();
+		$request = $request->withAttribute('here', '/admin/foobar/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->request);
+		Router::pushRequest($this->Url->getView()->getRequest());
 
 		$result = $this->Url->build(['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
 		$expected = '/admin/foobar/test';
@@ -73,9 +73,11 @@ class UrlHelperTest extends TestCase {
 		$expected = '/foobar/test';
 		$this->assertSame($expected, $result);
 
-		$this->Url->request->here = '/admin/foo/bar/baz/test';
-		$this->Url->request->params['prefix'] = 'admin';
-		$this->Url->request->params['plugin'] = 'Foo';
+		$request = $this->Url->getView()->getRequest();
+		$request = $request->withAttribute('here', '/admin/foo/bar/baz/test')
+			->withParam('prefix', 'admin')
+			->withParam('plugin', 'Foo');
+		$this->Url->getView()->setRequest($request);
 		Router::reload();
 		Router::connect('/:controller/:action/*');
 		Router::plugin('Foo', function (RouteBuilder $routes) {
@@ -86,8 +88,7 @@ class UrlHelperTest extends TestCase {
 				$routes->fallbacks();
 			});
 		});
-		Plugin::routes();
-		Router::pushRequest($this->Url->request);
+		Router::pushRequest($this->Url->getView()->getRequest());
 
 		$result = $this->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
 		$expected = '/admin/foo/bar/baz/x';
@@ -102,7 +103,7 @@ class UrlHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testBuildComplete() {
-		$this->Url->request->query['x'] = 'y';
+		$this->Url->getView()->setRequest($this->Url->getView()->getRequest()->withQueryParams(['x' => 'y']));
 
 		$result = $this->Url->buildComplete(['action' => 'test']);
 		$expected = '/test?x=y';

+ 1 - 1
tests/bootstrap.php

@@ -38,7 +38,7 @@ Cake\Core\Configure::write('Config', [
 		'adminEmail' => 'test@example.com',
 		'adminName' => 'Mark']);
 Cake\Mailer\Email::setConfig('default', ['transport' => 'Debug']);
-Cake\Mailer\Email::setConfigTransport('Debug', [
+Cake\Mailer\TransportFactory::setConfig('Debug', [
 		'className' => 'Debug'
 ]);