Skip to content
Permalink
Browse files

Update Controller & Component tests to remove Controller parameter.

The Controller parameter is not used in all components, it is also
redundant given that $event->subject() exists. Keeping the callback
signatures simple is more important than adding redundant parameters at
this point in time.

Re-enable most of the controller tests. Most do not rely on Models and
can be re-enabled. A few tests are failing as beforeRedirect() is not
complete.
  • Loading branch information...
markstory committed Jul 16, 2013
1 parent 581846e commit 670bfde3b5168c7abd3dd4c66a71f0b59ae087d3
@@ -50,14 +50,16 @@
*
* Each callback has a slightly different signature:
*
* - `intitalize(Event $event, Controller $controller)`
* - `startup(Event $event, Controller $controller)`
* - `beforeRender(Event $event, Controller $controller)`
* - `beforeRedirect(Event $event, Controller $controller, $url, $status, $exit)`
* - `shutdown(Event $event, Controller $controller)`
*
* @package Cake.Controller
* @link http://book.cakephp.org/2.0/en/controllers/components.html
* - `intitalize(Event $event)`
* - `startup(Event $event)`
* - `beforeRender(Event $event)`
* - `beforeRedirect(Event $event $url, $status, $exit)`
* - `shutdown(Event $event)`
*
* While the controller is not an explicit argument it is the subject of each event
* and can be fetched using Event::subject().
*
* @link http://book.cakephp.org/2.0/en/controllers/components.html
* @see Controller::$components
*/
class Component extends Object implements EventListener {
@@ -9,7 +9,6 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller.Component
* @since CakePHP(tm) v 0.10.0.1076
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
@@ -20,6 +20,7 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Error;
use Cake\Event\Event;
use Cake\Model\Datasource\Session;
use Cake\Network\Request;
use Cake\Network\Response;
@@ -257,10 +258,11 @@ class AuthComponent extends Component {
/**
* Initializes AuthComponent for use in the controller
*
* @param Controller $controller A reference to the instantiating controller object
* @param Event $event The initialize event.
* @return void
*/
public function initialize(Controller $controller) {
public function initialize(Event $event) {
$controller = $event->subject();
$this->request = $controller->request;
$this->response = $controller->response;
$this->_methods = $controller->methods;
@@ -274,10 +276,11 @@ public function initialize(Controller $controller) {
* Main execution method. Handles redirecting of invalid users, and processing
* of login form data.
*
* @param Controller $controller A reference to the instantiating controller object
* @param Event $event The startup event.
* @return boolean
*/
public function startup(Controller $controller) {
public function startup(Event $event) {
$controller = $event->subject();
$methods = array_flip(array_map('strtolower', $controller->methods));
$action = strtolower($controller->request->params['action']);
@@ -1,9 +1,5 @@
<?php
/**
* Cookie Component
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -13,7 +9,6 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller.Component
* @since CakePHP(tm) v 1.2.0.4213
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
@@ -34,7 +29,6 @@
*
* Cookie handling for the controller.
*
* @package Cake.Controller.Component
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html
*
*/
@@ -206,10 +200,9 @@ public function __construct(ComponentCollection $collection, $settings = array()
* Start CookieComponent for use in the controller
*
* @param Event $event An Event instance
* @param Controller $controller
* @return void
*/
public function startup(Event $event, Controller $controller) {
public function startup(Event $event) {
$this->_expire($this->time);
$this->_values[$this->name] = array();
@@ -123,11 +123,10 @@ public function __construct(ComponentCollection $collection, $settings = array()
* and the requested mime-types, RequestHandler::$ext is set to that value.
*
* @param Event $event The initialize event that was fired.
* @param Controller $controller A reference to the controller
* @return void
* @see Router::parseExtensions()
*/
public function initialize(Event $event, Controller $controller) {
public function initialize(Event $event) {
if (isset($this->request->params['_ext'])) {
$this->ext = $this->request->params['_ext'];
}
@@ -198,7 +197,8 @@ protected function _setExtension() {
* @param Controller $controller A reference to the controller
* @return void
*/
public function startup(Event $event, Controller $controller) {
public function startup(Event $event) {
$controller = $event->subject();
$controller->request->params['isAjax'] = $this->request->is('ajax');
$isRecognized = (
!in_array($this->ext, array('html', 'htm')) &&
@@ -245,13 +245,12 @@ public function convertXml($xml) {
* Modifies the $_POST and $_SERVER['REQUEST_METHOD'] to simulate a new GET request.
*
* @param Event $event The Controller.beforeRedirect event.
* @param Controller $controller A reference to the controller
* @param string|array $url A string or array containing the redirect location
* @param integer|array $status HTTP Status for redirect
* @param boolean $exit
* @return void
*/
public function beforeRedirect(Event $event, Controller $controller, $url, $status = null, $exit = true) {
public function beforeRedirect(Event $event, $url, $status = null, $exit = true) {
if (!$this->request->is('ajax')) {
return;
}
@@ -270,6 +269,7 @@ public function beforeRedirect(Event $event, Controller $controller, $url, $stat
$code = key($statusCode);
$this->response->statusCode($code);
}
$controller = $event->subject();
$this->response->body($controller->requestAction($url, array('return', 'bare' => false)));
$this->response->send();
$this->_stop();
@@ -285,7 +285,7 @@ public function beforeRedirect(Event $event, Controller $controller, $url, $stat
* @param Controller $controller
* @return boolean false if the render process should be aborted
*/
public function beforeRender(Event $event, Controller $controller) {
public function beforeRender(Event $event) {
if ($this->settings['checkHttpCache'] && $this->response->checkNotModified($this->request)) {
return false;
}
@@ -217,10 +217,10 @@ class SecurityComponent extends Component {
* Component startup. All security checking happens here.
*
* @param Event $event An Event instance
* @param Controller $controller Instantiating controller
* @return void
*/
public function startup(Event $event, Controller $controller) {
public function startup(Event $event) {
$controller = $event->subject();
$this->request = $controller->request;
$this->_action = $this->request->params['action'];
$this->_methodsRequired($controller);
@@ -1,9 +1,5 @@
<?php
/**
* SessionComponent. Provides access to Sessions from the Controller layer
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -13,7 +9,6 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller.Component
* @since CakePHP(tm) v 0.10.0.1232
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
@@ -27,7 +22,6 @@
* page requests. It acts as a wrapper for the `$_SESSION` as well as providing
* convenience methods for several `$_SESSION` related functions.
*
* @package Cake.Controller.Component
* @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html
* @link http://book.cakephp.org/2.0/en/development/sessions.html
*/
@@ -20,8 +20,6 @@
/**
* Class TestPluginController
*
* @package Cake.Test.TestApp.Plugin.TestPlugin.Controller
*/
namespace TestPlugin\Controller;
@@ -52,8 +52,8 @@ public function setUp() {
$this->Cookie->secure = false;
$this->Cookie->key = 'somerandomhaskey';
$event = new Event('Controller.startup');
$this->Cookie->startup($event, $this->Controller);
$event = new Event('Controller.startup', $this->Controller);
$this->Cookie->startup($event);
}
/**
Oops, something went wrong.

0 comments on commit 670bfde

Please sign in to comment.
You can’t perform that action at this time.