Browse Source

Merge pull request #174 from dereuromark/dev

Cleanup for next release.
Mark Sch 9 years ago
parent
commit
4df3c90e22

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 /vendor/
 /tmp/
 /plugins/Setup
+/composer.phar

+ 47 - 0
docs/Helper/Html.md

@@ -0,0 +1,47 @@
+# Html Helper
+
+An enhanced HtmlHelper
+- imageFromBlob()
+- resetLink() and completeLink()
+
+## Usage
+Attach it to your controllers like so:
+```php
+public $helpers = ['Tools.Html'];
+```
+It will replace the CakePHP core one everywhere.
+
+### Image from Blob
+Sometimes you might want to directly output images inside the HTML without external files involved.
+The image, like a small 16x16 icon, could also directly come from the database.
+
+```php
+$blobImage = file_get_contents($path . 'my-image.png');
+// or from somewhere else
+
+echo $this->Html->imageFromBlob($blobImage);
+```
+The output will be a base64 encoded embedded image.
+
+Bear in mind that this does not work with all (especially older) browsers.
+
+### Reset and Complete Links
+In some cases you want to display the links without the plugin and prefix automatically being taken from the current URL.
+This is especially important with navigation menu or layout elements, as those will be outputted on every page, even outside of the current plugin or prefix scope.
+
+You can then either manually and verbosely always set both to `false`, or just use the convenience method:
+```php
+echo $this->Html->resetLink(['controller' => 'Foo', 'action' => 'bar']);
+```
+
+Inside `/admin/plugin-name/example/action` the linked URL would normally become `/admin/plugin-name/foo/bar`.
+With the resetLink() method it will become the desired: `/foo/bar`.
+
+In both cases, however, the query strings are not passed on. If you want that, you can use the other convenience method:
+```php
+echo $this->Html->completeLink(['controller' => 'Foo', 'action' => 'bar']);
+```
+Now if there was a query string `?q=x` on the current action, it would also be passed along as `/foo/bar?q=x`.
+
+
+See also [Url helper](/docs/Url/Url.md).

+ 19 - 7
docs/README.md

@@ -12,16 +12,28 @@ This cake3 branch only works for **CakePHP3.x** - please use the master branch f
 * [Upgrade guide from 2.x to 3.x](Upgrade.md)
 
 ## Detailed Documentation - Quicklinks
+
+Routing:
+* [Url](Url/Url.md)
+
+ErrorHandler
 * [ErrorHandler](Error/ErrorHandler.md)
-* [Behavior/Jsonable](Behavior/Jsonable.md)
-* [Behavior/Passwordable](Behavior/Passwordable.md)
-* [Behavior/Slugged](Behavior/Slugged.md)
-* [Behavior/Bitmasked](Behavior/Bitmasked.md)
-* [Behavior/Reset](Behavior/Reset.md)
-* [Behavior/String](Behavior/String.md)
-* [View/Rss](View/Rss.md)
+
+Testing
 * [Testing](TestSuite/Testing.md)
 
+Helpers:
+* [Html](Helper/Html.md)
+* [Form](Helper/Form.md)
+
+Behaviors:
+* [Jsonable](Behavior/Jsonable.md)
+* [Passwordable](Behavior/Passwordable.md)
+* [Slugged](Behavior/Slugged.md)
+* [Bitmasked](Behavior/Bitmasked.md)
+* [Reset](Behavior/Reset.md)
+* [String](Behavior/String.md)
+
 ## Basic enhancements of the core
 
 ### Model

+ 32 - 0
docs/Url/Url.md

@@ -0,0 +1,32 @@
+# Url component and helper 
+
+There is both a component and helper that help to work around some URL issues.
+
+### Defaults
+If you need to merge in defaults to your URLs, you can get the information from the `defaults()` method:
+
+```php
+// From inside a plugin controller
+$$this->redirect(['controller' => 'Main', 'action' => 'index'] + $this->Url->defaults());
+```
+It will basically add in `'prefix' => false, 'plugin' => false`.
+
+### Reset
+You can in that case also just use the convenience method:
+```php
+$url = $this->Url->reset(['controller' => 'Main', 'action' => 'overview']);
+```
+
+Inside `/admin/plugin-name/example/action` the URL to redirect to would normally become `/admin/plugin-name/main/overview`.
+With the reset() method it will become the desired: `/main/overview`.
+
+### Complete
+In both cases, however, the query strings are not passed on. If you want that, you can use the other convenience method:
+```php
+$url = $this->Url->complete(['controller' => 'Main', 'action' => 'overview']);
+```
+Now if there was a query string `?q=x` on the current action, it would also be passed along as `/main/overview?q=x`.
+
+
+### Generating links
+For generating links for those cases please see [Html helper](/docs/Helper/Html.md).

+ 0 - 0
sniff


+ 0 - 194
src/Auth/AuthUserTrait.php

@@ -1,194 +0,0 @@
-<?php
-
-namespace Tools\Auth;
-
-use Cake\Utility\Hash;
-
-if (!defined('USER_ROLE_KEY')) {
-	define('USER_ROLE_KEY', 'Roles');
-}
-if (!defined('USER_RIGHT_KEY')) {
-	define('USER_RIGHT_KEY', 'Rights');
-}
-
-/**
- * Convenience wrapper to access Auth data and check on rights/roles.
- *
- * Simply add it at the class file:
- *
- *   trait AuthUserTrait;
- *
- * But needs
- *
- *   protected function _getUser() {}
- *
- * to be implemented in the using class.
- *
- * Expects the Role session infos to be either
- *     - `Auth.User.role_id` (single) or
- *     - `Auth.User.Role` (multi - flat array of roles, or array role data)
- * and can be adjusted via constants and defined().
- * Same goes for Right data.
- *
- * If roles are defined in configuration file (non-db roles setup) the constant
- * `USER_ROLE_KEY` has to be defined in `bootstrap.php`.
- * ```
- * // if role key in User model is role_id
- * define('USER_ROLE_KEY', 'role_id');
- * ```
- *
- * Note: This uses AuthComponent internally to work with both stateful and stateless auth.
- *
- * @author Mark Scherer
- * @license MIT
- * @deprecated Use TinyAuth AuthUser instead.
- */
-trait AuthUserTrait {
-
-	/**
-	 * Get the user id of the current session.
-	 *
-	 * This can be used anywhere to check if a user is logged in.
-	 *
-	 * @param string $field Field name. Defaults to `id`.
-	 * @return mixed User id if existent, null otherwise.
-	 */
-	public function id($field = 'id') {
-		return $this->user($field);
-	}
-
-	/**
-	 * This check can be used to tell if a record that belongs to some user is the
-	 * current logged in user
-	 *
-	 * @param string|int $userId
-	 * @param string $field Field name. Defaults to `id`.
-	 * @return bool
-	 */
-	public function isMe($userId, $field = 'id') {
-		return $userId && (string)$userId === (string)$this->user($field);
-	}
-
-	/**
-	 * Get the user data of the current session.
-	 *
-	 * @param string|null $key Key in dot syntax.
-	 * @return mixed Data
-	 */
-	public function user($key = null) {
-		$user = $this->_getUser();
-		if ($key === null) {
-			return $user;
-		}
-		return Hash::get($user, $key);
-	}
-
-	/**
-	 * Get the role(s) of the current session.
-	 *
-	 * It will return the single role for single role setup, and a flat
-	 * list of roles for multi role setup.
-	 *
-	 * @return mixed String or array of roles or null if inexistent.
-	 */
-	public function roles() {
-		$roles = $this->user(USER_ROLE_KEY);
-		if (!is_array($roles)) {
-			return $roles;
-		}
-		if (isset($roles[0]['id'])) {
-			$roles = Hash::extract($roles, '{n}.id');
-		}
-		return $roles;
-	}
-
-	/**
-	 * Check if the current session has this role.
-	 *
-	 * @param mixed $expectedRole
-	 * @param mixed|null $providedRoles
-	 * @return bool Success
-	 */
-	public function hasRole($expectedRole, $providedRoles = null) {
-		if ($providedRoles !== null) {
-			$roles = (array)$providedRoles;
-		} else {
-			$roles = (array)$this->roles();
-		}
-		if (empty($roles)) {
-			return false;
-		}
-
-		if (in_array($expectedRole, $roles)) {
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Check if the current session has one of these roles.
-	 *
-	 * You can either require one of the roles (default), or you can require all
-	 * roles to match.
-	 *
-	 * @param mixed $expectedRoles
-	 * @param bool $oneRoleIsEnough (if all $roles have to match instead of just one)
-	 * @param mixed|null $providedRoles
-	 * @return bool Success
-	 */
-	public function hasRoles($expectedRoles, $oneRoleIsEnough = true, $providedRoles = null) {
-		if ($providedRoles !== null) {
-			$roles = $providedRoles;
-		} else {
-			$roles = $this->roles();
-		}
-		$expectedRoles = (array)$expectedRoles;
-		if (empty($expectedRoles)) {
-			return false;
-		}
-		$count = 0;
-		foreach ($expectedRoles as $expectedRole) {
-			if ($this->hasRole($expectedRole, $roles)) {
-				if ($oneRoleIsEnough) {
-					return true;
-				}
-				$count++;
-			} else {
-				if (!$oneRoleIsEnough) {
-					return false;
-				}
-			}
-		}
-
-		if ($count === count($expectedRoles)) {
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Check if the current session has this right.
-	 *
-	 * Rights can be an additional element to give permissions, e.g.
-	 * the right to send messages/emails, to friend request other users,...
-	 * This can be set via Right model and stored in the Auth array upon login
-	 * the same way the roles are.
-	 *
-	 * @param mixed $expectedRight
-	 * @param mixed|null $providedRights
-	 * @return bool Success
-	 */
-	public function hasRight($expectedRight, $providedRights = null) {
-		if ($providedRights !== null) {
-			$rights = $providedRights;
-		} else {
-			$rights = $this->user(USER_RIGHT_KEY);
-		}
-		$rights = (array)$rights;
-		if (array_key_exists($expectedRight, $rights) && !empty($rights[$expectedRight])) {
-			return true;
-		}
-		return false;
-	}
-
-}

+ 0 - 44
src/Controller/Component/AuthUserComponent.php

@@ -1,44 +0,0 @@
-<?php
-
-namespace Tools\Controller\Component;
-
-use Cake\Event\Event;
-use Shim\Controller\Component\Component;
-use Tools\Auth\AuthUserTrait;
-
-/**
- * Authentication User component class
- *
- * @deprecated Use TinyAuth AuthUser instead.
- */
-class AuthUserComponent extends Component {
-
-	use AuthUserTrait;
-
-	/**
-	 * @var array
-	 */
-	public $components = ['Auth'];
-
-	/**
-	 * AuthUserComponent::beforeRender()
-	 *
-	 * @param \Cake\Event\Event $event
-	 * @return void
-	 */
-	public function beforeRender(Event $event) {
-		$controller = $event->subject();
-		$authUser = $this->_getUser();
-		$controller->set(compact('authUser'));
-	}
-
-	/**
-	 * AuthUserComponent::_getUser()
-	 *
-	 * @return array
-	 */
-	protected function _getUser() {
-		return (array)$this->Auth->user();
-	}
-
-}

+ 0 - 151
src/Controller/Component/FlashComponent.php

@@ -1,151 +0,0 @@
-<?php
-
-namespace Tools\Controller\Component;
-
-use Cake\Core\Configure;
-use Cake\Event\Event;
-use Cake\Network\Exception\InternalErrorException;
-use Cake\Utility\Inflector;
-use Shim\Controller\Component\Component;
-
-/**
- * A flash component to enhance flash message support with stackable messages, both
- * persistent and transient.
- *
- * @author Mark Scherer
- * @copyright 2014 Mark Scherer
- * @license MIT
- * @deprecated Use dereuromark/cakephp-flash plugin instead.
- *
- * @method void success(string $message, array $options = []) Set a message using "success" element
- * @method void error(string $message, array $options = []) Set a message using "error" element
- * @method void warning(string $message, array $options = []) Set a message using "warning" element
- * @method void info(string $message, array $options = []) Set a message using "info" element
- */
-class FlashComponent extends Component {
-
-	/**
-	 * @var array
-	 */
-	protected $_defaultConfig = [
-		'headerKey' => 'X-Flash', // Set to empty string to deactivate AJAX response
-		'sessionLimit' => 99 // Max message limit for session (Configure doesn't need one)
-	];
-
-	/**
-	 * Called after the Controller::beforeRender(), after the view class is loaded, and before the
-	 * Controller::render()
-	 *
-	 * @param \Cake\Event\Event $event
-	 * @return \Cake\Network\Response|null|void
-	 */
-	public function beforeRender(Event $event) {
-		if (!$this->Controller->request->is('ajax')) {
-			return;
-		}
-
-		$headerKey = $this->config('headerKey');
-		if (!$headerKey) {
-			return;
-		}
-
-		$ajaxMessages = array_merge(
-			(array)$this->Controller->request->session()->consume('FlashMessage'),
-			(array)Configure::consume('FlashMessage')
-		);
-
-		// The header can be read with JavaScript and a custom Message can be displayed
-		$this->Controller->response->header($headerKey, json_encode($ajaxMessages));
-	}
-
-	/**
-	 * Adds a flash message.
-	 * Updates "messages" session content (to enable multiple messages of one type).
-	 *
-	 * @param string $message Message to output.
-	 * @param string|null $options Options
-	 * @return void
-	 */
-	public function message($message, $options = null) {
-		if (!is_array($options)) {
-			$type = $options;
-			if (!$type) {
-				$type = 'info';
-			}
-			$options = [];
-		} else {
-			$options += ['element' => 'info'];
-			$type = $options['element'];
-		}
-
-		$old = (array)$this->Controller->request->session()->read('FlashMessage');
-		if (isset($old[$type]) && count($old[$type]) > $this->config('sessionLimit')) {
-			array_shift($old[$type]);
-		}
-		$old[$type][] = $message;
-		$this->Controller->request->session()->write('FlashMessage', $old);
-	}
-
-	/**
-	 * Wrapper for original core functionality going into this extended component.
-	 * Core Auth component, for example, requires this.
-	 *
-	 * @param string $message
-	 * @param array $config
-	 * @return void
-	 */
-	public function set($message, array $config = []) {
-		// For now we only use the element name
-		$defaults = ['element' => 'info'];
-		$config += $defaults;
-		$this->message($message, $config['element']);
-	}
-
-	/**
-	 * Adds a transient flash message.
-	 * These flash messages that are not saved (only available for current view),
-	 * will be merged into the session flash ones prior to output.
-	 *
-	 * @param string $message Message to output.
-	 * @param string|null $type Type ('error', 'warning', 'success', 'info' or custom class).
-	 * @return void
-	 */
-	public static function transientMessage($message, $type = null) {
-		if (!$type) {
-			$type = 'info';
-		}
-
-		$old = (array)Configure::read('FlashMessage');
-		if (isset($old[$type]) && count($old[$type]) > 99) {
-			array_shift($old[$type]);
-		}
-		$old[$type][] = $message;
-		Configure::write('FlashMessage', $old);
-	}
-
-	/**
-	 * Magic method for verbose flash methods based on element names.
-	 *
-	 * For example: $this->Flash->success('My message') would use the
-	 * success.ctp element under `App/Template/Element/Flash` for rendering the
-	 * flash message.
-	 *
-	 * @param string $name Element name to use.
-	 * @param array $args Parameters to pass when calling `FlashComponent::message()` or `set()`.
-	 * @return void
-	 * @throws \Cake\Network\Exception\InternalErrorException If missing the flash message.
-	 */
-	public function __call($name, $args) {
-		$options = ['element' => Inflector::underscore($name)];
-
-		if (count($args) < 1) {
-			throw new InternalErrorException('Flash message missing.');
-		}
-
-		if (!empty($args[1])) {
-			$options += (array)$args[1];
-		}
-		$this->message($args[0], $options);
-	}
-
-}

+ 99 - 0
src/Controller/Component/UrlComponent.php

@@ -0,0 +1,99 @@
+<?php
+
+namespace Tools\Controller\Component;
+
+use Cake\Routing\Router;
+use Shim\Controller\Component\Component;
+
+/**
+ * A component for URL topics
+ *
+ * @author Mark Scherer
+ * @license MIT
+ */
+class UrlComponent extends Component {
+
+	/**
+	 * Returns a URL based on provided parameters.
+	 *
+	 * ### Options:
+	 *
+	 * - `fullBase`: If true, the full base URL will be prepended to the result
+	 *
+	 * @param string|array|null $url Either a relative string url like `/products/view/23` or
+	 *    an array of URL parameters. Using an array for URLs will allow you to leverage
+	 *    the reverse routing features of CakePHP.
+	 * @param array $options Array of options
+	 * @return string Full translated URL with base path.
+	 */
+	public function build($url = null, array $options = []) {
+		$defaults = [
+			'fullBase' => false,
+		];
+		$options += $defaults;
+
+		$url = Router::url($url, $options['fullBase']);
+
+		return $url;
+	}
+
+	/**
+	 * Creates a reset URL.
+	 * The prefix and plugin params are resetting to default false.
+	 *
+	 * Can only add defaults for array URLs.
+	 *
+	 * @param string|array|null $url URL.
+	 * @param bool $full If true, the full base URL will be prepended to the result
+	 * @return string Full translated URL with base path.
+	 */
+	public function reset($url = null, $full = false) {
+		if (is_array($url)) {
+			$url += $this->defaults();
+		}
+
+		return Router::url($url, $full);
+	}
+
+	/**
+	 * @return array
+	 */
+	public function defaults() {
+		return [
+			'prefix' => false,
+			'plugin' => false
+		];
+	}
+
+	/**
+	 * Returns a URL based on provided parameters.
+	 *
+	 * Can only add query strings for array URLs.
+	 *
+	 * @param string|array|null $url URL.
+	 * @param bool $full If true, the full base URL will be prepended to the result
+	 * @return string Full translated URL with base path.
+	 */
+	public function complete($url = null, $full = false) {
+		if (is_array($url)) {
+			$url = $this->addQueryStrings($url);
+		}
+
+		return Router::url($url, $full);
+	}
+
+	/**
+	 * @param array $url
+	 *
+	 * @return array
+	 */
+	protected function addQueryStrings(array $url) {
+		if (!isset($url['?'])) {
+			$url['?'] = [];
+		}
+		$url['?'] += $this->request->query;
+
+		return $url;
+	}
+
+}

+ 0 - 71
src/Database/Type/YearType.php

@@ -1,71 +0,0 @@
-<?php
-
-namespace Tools\Database\Type;
-
-use Cake\Database\Driver;
-use Cake\Database\Type;
-use PDO;
-
-/**
- * Experimental year type (MySQL)
- *
- * Needs:
- * - Type::map('year', 'Tools\Database\Type\YearType'); in bootstrap
- * - Manual FormHelper $this->Form->input('published', ['type' => 'year']);
- */
-class YearType extends Type {
-
-	/**
-	 * Date format for DateTime object
-	 *
-	 * @var string
-	 */
-	protected $_format = 'Y';
-
-	/**
-	 * Convert binary data into the database format.
-	 *
-	 * Binary data is not altered before being inserted into the database.
-	 * As PDO will handle reading file handles.
-	 *
-	 * @param string|resource $value The value to convert.
-	 * @param \Cake\Database\Driver $driver The driver instance to convert with.
-	 * @return string|resource
-	 */
-	public function toDatabase($value, Driver $driver) {
-		if (is_array($value)) {
-			$value = $value['year'];
-		}
-		if ($value === null || !(int)$value) {
-			return null;
-		}
-		return $value;
-	}
-
-	/**
-	 * Convert binary into resource handles
-	 *
-	 * @param null|string|resource $value The value to convert.
-	 * @param \Cake\Database\Driver $driver The driver instance to convert with.
-	 * @return resource|null
-	 * @throws \Cake\Core\Exception\Exception
-	 */
-	public function toPHP($value, Driver $driver) {
-		if ($value === null || !(int)$value) {
-			return null;
-		}
-		return $value;
-	}
-
-	/**
-	 * Get the correct PDO binding type for Year data.
-	 *
-	 * @param mixed $value The value being bound.
-	 * @param \Cake\Database\Driver $driver The driver.
-	 * @return int
-	 */
-	public function toStatement($value, Driver $driver) {
-		return PDO::PARAM_INT;
-	}
-
-}

+ 4 - 1
src/Model/Behavior/JsonableBehavior.php

@@ -9,6 +9,7 @@ use Cake\ORM\Behavior;
 use Cake\ORM\Entity;
 use Cake\ORM\Query;
 use Exception;
+use Tools\Database\Type\ArrayType;
 use Tools\Utility\Text;
 
 /**
@@ -70,10 +71,10 @@ class JsonableBehavior extends Behavior {
 
 	/**
 	 * @param array $config
+	 * @throws \Exception
 	 * @return void
 	 */
 	public function initialize(array $config = []) {
-		Type::map('array', 'Tools\Database\Type\ArrayType');
 		if (empty($this->_config['fields'])) {
 			throw new Exception('Fields are required');
 		}
@@ -93,6 +94,8 @@ class JsonableBehavior extends Behavior {
 			$options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_ERROR_INF_OR_NAN | JSON_PARTIAL_OUTPUT_ON_ERROR;
 			$this->_config['encodeParams']['options'] = $options;
 		}
+
+		Type::map('array', ArrayType::class);
 	}
 
 	/**

+ 0 - 80
src/Utility/Multibyte.php

@@ -1,80 +0,0 @@
-<?php
-
-namespace Tools\Utility;
-
-/**
- * Multibyte handling methods.
- *
- * Shim class for 3.x built from 2.x core file.
- */
-
-/**
- * Multibyte handling methods.
- */
-class Multibyte {
-
-	/**
-	 * Converts a multibyte character string
-	 * to the decimal value of the character
-	 *
-	 * @param string $string String to convert.
-	 * @return array
-	 */
-	public static function utf8($string) {
-		$map = [];
-
-		$values = [];
-		$find = 1;
-		$length = strlen($string);
-
-		for ($i = 0; $i < $length; $i++) {
-			$value = ord($string[$i]);
-
-			if ($value < 128) {
-				$map[] = $value;
-			} else {
-				if (empty($values)) {
-					$find = ($value < 224) ? 2 : 3;
-				}
-				$values[] = $value;
-
-				if (count($values) === $find) {
-					if ($find == 3) {
-						$map[] = (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64);
-					} else {
-						$map[] = (($values[0] % 32) * 64) + ($values[1] % 64);
-					}
-					$values = [];
-					$find = 1;
-				}
-			}
-		}
-		return $map;
-	}
-
-	/**
-	 * Converts the decimal value of a multibyte character string
-	 * to a string
-	 *
-	 * @param array $array Values array.
-	 * @return string
-	 */
-	public static function ascii($array) {
-		$ascii = '';
-
-		foreach ($array as $utf8) {
-			if ($utf8 < 128) {
-				$ascii .= chr($utf8);
-			} elseif ($utf8 < 2048) {
-				$ascii .= chr(192 + (($utf8 - ($utf8 % 64)) / 64));
-				$ascii .= chr(128 + ($utf8 % 64));
-			} else {
-				$ascii .= chr(224 + (($utf8 - ($utf8 % 4096)) / 4096));
-				$ascii .= chr(128 + ((($utf8 % 4096) - ($utf8 % 64)) / 64));
-				$ascii .= chr(128 + ($utf8 % 64));
-			}
-		}
-		return $ascii;
-	}
-
-}

+ 1 - 34
src/Utility/Utility.php

@@ -315,38 +315,7 @@ class Utility {
 	}
 
 	/**
-	 * Encode strings with base64_encode and also
-	 * replace chars base64 uses that would mess up the url.
-	 *
-	 * Do not use this for querystrings. Those will escape automatically.
-	 * This is only useful for named or passed params.
-	 *
-	 * @deprecated Use query strings instead
-	 * @param string $string Unsafe string
-	 * @return string Encoded string
-	 */
-	public static function urlEncode($string) {
-		return str_replace(['/', '='], ['-', '_'], base64_encode($string));
-	}
-
-	/**
-	 * Decode strings with base64_encode and also
-	 * replace back chars base64 uses that would mess up the url.
-	 *
-	 * Do not use this for querystrings. Those will escape automatically.
-	 * This is only useful for named or passed params.
-	 *
-	 * @deprecated Use query strings instead
-	 * @param string $string Safe string
-	 * @return string Decoded string
-	 */
-	public static function urlDecode($string) {
-		return base64_decode(str_replace(['-', '_'], ['/', '='], $string));
-	}
-
-	/**
 	 * Returns true only if all values are true.
-	 * //TODO: maybe move to bootstrap?
 	 *
 	 * @param array $array
 	 * @return bool Result
@@ -365,7 +334,6 @@ class Utility {
 
 	/**
 	 * Returns true if at least one value is true.
-	 * //TODO: maybe move to bootstrap?
 	 *
 	 * @param array $array
 	 * @return bool Result
@@ -388,7 +356,7 @@ class Utility {
 	 * @deprecated Not sure this is useful for CakePHP 3.0
 	 */
 	public static function isValidSaveAll($array) {
-		if (empty($array)) {
+		if (!$array) {
 			return false;
 		}
 		$ret = true;
@@ -404,7 +372,6 @@ class Utility {
 
 	/**
 	 * Convenience function for automatic casting in form methods etc.
-	 * //TODO: maybe move to bootstrap?
 	 *
 	 * @param mixed $value
 	 * @param string $type

+ 0 - 30
src/View/Helper/AuthUserHelper.php

@@ -1,30 +0,0 @@
-<?php
-
-namespace Tools\View\Helper;
-
-use Cake\View\Helper;
-use RuntimeException;
-use Tools\Auth\AuthUserTrait;
-
-/**
- * Helper to access auth user data.
- *
- * @deprecated Use TinyAuth AuthUser instead.
- */
-class AuthUserHelper extends Helper {
-
-	use AuthUserTrait;
-
-	/**
-	 * AuthUserHelper::_getUser()
-	 *
-	 * @return array
-	 */
-	protected function _getUser() {
-		if (!isset($this->_View->viewVars['authUser'])) {
-			throw new RuntimeException('AuthUser helper needs AuthUser component to function');
-		}
-		return $this->_View->viewVars['authUser'];
-	}
-
-}

+ 0 - 45
src/View/Helper/CookieHelper.php

@@ -1,45 +0,0 @@
-<?php
-
-namespace Tools\View\Helper;
-
-use Cake\View\Helper;
-
-/**
- * Cookie Helper.
- */
-class CookieHelper extends Helper {
-
-	/**
-	 * Reads a cookie value for a key or return values for all keys.
-	 *
-	 * In your view: `$this->Cookie->read('key');`
-	 *
-	 * @param string|null $name the name of the cookie key you want to read
-	 * @return mixed values from the cookie vars
-	 */
-	public function read($name = null) {
-		return $this->request->cookie($name);
-	}
-
-	/**
-	 * Checks if a cookie key has been set.
-	 *
-	 * In your view: `$this->Cookie->check('key');`
-	 *
-	 * @param string $name Cookie name to check.
-	 * @return bool
-	 */
-	public function check($name) {
-		return $this->request->cookie($name) !== null;
-	}
-
-	/**
-	 * Event listeners.
-	 *
-	 * @return array
-	 */
-	public function implementedEvents() {
-		return [];
-	}
-
-}

+ 0 - 127
src/View/Helper/FlashHelper.php

@@ -1,127 +0,0 @@
-<?php
-
-namespace Tools\View\Helper;
-
-use Cake\Core\Configure;
-use Cake\Utility\Hash;
-use Cake\View\Helper;
-use Tools\Controller\Component\FlashComponent;
-
-/**
- * Flash helper
- *
- * @author Mark Scherer
- * @license MIT
- * @deprecated Use dereuromark/cakephp-flash plugin instead.
- */
-class FlashHelper extends Helper {
-
-	/**
-	 * Display all flash messages.
-	 *
-	 * @param array $types Types to output. Defaults to all if none are specified.
-	 * @return string HTML
-	 * @deprecated Use render() instead
-	 */
-	public function flash(array $types = []) {
-		return $this->render($types);
-	}
-
-	/**
-	 * Display all flash messages.
-	 *
-	 * TODO: export div wrapping method (for static messaging on a page)
-	 *
-	 * @param array $types Types to output. Defaults to all if none are specified.
-	 * @return string HTML
-	 */
-	public function render(array $types = []) {
-		// Get the messages from the session
-		$messages = (array)$this->request->session()->read('FlashMessage');
-		$cMessages = (array)Configure::read('FlashMessage');
-		if (!empty($cMessages)) {
-			$messages = (array)Hash::merge($messages, $cMessages);
-		}
-		$html = '';
-		if (!empty($messages)) {
-			$html = '<div class="flash-messages">';
-
-			if ($types) {
-				foreach ($types as $type) {
-					// Add a div for each message using the type as the class.
-					foreach ($messages as $messageType => $msgs) {
-						if ($messageType !== $type) {
-							continue;
-						}
-						foreach ((array)$msgs as $msg) {
-							$html .= $this->_message($msg, $messageType);
-						}
-					}
-				}
-			} else {
-				foreach ($messages as $messageType => $msgs) {
-					foreach ((array)$msgs as $msg) {
-						$html .= $this->_message($msg, $messageType);
-					}
-				}
-			}
-			$html .= '</div>';
-			if ($types) {
-				foreach ($types as $type) {
-					$this->request->session()->delete('FlashMessage.' . $type);
-					Configure::delete('FlashMessage.' . $type);
-				}
-			} else {
-				$this->request->session()->delete('FlashMessage');
-				Configure::delete('FlashMessage');
-			}
-		}
-
-		return $html;
-	}
-
-	/**
-	 * Outputs a single flash message directly.
-	 * Note that this does not use the Session.
-	 *
-	 * @param string $message String to output.
-	 * @param string $type Type (success, warning, error, info)
-	 * @param bool $escape Set to false to disable escaping.
-	 * @return string HTML
-	 */
-	public function message($message, $type = 'info', $escape = true) {
-		$html = '<div class="flash-messages">';
-		if ($escape) {
-			$msg = h($message);
-		}
-		$html .= $this->_message($message, $type);
-		$html .= '</div>';
-		return $html;
-	}
-
-	/**
-	 * Formats a message
-	 *
-	 * @param string $msg Message to output.
-	 * @param string $type Type that will be formatted to a class tag.
-	 * @return string
-	 */
-	protected function _message($msg, $type) {
-		if (!empty($msg)) {
-			return '<div class="message' . (!empty($type) ? ' ' . $type : '') . '">' . $msg . '</div>';
-		}
-		return '';
-	}
-
-	/**
-	 * Add a message on the fly
-	 *
-	 * @param string $msg
-	 * @param string|null $class
-	 * @return void
-	 */
-	public function addTransientMessage($msg, $class = null) {
-		FlashComponent::transientMessage($msg, $class);
-	}
-
-}

+ 0 - 347
src/View/Helper/JsHelper.php

@@ -1,347 +0,0 @@
-<?php
-/**
- * Javascript Generator class file.
- *
- * This is deprecated and only here to easy migration from 2.x applications
- * that rely on the JsHelper buffer functionality.
- */
-
-namespace Tools\View\Helper;
-
-use Cake\View\Helper;
-use Tools\Utility\Multibyte;
-
-/**
- * Javascript Generator helper class for easy use of JavaScript.
- *
- * JsHelper provides an abstract interface for authoring JavaScript with a
- * given client-side library.
- *
- * Note: onDomReady always defaults to false now, you will to add this yourself.
- */
-class JsHelper extends Helper {
-
-	/**
-	 * Whether or not you want scripts to be buffered or output.
-	 *
-	 * @var bool
-	 */
-	public $bufferScripts = true;
-
-	/**
-	 * Helper dependencies
-	 *
-	 * @var array
-	 */
-	public $helpers = ['Html', 'Form'];
-
-	/**
-	 * Variables to pass to Javascript.
-	 *
-	 * @var array
-	 */
-	protected $_jsVars = [];
-
-	/**
-	 * Scripts that are queued for output
-	 *
-	 * @var array
-	 */
-	protected $_bufferedScripts = [];
-
-	/**
-	 * The javascript variable created by set() variables.
-	 *
-	 * @var string
-	 */
-	public $setVariable = 'app';
-
-	/**
-	 * Generates a JavaScript object in JavaScript Object Notation (JSON)
-	 * from an array. Will use native JSON encode method if available, and $useNative == true
-	 *
-	 * ### Options:
-	 *
-	 * - `prefix` - String prepended to the returned data.
-	 * - `postfix` - String appended to the returned data.
-	 *
-	 * @param array $data Data to be converted.
-	 * @param array $options Set of options, see above.
-	 * @return string A JSON code block
-	 */
-	public function object($data = [], $options = []) {
-		$defaultOptions = [
-			'prefix' => '', 'postfix' => '',
-		];
-		$options += $defaultOptions;
-
-		return $options['prefix'] . json_encode($data) . $options['postfix'];
-	}
-
-	/**
-	 * Converts a PHP-native variable of any type to a JSON-equivalent representation
-	 *
-	 * @param mixed $val A PHP variable to be converted to JSON
-	 * @param bool $quoteString If false, leaves string values unquoted
-	 * @return string a JavaScript-safe/JSON representation of $val
-	 */
-	public function value($val = [], $quoteString = true) {
-		if ($quoteString === null) {
-			$quoteString = true;
-		}
-		switch (true) {
-			case (is_array($val) || is_object($val)):
-				$val = $this->object($val);
-				break;
-			case ($val === null):
-				$val = 'null';
-				break;
-			case (is_bool($val)):
-				$val = ($val === true) ? 'true' : 'false';
-				break;
-			case (is_int($val)):
-				break;
-			case (is_float($val)):
-				$val = sprintf('%.11f', $val);
-				break;
-			default:
-				$val = $this->escape($val);
-				if ($quoteString) {
-					$val = '"' . $val . '"';
-				}
-		}
-		return $val;
-	}
-
-	/**
-	 * Escape a string to be JSON friendly.
-	 *
-	 * List of escaped elements:
-	 *
-	 * - "\r" => '\n'
-	 * - "\n" => '\n'
-	 * - '"' => '\"'
-	 *
-	 * @param string $string String that needs to get escaped.
-	 * @return string Escaped string.
-	 */
-	public function escape($string) {
-		return $this->_utf8ToHex($string);
-	}
-
-	/**
-	 * Encode a string into JSON. Converts and escapes necessary characters.
-	 *
-	 * @param string $string The string that needs to be utf8->hex encoded
-	 * @return string
-	 */
-	protected function _utf8ToHex($string) {
-		$length = strlen($string);
-		$return = '';
-		for ($i = 0; $i < $length; ++$i) {
-			$ord = ord($string{$i});
-			switch (true) {
-				case $ord == 0x08:
-					$return .= '\b';
-					break;
-				case $ord == 0x09:
-					$return .= '\t';
-					break;
-				case $ord == 0x0A:
-					$return .= '\n';
-					break;
-				case $ord == 0x0C:
-					$return .= '\f';
-					break;
-				case $ord == 0x0D:
-					$return .= '\r';
-					break;
-				case $ord == 0x22:
-				case $ord == 0x2F:
-				case $ord == 0x5C:
-					$return .= '\\' . $string{$i};
-					break;
-				case (($ord >= 0x20) && ($ord <= 0x7F)):
-					$return .= $string{$i};
-					break;
-				case (($ord & 0xE0) == 0xC0):
-					if ($i + 1 >= $length) {
-						$i += 1;
-						$return .= '?';
-						break;
-					}
-					$charbits = $string{$i} . $string{$i + 1};
-					$char = Multibyte::utf8($charbits);
-					$return .= sprintf('\u%04s', dechex($char[0]));
-					$i += 1;
-					break;
-				case (($ord & 0xF0) == 0xE0):
-					if ($i + 2 >= $length) {
-						$i += 2;
-						$return .= '?';
-						break;
-					}
-					$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2};
-					$char = Multibyte::utf8($charbits);
-					$return .= sprintf('\u%04s', dechex($char[0]));
-					$i += 2;
-					break;
-				case (($ord & 0xF8) == 0xF0):
-					if ($i + 3 >= $length) {
-						$i += 3;
-						$return .= '?';
-						break;
-					}
-					$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3};
-					$char = Multibyte::utf8($charbits);
-					$return .= sprintf('\u%04s', dechex($char[0]));
-					$i += 3;
-					break;
-				case (($ord & 0xFC) == 0xF8):
-					if ($i + 4 >= $length) {
-						$i += 4;
-						$return .= '?';
-						break;
-					}
-					$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4};
-					$char = Multibyte::utf8($charbits);
-					$return .= sprintf('\u%04s', dechex($char[0]));
-					$i += 4;
-					break;
-				case (($ord & 0xFE) == 0xFC):
-					if ($i + 5 >= $length) {
-						$i += 5;
-						$return .= '?';
-						break;
-					}
-					$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4} . $string{$i + 5};
-					$char = Multibyte::utf8($charbits);
-					$return .= sprintf('\u%04s', dechex($char[0]));
-					$i += 5;
-					break;
-			}
-		}
-		return $return;
-	}
-
-	/**
-	 * Writes all Javascript generated so far to a code block or
-	 * caches them to a file and returns a linked script. If no scripts have been
-	 * buffered this method will return null. If the request is an XHR(ajax) request
-	 * onDomReady will be set to false. As the dom is already 'ready'.
-	 *
-	 * ### Options
-	 *
-	 * - `inline` - Set to true to have scripts output as a script block inline
-	 *   if `cache` is also true, a script link tag will be generated. (default true)
-	 * - `cache` - Set to true to have scripts cached to a file and linked in (default false)
-	 * - `clear` - Set to false to prevent script cache from being cleared (default true)
-	 * - `onDomReady` - wrap cached scripts in domready event (default true)
-	 * - `safe` - if an inline block is generated should it be wrapped in <![CDATA[ ... ]]> (default true)
-	 *
-	 * @param array $options options for the code block
-	 * @return mixed Completed javascript tag if there are scripts, if there are no buffered
-	 *   scripts null will be returned.
-	 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::writeBuffer
-	 */
-	public function writeBuffer($options = []) {
-		$domReady = false;
-		$defaults = [
-			'onDomReady' => $domReady,
-			'cache' => false, 'clear' => true, 'safe' => true
-		];
-		$options += $defaults;
-		$script = implode("\n", $this->getBuffer($options['clear']));
-
-		if (empty($script)) {
-			return null;
-		}
-
-		if ($options['onDomReady']) {
-			$script = $this->{$this->_engineName}->domReady($script);
-		}
-		$opts = $options;
-		unset($opts['onDomReady'], $opts['cache'], $opts['clear']);
-
-		if (isset($opts['inline'])) {
-			unset($opts['inline']);
-		}
-		$return = $this->Html->scriptBlock($script, $opts);
-
-		return $return;
-	}
-
-	/**
-	 * Write a script to the buffered scripts.
-	 *
-	 * @param string $script Script string to add to the buffer.
-	 * @param bool $top If true the script will be added to the top of the
-	 *   buffered scripts array. If false the bottom.
-	 * @return void
-	 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::buffer
-	 */
-	public function buffer($script, $top = false) {
-		if ($top) {
-			array_unshift($this->_bufferedScripts, $script);
-		} else {
-			$this->_bufferedScripts[] = $script;
-		}
-	}
-
-	/**
-	 * Get all the buffered scripts
-	 *
-	 * @param bool $clear Whether or not to clear the script caches (default true)
-	 * @return array Array of scripts added to the request.
-	 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::getBuffer
-	 */
-	public function getBuffer($clear = true) {
-		$this->_createVars();
-		$scripts = $this->_bufferedScripts;
-		if ($clear) {
-			$this->_bufferedScripts = [];
-			$this->_jsVars = [];
-		}
-		return $scripts;
-	}
-
-	/**
-	 * Generates the object string for variables passed to javascript and adds to buffer
-	 *
-	 * @return void
-	 */
-	protected function _createVars() {
-		if (!empty($this->_jsVars)) {
-			$setVar = (strpos($this->setVariable, '.')) ? $this->setVariable : 'window.' . $this->setVariable;
-			$this->buffer($setVar . ' = ' . $this->object($this->_jsVars) . ';', true);
-		}
-	}
-
-	/**
-	 * Pass variables into Javascript. Allows you to set variables that will be
-	 * output when the buffer is fetched with `JsHelper::getBuffer()` or `JsHelper::writeBuffer()`
-	 * The Javascript variable used to output set variables can be controlled with `JsHelper::$setVariable`
-	 *
-	 * @param string|array $one Either an array of variables to set, or the name of the variable to set.
-	 * @param string|array|null $two If $one is a string, $two is the value for that key.
-	 * @return void
-	 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::set
-	 */
-	public function set($one, $two = null) {
-		$data = null;
-		if (is_array($one)) {
-			if (is_array($two)) {
-				$data = array_combine($one, $two);
-			} else {
-				$data = $one;
-			}
-		} else {
-			$data = [$one => $two];
-		}
-		if (!$data) {
-			return;
-		}
-		$this->_jsVars = array_merge($this->_jsVars, $data);
-	}
-
-}

+ 18 - 28
src/View/Helper/TimelineHelper.php

@@ -24,28 +24,6 @@ class TimelineHelper extends Helper {
 	public $helpers = ['Tools.Js'];
 
 	/**
-	 * @var array
-	 */
-	protected $_defaultConfig = [
-		'id' => 'mytimeline',
-		'selectable' => false,
-		'editable' => false,
-		'min' => null, // Min date.
-		'max' => null, // Max date.
-		'width' => '100%',
-		'height' => null, // Auto.
-		'style' => 'box',
-		'current' => null, // Current time.
-	];
-
-	/**
-	 * @var array
-	 */
-	protected $_items = [];
-
-	/**
-	 * Apply settings and merge them with the defaults.
-	 *
 	 * Possible values are (with their default values):
 	 *  - 'min',
 	 *  - 'max',
@@ -64,13 +42,25 @@ class TimelineHelper extends Helper {
 	 *  - ...
 	 *
 	 * @link http://almende.github.io/chap-links-library/js/timeline/doc/
-	 * @param array $settings Key value pairs to merge with current settings.
-	 * @return void
-	 * @deprecated
+	 *
+	 * @var array
 	 */
-	public function settings($settings) {
-		$this->config($settings);
-	}
+	protected $_defaultConfig = [
+		'id' => 'mytimeline',
+		'selectable' => false,
+		'editable' => false,
+		'min' => null, // Min date.
+		'max' => null, // Max date.
+		'width' => '100%',
+		'height' => null, // Auto.
+		'style' => 'box',
+		'current' => null, // Current time.
+	];
+
+	/**
+	 * @var array
+	 */
+	protected $_items = [];
 
 	/**
 	 * Add timeline item.

+ 0 - 38
tests/TestApp/Controller/FlashComponentTestController.php

@@ -1,38 +0,0 @@
-<?php
-namespace TestApp\Controller;
-
-use Tools\Controller\Controller;
-
-/**
- * Use Controller instead of AppController to avoid conflicts
- */
-class FlashComponentTestController extends Controller {
-
-	/**
-	 * @var array
-	 */
-	public $components = ['Tools.Flash'];
-
-	/**
-	 * @var bool
-	 */
-	public $failed = false;
-
-	/**
-	 * @var array
-	 */
-	public $testHeaders = [];
-
-	public function fail() {
-		$this->failed = true;
-	}
-
-	public function redirect($url, $status = null, $exit = true) {
-		return $status;
-	}
-
-	public function header($status) {
-		$this->testHeaders[] = $status;
-	}
-
-}

+ 18 - 0
tests/TestApp/Controller/UrlComponentTestController.php

@@ -0,0 +1,18 @@
+<?php
+namespace TestApp\Controller;
+
+use Tools\Controller\Controller;
+
+/**
+ * Use Controller instead of AppController to avoid conflicts
+ *
+ * @property \Tools\Controller\Component\UrlComponent $Url
+ */
+class UrlComponentTestController extends Controller {
+
+	/**
+	 * @var array
+	 */
+	public $components = ['Tools.Url'];
+
+}

+ 0 - 171
tests/TestCase/Controller/Component/AuthUserComponentTest.php

@@ -1,171 +0,0 @@
-<?php
-
-namespace Tools\Test\TestCase\Controller\Component;
-
-use Cake\Controller\ComponentRegistry;
-use Cake\Controller\Component\AuthComponent;
-use Cake\Controller\Controller;
-use Cake\Network\Request;
-use Tools\Controller\Component\AuthUserComponent;
-use Tools\TestSuite\TestCase;
-
-/**
- * AuthUserComponent class
- */
-class AuthUserComponentTest extends TestCase {
-
-	/**
-	 * @var array
-	 */
-	public $fixtures = ['core.sessions'];
-
-	/**
-	 * @var \Tools\Controller\Component\AuthUserComponent
-	 */
-	public $AuthUser;
-
-	/**
-	 * @var \Cake\Controller\ComponentRegistry
-	 */
-	public $ComponentRegistry;
-
-	/**
-	 * @return void
-	 */
-	public function setUp() {
-		parent::setUp();
-
-		$controller = new Controller(new Request());
-		$this->ComponentRegistry = new ComponentRegistry($controller);
-		$this->AuthUser = new AuthUserComponent($this->ComponentRegistry);
-		$this->AuthUser->Auth = $this->getMockBuilder(AuthComponent::class)
-			->setMethods(['user'])
-			->setConstructorArgs([$this->ComponentRegistry])
-			->getMock();
-	}
-
-	/**
-	 * @return void
-	 */
-	public function tearDown() {
-		parent::tearDown();
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testEmptyAuthSession() {
-		$this->assertNull($this->AuthUser->id());
-
-		$this->assertFalse($this->AuthUser->isMe(null));
-		$this->assertFalse($this->AuthUser->isMe(''));
-		$this->assertFalse($this->AuthUser->isMe(0));
-		$this->assertFalse($this->AuthUser->isMe(1));
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testId() {
-		$this->AuthUser->Auth->expects($this->once())
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1']));
-
-		$this->assertSame('1', $this->AuthUser->id());
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testIsMe() {
-		$this->AuthUser->Auth->expects($this->any())
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1']));
-
-		$this->assertFalse($this->AuthUser->isMe(null));
-		$this->assertFalse($this->AuthUser->isMe(''));
-		$this->assertFalse($this->AuthUser->isMe(0));
-
-		$this->assertTrue($this->AuthUser->isMe('1'));
-		$this->assertTrue($this->AuthUser->isMe(1));
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testUser() {
-		$this->AuthUser->Auth->expects($this->any())
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1', 'username' => 'foo']));
-
-		$this->assertSame(['id' => '1', 'username' => 'foo'], $this->AuthUser->user());
-		$this->assertSame('foo', $this->AuthUser->user('username'));
-		$this->assertNull($this->AuthUser->user('foofoo'));
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testRoles() {
-		$this->AuthUser->Auth->expects($this->once())
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1', 'Roles' => ['1', '2']]));
-
-		$this->assertSame(['1', '2'], $this->AuthUser->roles());
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testRolesDeep() {
-		$this->AuthUser->Auth->expects($this->once())
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1', 'Roles' => [['id' => '1'], ['id' => '2']]]));
-
-		$this->assertSame(['1', '2'], $this->AuthUser->roles());
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testHasRole() {
-		$this->AuthUser->Auth->expects($this->exactly(3))
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1', 'Roles' => [['id' => '1'], ['id' => '2']]]));
-
-		$this->assertTrue($this->AuthUser->hasRole(2));
-		$this->assertTrue($this->AuthUser->hasRole('2'));
-		$this->assertFalse($this->AuthUser->hasRole(3));
-
-		$this->assertTrue($this->AuthUser->hasRole(3, [1, 3]));
-		$this->assertFalse($this->AuthUser->hasRole(3, [2, 4]));
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testHasRoles() {
-		$this->AuthUser->Auth->expects($this->exactly(6))
-			->method('user')
-			->with(null)
-			->will($this->returnValue(['id' => '1', 'Roles' => [['id' => '1'], ['id' => '2']]]));
-
-		$this->assertTrue($this->AuthUser->hasRoles([2]));
-		$this->assertTrue($this->AuthUser->hasRoles('2'));
-		$this->assertFalse($this->AuthUser->hasRoles([3, 4]));
-		$this->assertTrue($this->AuthUser->hasRoles([1, 2], false));
-
-		$this->assertTrue($this->AuthUser->hasRoles([1, 6], [1, 3, 5]));
-		$this->assertFalse($this->AuthUser->hasRoles([3, 4], [2, 4]));
-
-		$this->assertFalse($this->AuthUser->hasRoles([1, 3, 5], false, [1, 3]));
-		$this->assertTrue($this->AuthUser->hasRoles([1, 3, 5], false, [1, 3, 5]));
-	}
-
-}

+ 0 - 112
tests/TestCase/Controller/Component/FlashComponentTest.php

@@ -1,112 +0,0 @@
-<?php
-
-namespace Tools\Test\TestCase\Controller\Component;
-
-use Cake\Core\Configure;
-use Cake\Event\Event;
-use Cake\Network\Request;
-use TestApp\Controller\FlashComponentTestController;
-use Tools\TestSuite\TestCase;
-
-/**
- */
-class FlashComponentTest extends TestCase {
-
-	/**
-	 * @var \TestApp\Controller\FlashComponentTestController
-	 */
-	public $Controller;
-
-	/**
-	 * @return void
-	 */
-	public function setUp() {
-		parent::setUp();
-
-		Configure::write('App.namespace', 'TestApp');
-
-		$this->Controller = new FlashComponentTestController();
-		$this->Controller->startupProcess();
-
-		$this->Controller->request->session()->delete('FlashMessage');
-	}
-
-	/**
-	 * @return void
-	 */
-	public function tearDown() {
-		parent::tearDown();
-
-		unset($this->Controller->Flash);
-		unset($this->Controller);
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testTransientMessage() {
-		$this->Controller->Flash->transientMessage('xyz', 'success');
-
-		$res = Configure::read('FlashMessage');
-		$this->assertTrue(!empty($res));
-		$this->assertTrue(isset($res['success'][0]) && $res['success'][0] === 'xyz');
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testMessage() {
-		$this->Controller->Flash->message('efg');
-
-		$res = $this->Controller->request->session()->read('FlashMessage');
-		$this->assertTrue(!empty($res));
-		$this->assertTrue(isset($res['info'][0]));
-		$this->assertSame('efg', $res['info'][0]);
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testMagic() {
-		$this->Controller->Flash->error('Some Error Message');
-
-		$res = $this->Controller->request->session()->read('FlashMessage');
-		$this->assertTrue(!empty($res));
-		$this->assertTrue(isset($res['error'][0]));
-		$this->assertSame('Some Error Message', $res['error'][0]);
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testCoreHook() {
-		$this->Controller->Flash->set('Some Message');
-
-		$res = $this->Controller->request->session()->read('FlashMessage');
-		$this->assertTrue(!empty($res));
-		$this->assertTrue(isset($res['info'][0]));
-		$this->assertSame('Some Message', $res['info'][0]);
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testAjax() {
-		$this->Controller->request = $this->getMockBuilder(Request::class)->setMethods(['is'])->getMock();
-		$this->Controller->Flash->success('yeah');
-		$this->Controller->Flash->transientMessage('xyz', 'warning');
-
-		$this->Controller->request->expects($this->once())
-			->method('is')
-			->with('ajax')
-			->will($this->returnValue(true));
-
-		$event = new Event('Controller.startup', $this->Controller);
-		$this->Controller->Flash->beforeRender($event);
-
-		$result = $this->Controller->response->header();
-		$expected = ['X-Flash' => '{"success":["yeah"],"warning":["xyz"]}'];
-		$this->assertSame($expected, $result);
-	}
-
-}

+ 126 - 0
tests/TestCase/Controller/Component/UrlComponentTest.php

@@ -0,0 +1,126 @@
+<?php
+
+namespace Tools\Test\TestCase\Controller\Component;
+
+use Cake\Core\Configure;
+use Cake\Core\Plugin;
+use Cake\Event\Event;
+use Cake\Network\Request;
+use Cake\Routing\Router;
+use TestApp\Controller\UrlComponentTestController;
+use Tools\TestSuite\TestCase;
+
+/**
+ */
+class UrlComponentTest extends TestCase {
+
+	/**
+	 * @var \Cake\Event\Event
+	 */
+	public $event;
+
+	/**
+	 * @var \TestApp\Controller\UrlComponentTestController
+	 */
+	public $Controller;
+
+	/**
+	 * @return void
+	 */
+	public function setUp() {
+		parent::setUp();
+
+		$this->event = new Event('Controller.beforeFilter');
+		$this->Controller = new UrlComponentTestController(new Request());
+
+		Configure::write('App.fullBaseUrl', 'http://localhost');
+	}
+
+	/**
+	 * @return void
+	 */
+	public function tearDown() {
+		parent::tearDown();
+
+		unset($this->Controller);
+	}
+
+	/**
+	 * @return void
+	 */
+	public function testDefaults() {
+		$is = $this->Controller->Url->defaults();
+		$expected = [
+			'prefix' => false,
+			'plugin' => false
+		];
+		$this->assertSame($expected, $is);
+	}
+
+	/**
+	 * @return void
+	 */
+	public function testBuild() {
+		$is = $this->Controller->Url->build(['action' => 'x']);
+		$expected = '/x';
+		$this->assertSame($expected, $is);
+
+		$is = $this->Controller->Url->build(['action' => 'x'], ['fullBase' => true]);
+		$expected = 'http://localhost/x';
+		$this->assertSame($expected, $is);
+	}
+
+	/**
+	 * @return void
+	 */
+	public function testReset() {
+		Router::connect('/:controller/:action/*');
+
+		$result = $this->Controller->Url->reset(['controller' => 'foobar', 'action' => 'test']);
+		$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';
+		Router::reload();
+		Router::connect('/:controller/:action/*');
+		Router::plugin('Foo', function ($routes) {
+			$routes->fallbacks();
+		});
+		Router::prefix('admin', function ($routes) {
+			$routes->plugin('Foo', function ($routes) {
+				$routes->fallbacks();
+			});
+		});
+		Plugin::routes();
+		Router::pushRequest($this->Controller->Url->request);
+
+		$result = $this->Controller->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
+		$expected = '/admin/foo/bar/baz/x';
+		$this->assertSame($expected, $result);
+
+		$result = $this->Controller->Url->reset(['controller' => 'bar', 'action' => 'baz', 'x']);
+		$expected = '/bar/baz/x';
+		$this->assertSame($expected, $result);
+	}
+
+	/**
+	 * @return void
+	 */
+	public function testComplete() {
+		$this->Controller->Url->request->query['x'] = 'y';
+
+		$result = $this->Controller->Url->complete(['action' => 'test']);
+		$expected = '/test?x=y';
+		$this->assertSame($expected, $result);
+
+		$result = $this->Controller->Url->complete(['action' => 'test', '?' => ['a' => 'b']]);
+		$expected = '/test?a=b&x=y';
+		$this->assertSame($expected, $result);
+
+		$expected = '/test?a=b&amp;x=y';
+		$this->assertSame($expected, h($result));
+	}
+
+}

+ 32 - 103
tests/TestCase/Utility/UtilityTest.php

@@ -42,8 +42,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testInArray()
-	 *
 	 * @covers ::inArray
 	 * @return void
 	 */
@@ -70,6 +68,9 @@ class UtilityTest extends TestCase {
 		$this->assertFalse($res);
 	}
 
+	/**
+	 * @return void
+	 */
 	public function testTokenize() {
 		$res = Utility::tokenize('');
 		$this->assertSame([], $res);
@@ -85,8 +86,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testPregMatch()
-	 *
 	 * @covers ::pregMatch
 	 * @return void
 	 */
@@ -121,8 +120,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testPregMatchWithPatternEscape()
-	 *
 	 * @covers ::pregMatch
 	 * @return void
 	 */
@@ -143,8 +140,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testPregMatchAll()
-	 *
 	 * @covers ::pregMatchAll
 	 * @return void
 	 */
@@ -167,8 +162,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testStrSplit()
-	 *
 	 * @covers ::strSplit
 	 * @return void
 	 */
@@ -182,30 +175,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testUrlEncode()
-	 *
-	 * @covers ::urlEncode
-	 * @return void
-	 */
-	public function testUrlEncode() {
-		$res = Utility::urlEncode('Some/cool=value+more-infos');
-		$this->assertSame('U29tZS9jb29sPXZhbHVlK21vcmUtaW5mb3M_', $res);
-	}
-
-	/**
-	 * UtilityTest::testUrlDecode()
-	 *
-	 * @covers ::urlDecode
-	 * @return void
-	 */
-	public function testUrlDecode() {
-		$res = Utility::urlDecode('U29tZS9jb29sPXZhbHVlK21vcmUtaW5mb3M_');
-		$this->assertSame('Some/cool=value+more-infos', $res);
-	}
-
-	/**
-	 * UtilityTest::testTypeCast()
-	 *
 	 * @covers ::typeCast
 	 * @return void
 	 */
@@ -216,19 +185,15 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testGetClientIp()
-	 *
 	 * @covers ::getClientIp
 	 * @return void
 	 */
 	public function testGetClientIp() {
 		$res = Utility::getClientIp();
-		$this->assertEquals(env('REMOTE_ADDR'), $res);
+		$this->assertSame((string)env('REMOTE_ADDR'), $res);
 	}
 
 	/**
-	 * UtilityTest::testFileExists()
-	 *
 	 * @covers ::fileExists
 	 * @return void
 	 */
@@ -247,8 +212,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testUrlExists()
-	 *
 	 * @covers ::urlExists
 	 * @return void
 	 */
@@ -261,17 +224,15 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testGetReferer()
-	 *
 	 * @covers ::getReferer
 	 * @return void
 	 */
 	public function testGetReferer() {
 		$res = Utility::getReferer();
-		$this->assertEquals(env('HTTP_REFERER'), $res);
+		$this->assertSame(env('HTTP_REFERER'), $res);
 
 		$res = Utility::getReferer(true);
-		$this->assertEquals(env('HTTP_REFERER'), $res);
+		$this->assertSame(env('HTTP_REFERER'), $res);
 
 		$_SERVER['HTTP_REFERER'] = '/foo/bar';
 		$res = Utility::getReferer(true);
@@ -279,59 +240,50 @@ class UtilityTest extends TestCase {
 		if (!$base) {
 			$base = ''; //'http://localhost';
 		}
-		$this->assertEquals($base . env('HTTP_REFERER'), $res);
+		$this->assertSame($base . env('HTTP_REFERER'), $res);
 	}
 
 	/**
-	 * UtilityTest::testGetHeaderFromUrl()
-	 *
 	 * @covers ::getHeaderFromUrl
 	 * @return void
 	 */
 	public function testGetHeaderFromUrl() {
 		$res = Utility::getHeaderFromUrl('http://www.spiegel.de');
 		$this->assertTrue(is_array($res) && count($res) > 1);
-		//$this->assertEquals('HTTP/1.0 200 OK', $res[0]);
+		//$this->assertSame('HTTP/1.0 200 OK', $res[0]);
 	}
 
 	/**
-	 * UtilityTest::testAutoPrefixUrl()
-	 *
 	 * @covers ::autoPrefixUrl
 	 * @return void
 	 */
 	public function testAutoPrefixUrl() {
 		$res = Utility::autoPrefixUrl('www.spiegel.de');
-		$this->assertEquals('http://www.spiegel.de', $res);
+		$this->assertSame('http://www.spiegel.de', $res);
 	}
 
 	/**
-	 * UtilityTest::testCleanUrl()
-	 *
 	 * @covers ::cleanUrl
 	 * @return void
 	 */
 	public function testCleanUrl() {
 		$res = Utility::cleanUrl('www.spiegel.de');
-		$this->assertEquals('http://www.spiegel.de', $res);
+		$this->assertSame('http://www.spiegel.de', $res);
 
 		$res = Utility::cleanUrl('http://');
-		$this->assertEquals('', $res);
+		$this->assertSame('', $res);
 
 		$res = Utility::cleanUrl('http://www');
-		$this->assertEquals('', $res);
+		$this->assertSame('', $res);
 
 		$res = Utility::cleanUrl('spiegel.de');
-		$this->assertEquals('http://spiegel.de', $res);
+		$this->assertSame('http://spiegel.de', $res);
 
 		$res = Utility::cleanUrl('spiegel.de', true);
-		//echo returns($res);
-		$this->assertEquals('http://www.spiegel.de', $res);
+		$this->assertSame('http://www.spiegel.de', $res);
 	}
 
 	/**
-	 * UtilityTest::testDeep()
-	 *
 	 * @covers ::trimDeep
 	 * @return void
 	 */
@@ -346,17 +298,16 @@ class UtilityTest extends TestCase {
 			'e 49r ' => 'rf r',
 			'er' => [['ee' => ['rr ' => 'tt']]]
 		];
-		//$this->assertSame($expected, $is);
 
 		$res = Utility::trimDeep($is);
 		$this->assertSame($expected, $res);
-
-		//$res = CommonComponent::trimDeep($is);
-		//$this->assertSame($expected, $res);
 	}
 
-	//TODO: move to boostrap
-
+	/**
+	 * //TODO
+	 *
+	 * @return void
+	 */
 	public function _testDeepFunction() {
 		$is = [
 			'f some',
@@ -381,59 +332,57 @@ class UtilityTest extends TestCase {
 	public function testCountDim() {
 		$data = ['one', '2', 'three'];
 		$result = Utility::countDim($data);
-		$this->assertEquals(1, $result);
+		$this->assertSame(1, $result);
 
 		$data = ['1' => '1.1', '2', '3'];
 		$result = Utility::countDim($data);
-		$this->assertEquals(1, $result);
+		$this->assertSame(1, $result);
 
 		$data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => '3.1.1']];
 		$result = Utility::countDim($data);
-		$this->assertEquals(2, $result);
+		$this->assertSame(2, $result);
 
 		$data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
 		$result = Utility::countDim($data);
-		$this->assertEquals(1, $result);
+		$this->assertSame(1, $result);
 
 		$data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
 		$result = Utility::countDim($data, true);
-		$this->assertEquals(2, $result);
+		$this->assertSame(2, $result);
 
 		$data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
 		$result = Utility::countDim($data);
-		$this->assertEquals(2, $result);
+		$this->assertSame(2, $result);
 
 		$data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
 		$result = Utility::countDim($data, true);
-		$this->assertEquals(3, $result);
+		$this->assertSame(3, $result);
 
 		$data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => '2.1.1.1']]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
 		$result = Utility::countDim($data, true);
-		$this->assertEquals(4, $result);
+		$this->assertSame(4, $result);
 
 		$data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
 		$result = Utility::countDim($data, true);
-		$this->assertEquals(5, $result);
+		$this->assertSame(5, $result);
 
 		$data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
 		$result = Utility::countDim($data, true);
-		$this->assertEquals(5, $result);
+		$this->assertSame(5, $result);
 
 		$set = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
 		$result = Utility::countDim($set, false, 0);
-		$this->assertEquals(2, $result);
+		$this->assertSame(2, $result);
 
 		$result = Utility::countDim($set, true);
-		$this->assertEquals(5, $result);
+		$this->assertSame(5, $result);
 
 		$data = ['one' => [null], ['null' => null], 'three' => [true, false, null]];
 		$result = Utility::countDim($data, true);
-		$this->assertEquals(2, $result);
+		$this->assertSame(2, $result);
 	}
 
 	/**
-	 * UtilityTest::testExpand()
-	 *
 	 * @return void
 	 */
 	public function testExpandList() {
@@ -460,8 +409,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testExpandListWithKeyLessListInvalid()
-	 *
 	 * @expectedException \RuntimeException
 	 * @return void
 	 */
@@ -474,8 +421,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testExpandListWithKeyLessList()
-	 *
 	 * @return void
 	 */
 	public function testExpandListWithKeyLessList() {
@@ -493,8 +438,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testFlatten()
-	 *
 	 * @return void
 	 */
 	public function testFlatten() {
@@ -541,8 +484,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testArrayFlattenBasic()
-	 *
 	 * @covers ::arrayFlatten
 	 * @return void
 	 */
@@ -589,8 +530,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testArrayFlattenAndPreserveKeys()
-	 *
 	 * @covers ::arrayFlatten
 	 * @return void
 	 */
@@ -611,8 +550,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testArrayShiftKeys()
-	 *
 	 * @covers ::arrayShiftKeys
 	 * @return void
 	 */
@@ -634,8 +571,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testTime()
-	 *
 	 * @covers ::returnElapsedTime
 	 * @return void
 	 */
@@ -655,8 +590,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testLogicalAnd()
-	 *
 	 * @covers ::logicalAnd
 	 * @return void
 	 */
@@ -681,8 +614,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testLogicalOr()
-	 *
 	 * @covers ::logicalOr
 	 * @return void
 	 */
@@ -716,8 +647,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * UtilityTest::testIsValidSaveAll()
-	 *
 	 * @covers ::isValidSaveAll
 	 * @return void
 	 */

+ 0 - 172
tests/TestCase/View/Helper/AuthUserHelperTest.php

@@ -1,172 +0,0 @@
-<?php
-
-namespace Tools\Test\TestCase\View\Helper;
-
-use Cake\Network\Request;
-use Cake\View\View;
-use Tools\TestSuite\TestCase;
-use Tools\View\Helper\AuthUserHelper;
-
-/**
- * AuthUserHelper class
- */
-class AuthUserHelperTest extends TestCase {
-
-	/**
-	 * Fixtures
-	 *
-	 * @var array
-	 */
-	public $fixtures = ['core.sessions'];
-
-	/**
-	 * @var \Tools\View\Helper\AuthUserHelper
-	 */
-	public $AuthUser;
-
-	/**
-	 * setUp method
-	 *
-	 * @return void
-	 */
-	public function setUp() {
-		parent::setUp();
-
-		$this->request = $this->getMockBuilder(Request::class)->setMethods(['cookie'])->getMock();
-		$this->view = new View($this->request);
-		$this->AuthUser = new AuthUserHelper($this->view);
-	}
-
-	/**
-	 * tearDown method
-	 *
-	 * @return void
-	 */
-	public function tearDown() {
-		parent::tearDown();
-	}
-
-	/**
-	 * testSessionReadWrite method
-	 *
-	 * @return void
-	 * @expectedException \RuntimeException
-	 */
-	public function testEmptyAuthSessionDueToMissing() {
-		$this->AuthUser->id();
-	}
-
-	/**
-	 * AuthUserHelperTest::testEmptyAuthSession()
-	 *
-	 * @return void
-	 */
-	public function testEmptyAuthSession() {
-		$this->view->viewVars['authUser'] = [];
-		$this->assertNull($this->AuthUser->id());
-
-		$this->assertFalse($this->AuthUser->isMe(null));
-		$this->assertFalse($this->AuthUser->isMe(''));
-		$this->assertFalse($this->AuthUser->isMe(0));
-		$this->assertFalse($this->AuthUser->isMe(1));
-	}
-
-	/**
-	 * AuthUserHelperTest::testId()
-	 *
-	 * @return void
-	 */
-	public function testId() {
-		$this->view->viewVars['authUser'] = ['id' => '1'];
-
-		$this->assertSame('1', $this->AuthUser->id());
-	}
-
-	/**
-	 * AuthUserHelperTest::testId()
-	 *
-	 * @return void
-	 */
-	public function testIsMe() {
-		$this->view->viewVars['authUser'] = ['id' => '1'];
-
-		$this->assertFalse($this->AuthUser->isMe(null));
-		$this->assertFalse($this->AuthUser->isMe(''));
-		$this->assertFalse($this->AuthUser->isMe(0));
-
-		$this->assertTrue($this->AuthUser->isMe('1'));
-		$this->assertTrue($this->AuthUser->isMe(1));
-	}
-
-	/**
-	 * AuthUserHelperTest::testUser()
-	 *
-	 * @return void
-	 */
-	public function testUser() {
-		$this->view->viewVars['authUser'] = ['id' => '1', 'username' => 'foo'];
-
-		$this->assertSame(['id' => '1', 'username' => 'foo'], $this->AuthUser->user());
-		$this->assertSame('foo', $this->AuthUser->user('username'));
-		$this->assertNull($this->AuthUser->user('foofoo'));
-	}
-
-	/**
-	 * AuthUserHelperTest::testRoles()
-	 *
-	 * @return void
-	 */
-	public function testRoles() {
-		$this->view->viewVars['authUser'] = ['id' => '1', 'Roles' => ['1', '2']];
-
-		$this->assertSame(['1', '2'], $this->AuthUser->roles());
-	}
-
-	/**
-	 * AuthUserHelperTest::testRolesDeep()
-	 *
-	 * @return void
-	 */
-	public function testRolesDeep() {
-		$this->view->viewVars['authUser'] = ['id' => '1', 'Roles' => [['id' => '1'], ['id' => '2']]];
-
-		$this->assertSame(['1', '2'], $this->AuthUser->roles());
-	}
-
-	/**
-	 * AuthUserHelperTest::testHasRole()
-	 *
-	 * @return void
-	 */
-	public function testHasRole() {
-		$this->view->viewVars['authUser'] = ['id' => '1', 'Roles' => [['id' => '1'], ['id' => '2']]];
-
-		$this->assertTrue($this->AuthUser->hasRole(2));
-		$this->assertTrue($this->AuthUser->hasRole('2'));
-		$this->assertFalse($this->AuthUser->hasRole(3));
-
-		$this->assertTrue($this->AuthUser->hasRole(3, [1, 3]));
-		$this->assertFalse($this->AuthUser->hasRole(3, [2, 4]));
-	}
-
-	/**
-	 * AuthUserHelperTest::testHasRoles()
-	 *
-	 * @return void
-	 */
-	public function testHasRoles() {
-		$this->view->viewVars['authUser'] = ['id' => '1', 'Roles' => [['id' => '1'], ['id' => '2']]];
-
-		$this->assertTrue($this->AuthUser->hasRoles([2]));
-		$this->assertTrue($this->AuthUser->hasRoles('2'));
-		$this->assertFalse($this->AuthUser->hasRoles([3, 4]));
-		$this->assertTrue($this->AuthUser->hasRoles([1, 2], false));
-
-		$this->assertTrue($this->AuthUser->hasRoles([1, 6], [1, 3, 5]));
-		$this->assertFalse($this->AuthUser->hasRoles([3, 4], [2, 4]));
-
-		$this->assertFalse($this->AuthUser->hasRoles([1, 3, 5], false, [1, 3]));
-		$this->assertTrue($this->AuthUser->hasRoles([1, 3, 5], false, [1, 3, 5]));
-	}
-
-}

+ 0 - 77
tests/TestCase/View/Helper/CookieHelperTest.php

@@ -1,77 +0,0 @@
-<?php
-
-namespace Tools\Test\TestCase\View\Helper;
-
-use Cake\Network\Request;
-use Cake\ORM\Table;
-use Cake\View\View;
-use Tools\TestSuite\TestCase;
-use Tools\View\Helper\CookieHelper;
-
-class CookieHelperTest extends TestCase {
-
-	/**
-	 * @var \Tools\View\Helper\CookieHelper
-	 */
-	public $Cookie;
-
-	/**
-	 * @return void
-	 */
-	public function setUp() {
-		parent::setUp();
-
-		$this->Cookie = new CookieHelper(new View(null));
-		$this->Cookie->request = $this->getMockBuilder(Request::class)->setMethods(['cookie'])->getMock();
-	}
-
-	/**
-	 * @return void
-	 */
-	public function tearDown() {
-		unset($this->Table);
-
-		parent::tearDown();
-	}
-
-	/**
-	 * CookieHelperTest::testObject()
-	 *
-	 * @return void
-	 */
-	public function testObject() {
-		$this->assertInstanceOf('Tools\View\Helper\CookieHelper', $this->Cookie);
-	}
-
-	/**
-	 * CookieHelperTest::testCheck()
-	 *
-	 * @return void
-	 */
-	public function testCheck() {
-		$this->Cookie->request->expects($this->at(0))
-			->method('cookie')
-			->will($this->returnValue(null));
-		$this->Cookie->request->expects($this->at(1))
-			->method('cookie')
-			->will($this->returnValue('val'));
-
-		$this->assertFalse($this->Cookie->check('Foo.key'));
-		$this->assertTrue($this->Cookie->check('Foo.key'));
-	}
-
-	/**
-	 * CookieHelperTest::testRead()
-	 *
-	 * @return void
-	 */
-	public function testRead() {
-		$this->Cookie->request->expects($this->once())
-			->method('cookie')
-			->will($this->returnValue('val'));
-
-		$output = $this->Cookie->read('Foo.key');
-		$this->assertTextEquals('val', $output);
-	}
-
-}

+ 0 - 112
tests/TestCase/View/Helper/FlashHelperTest.php

@@ -1,112 +0,0 @@
-<?php
-
-namespace Tools\Test\TestCase\View\Helper;
-
-use Cake\Routing\Router;
-use Cake\View\View;
-use Tools\TestSuite\TestCase;
-use Tools\View\Helper\FlashHelper;
-
-/**
- * FlashHelper tests
- */
-class FlashHelperTest extends TestCase {
-
-	/**
-	 * @var array
-	 */
-	public $fixtures = ['core.sessions'];
-
-	/**
-	 * @var \Tools\View\Helper\FlashHelper
-	 */
-	public $Flash;
-
-	/**
-	 * @return void
-	 */
-	public function setUp() {
-		parent::setUp();
-
-		Router::reload();
-		$View = new View(null);
-		$this->Flash = new FlashHelper($View);
-	}
-
-	/**
-	 * FlashHelperTest::testMessage()
-	 *
-	 * @return void
-	 */
-	public function testMessage() {
-		$result = $this->Flash->message(h('Foo & bar'), 'success');
-		$expected = '<div class="flash-messages"><div class="message success">Foo &amp; bar</div></div>';
-		$this->assertEquals($expected, $result);
-	}
-
-	/**
-	 * FlashHelperTest::testRender()
-	 *
-	 * @return void
-	 */
-	public function testRender() {
-		$this->Flash->addTransientMessage(h('Foo & bar'), 'success');
-
-		$result = $this->Flash->render();
-		$expected = '<div class="flash-messages"><div class="message success">Foo &amp; bar</div></div>';
-		$this->assertEquals($expected, $result);
-
-		$this->Flash->addTransientMessage('I am an error', 'error');
-		$this->Flash->addTransientMessage('I am a warning', 'warning');
-		$this->Flash->addTransientMessage('I am some info', 'info');
-		$this->Flash->addTransientMessage('I am also some info');
-		$this->Flash->addTransientMessage('I am sth custom', 'custom');
-
-		$result = $this->Flash->render();
-		$this->assertTextContains('message error', $result);
-		$this->assertTextContains('message warning', $result);
-		$this->assertTextContains('message info', $result);
-		$this->assertTextContains('message custom', $result);
-
-		$result = substr_count($result, 'message info');
-		$this->assertSame(2, $result);
-	}
-
-	/**
-	 * Test that you can define your own order or just output a subpart of
-	 * the types.
-	 *
-	 * @return void
-	 */
-	public function testFlashWithTypes() {
-		$this->Flash->addTransientMessage('I am an error', 'error');
-		$this->Flash->addTransientMessage('I am a warning', 'warning');
-		$this->Flash->addTransientMessage('I am some info', 'info');
-		$this->Flash->addTransientMessage('I am also some info');
-		$this->Flash->addTransientMessage('I am sth custom', 'custom');
-
-		$result = $this->Flash->render(['warning', 'error']);
-		$expected = '<div class="flash-messages"><div class="message warning">I am a warning</div><div class="message error">I am an error</div></div>';
-		$this->assertEquals($expected, $result);
-
-		$result = $this->Flash->render(['info']);
-		$expected = '<div class="flash-messages"><div class="message info">I am some info</div><div class="message info">I am also some info</div></div>';
-		$this->assertEquals($expected, $result);
-
-		$result = $this->Flash->render();
-		$expected = '<div class="flash-messages"><div class="message custom">I am sth custom</div></div>';
-		$this->assertEquals($expected, $result);
-	}
-
-	/**
-	 * TearDown method
-	 *
-	 * @return void
-	 */
-	public function tearDown() {
-		parent::tearDown();
-
-		unset($this->Flash);
-	}
-
-}

+ 0 - 64
tests/TestCase/View/Helper/JsHelperTest.php

@@ -1,64 +0,0 @@
-<?php
-
-namespace Tools\Test\TestCase\View\Helper;
-
-use Cake\View\View;
-use Tools\TestSuite\TestCase;
-use Tools\View\Helper\JsHelper;
-
-class JsHelperTest extends TestCase {
-
-	/**
-	 * @return void
-	 */
-	public function setUp() {
-		parent::setUp();
-
-		$this->Js = new JsHelper(new View(null));
-	}
-
-	/**
-	 * @return void
-	 */
-	public function tearDown() {
-		unset($this->Table);
-
- 		//TableRegistry::clear();
-		parent::tearDown();
-	}
-
-	/**
-	 * @return void
-	 */
-	public function testObject() {
-		$this->assertInstanceOf('Tools\View\Helper\JsHelper', $this->Js);
-	}
-
-	/**
-	 * JsHelperTest::testBuffer()
-	 *
-	 * @return void
-	 */
-	public function testBuffer() {
-		$script = <<<JS
-jQuery(document).ready(function() {
-	// Code
-});
-JS;
-		$this->Js->buffer($script);
-
-		$output = $this->Js->writeBuffer();
-
-		$expected = <<<HTML
-<script>
-//<![CDATA[
-jQuery(document).ready(function() {
-	// Code
-});
-//]]>
-</script>
-HTML;
-		$this->assertTextEquals($expected, $output);
-	}
-
-}