Skip to content

Commit

Permalink
Update Controller & Component tests to remove Controller parameter.
Browse files Browse the repository at this point in the history
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 18, 2013
1 parent 581846e commit 670bfde
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 284 deletions.
18 changes: 10 additions & 8 deletions lib/Cake/Controller/Component.php
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion lib/Cake/Controller/Component/AclComponent.php
Expand Up @@ -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
*/
Expand Down
11 changes: 7 additions & 4 deletions lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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']);

Expand Down
9 changes: 1 addition & 8 deletions lib/Cake/Controller/Component/CookieComponent.php
@@ -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)
*
Expand All @@ -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
*/
Expand All @@ -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
*
*/
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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')) &&
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Component/SecurityComponent.php
Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions lib/Cake/Controller/Component/SessionComponent.php
@@ -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)
*
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down
Expand Up @@ -20,8 +20,6 @@

/**
* Class TestPluginController
*
* @package Cake.Test.TestApp.Plugin.TestPlugin.Controller
*/
namespace TestPlugin\Controller;

Expand Down
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 670bfde

Please sign in to comment.