Browse Source

Cleanup for next release.

dereuromark 9 years ago
parent
commit
a13f3d16c2

+ 1 - 0
.gitignore

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

+ 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;
+	}
+
+}

+ 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 - 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);
-	}
-
-}

+ 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 - 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);
-	}
-
-}