2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ControllerTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:54:34 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5436
|
2009-05-01 21:05:46 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-26 01:27:02 +00:00
|
|
|
App::import('Controller', 'Controller', false);
|
2010-08-01 04:39:09 +00:00
|
|
|
App::import('Core', array('CakeRequest', 'CakeResponse'));
|
2008-05-30 11:40:08 +00:00
|
|
|
App::import('Component', 'Security');
|
|
|
|
App::import('Component', 'Cookie');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-12-16 05:01:43 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* AppController class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-10-09 17:03:44 +00:00
|
|
|
*/
|
2010-12-16 05:01:43 +00:00
|
|
|
class ControllerTestAppController extends Controller {
|
|
|
|
/**
|
|
|
|
* helpers property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public $helpers = array('Html');
|
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public $uses = array('ControllerPost');
|
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public $components = array('Cookie');
|
2008-10-09 17:03:44 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-12-16 05:01:43 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ControllerPost class
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ControllerPost extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ControllerPost'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ControllerPost';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'posts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* invalidFields property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $invalidFields = array('name' => 'error_msg');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* lastQuery property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var mixed null
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $lastQuery = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeFind method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
|
|
|
* @param mixed $query
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function beforeFind($query) {
|
|
|
|
$this->lastQuery = $query;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* find method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
|
|
|
* @param mixed $type
|
|
|
|
* @param array $options
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-12-18 05:03:03 +00:00
|
|
|
function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
|
|
|
|
if ($conditions == 'popular') {
|
2008-06-08 14:35:14 +00:00
|
|
|
$conditions = array($this->name . '.' . $this->primaryKey .' > ' => '1');
|
2010-12-18 05:03:03 +00:00
|
|
|
$options = Set::merge($fields, compact('conditions'));
|
|
|
|
return parent::find('all', $fields);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-12-18 05:03:03 +00:00
|
|
|
return parent::find($conditions, $fields);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* ControllerPostsController class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-10-09 17:03:44 +00:00
|
|
|
*/
|
2010-12-16 05:01:43 +00:00
|
|
|
class ControllerCommentsController extends ControllerTestAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'ControllerPost'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ControllerComments';
|
2010-12-16 05:01:43 +00:00
|
|
|
|
|
|
|
protected $_mergeParent = 'ControllerTestAppController';
|
2008-10-09 17:03:44 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ControllerComment class
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ControllerComment extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ControllerComment'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Comment';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'comments'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* data property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $data = array('name' => 'Some Name');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* alias property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ControllerComment'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $alias = 'ControllerComment';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-26 01:37:17 +00:00
|
|
|
/**
|
|
|
|
* ControllerAlias class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-09-26 01:37:17 +00:00
|
|
|
*/
|
|
|
|
class ControllerAlias extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-26 01:37:17 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'ControllerAlias'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ControllerAlias';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-26 01:37:17 +00:00
|
|
|
/**
|
|
|
|
* alias property
|
|
|
|
*
|
|
|
|
* @var string 'ControllerSomeAlias'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $alias = 'ControllerSomeAlias';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-26 01:37:17 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
*
|
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'posts';
|
2008-09-26 01:37:17 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-27 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* NameTest class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-08-27 01:30:09 +00:00
|
|
|
*/
|
|
|
|
class NameTest extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-27 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
* @var string 'Name'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Name';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-27 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
* @var string 'names'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-27 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* alias property
|
|
|
|
*
|
|
|
|
* @var string 'ControllerComment'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $alias = 'Name';
|
2008-08-27 01:30:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-09 17:03:44 +00:00
|
|
|
* TestController class
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-12-16 05:01:43 +00:00
|
|
|
class TestController extends ControllerTestAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-09 17:03:44 +00:00
|
|
|
* name property
|
|
|
|
* @var string 'Name'
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestController';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* helpers property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $helpers = array('Session', 'Xml');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* components property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Security');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array('ControllerComment', 'ControllerAlias');
|
2010-12-16 05:01:43 +00:00
|
|
|
|
|
|
|
protected $_mergeParent = 'ControllerTestAppController';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
|
|
|
* @param mixed $testId
|
|
|
|
* @param mixed $test2Id
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index($testId, $test2Id) {
|
2010-09-11 03:37:15 +00:00
|
|
|
$this->data = array(
|
|
|
|
'testId' => $testId,
|
|
|
|
'test2Id' => $test2Id
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestComponent class
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestComponent extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeRedirect method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function beforeRedirect() {
|
|
|
|
}
|
2010-02-28 17:25:35 +00:00
|
|
|
/**
|
|
|
|
* initialize method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-12-18 05:03:03 +00:00
|
|
|
function initialize($controller) {
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* startup method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-12-18 05:03:03 +00:00
|
|
|
function startup($controller) {
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* shutdown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-12-18 05:03:03 +00:00
|
|
|
function shutdown($controller) {
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
2010-07-16 01:52:24 +00:00
|
|
|
/**
|
|
|
|
* beforeRender callback
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-12-18 05:03:03 +00:00
|
|
|
function beforeRender($controller) {
|
2010-07-16 01:52:24 +00:00
|
|
|
if ($this->viewclass) {
|
|
|
|
$controller->view = $this->viewclass;
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* AnotherTestController class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-10-09 17:03:44 +00:00
|
|
|
*/
|
2010-12-16 05:01:43 +00:00
|
|
|
class AnotherTestController extends ControllerTestAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
* @var string 'Name'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'AnotherTest';
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = null;
|
2010-12-16 05:01:43 +00:00
|
|
|
|
|
|
|
protected $_mergeParent = 'ControllerTestAppController';
|
2008-10-09 17:03:44 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ControllerTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class ControllerTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.post', 'core.comment', 'core.name');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
/**
|
2010-09-19 17:47:31 +00:00
|
|
|
* reset environment.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setUp() {
|
|
|
|
App::objects('plugin', null, false);
|
2010-09-22 02:16:33 +00:00
|
|
|
App::build();
|
|
|
|
Router::reload();
|
2010-09-19 17:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* teardown
|
2009-06-11 16:13:16 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-19 17:47:31 +00:00
|
|
|
function teardown() {
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2009-07-24 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 00:02:53 +00:00
|
|
|
/**
|
|
|
|
* testLoadModel method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadModel() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
$Controller = new Controller($request);
|
2010-05-02 00:02:53 +00:00
|
|
|
|
|
|
|
$this->assertFalse(isset($Controller->ControllerPost));
|
|
|
|
|
|
|
|
$result = $Controller->loadModel('ControllerPost');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
|
|
|
$this->assertTrue(in_array('ControllerPost', $Controller->modelNames));
|
|
|
|
|
|
|
|
ClassRegistry::flush();
|
|
|
|
unset($Controller);
|
|
|
|
}
|
|
|
|
|
2010-07-14 00:19:31 +00:00
|
|
|
/**
|
|
|
|
* testLoadModel method from a plugin controller
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadModelInPlugins() {
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
|
|
|
'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS),
|
|
|
|
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS)
|
|
|
|
));
|
|
|
|
App::import('Controller', 'TestPlugin.TestPlugin');
|
|
|
|
|
|
|
|
$Controller = new TestPluginController();
|
|
|
|
$Controller->plugin = 'TestPlugin';
|
|
|
|
$Controller->uses = false;
|
|
|
|
|
|
|
|
$this->assertFalse(isset($Controller->Comment));
|
|
|
|
|
|
|
|
$result = $Controller->loadModel('Comment');
|
|
|
|
$this->assertTrue($result);
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('Comment', $Controller->Comment);
|
2010-07-14 00:19:31 +00:00
|
|
|
$this->assertTrue(in_array('Comment', $Controller->modelNames));
|
|
|
|
|
|
|
|
ClassRegistry::flush();
|
|
|
|
unset($Controller);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testConstructClasses method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testConstructClasses() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
$Controller = new Controller($request);
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller->modelClass = 'ControllerPost';
|
|
|
|
$Controller->passedArgs[] = '1';
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$this->assertEqual($Controller->ControllerPost->id, 1);
|
|
|
|
|
|
|
|
unset($Controller);
|
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller = new Controller($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller->uses = array('ControllerPost', 'ControllerComment');
|
|
|
|
$Controller->passedArgs[] = '1';
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
|
|
|
$this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment'));
|
2008-09-26 01:37:17 +00:00
|
|
|
|
2008-08-25 22:33:36 +00:00
|
|
|
$this->assertEqual($Controller->ControllerComment->name, 'Comment');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($Controller);
|
2008-09-22 04:10:49 +00:00
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)));
|
2008-09-22 04:10:49 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller = new Controller($request);
|
2008-09-22 04:10:49 +00:00
|
|
|
$Controller->uses = array('TestPlugin.TestPluginPost');
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
|
|
|
$this->assertEqual($Controller->modelClass, 'TestPluginPost');
|
|
|
|
$this->assertTrue(isset($Controller->TestPluginPost));
|
|
|
|
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
|
2008-09-26 01:37:17 +00:00
|
|
|
|
2008-09-22 04:10:49 +00:00
|
|
|
unset($Controller);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* testAliasName method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-08-27 01:30:09 +00:00
|
|
|
function testAliasName() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
$Controller = new Controller($request);
|
2008-08-27 01:30:09 +00:00
|
|
|
$Controller->uses = array('NameTest');
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
|
|
|
$this->assertEqual($Controller->NameTest->name, 'Name');
|
|
|
|
$this->assertEqual($Controller->NameTest->alias, 'Name');
|
|
|
|
|
|
|
|
unset($Controller);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPersistent method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPersistent() {
|
2010-06-12 23:01:51 +00:00
|
|
|
$this->markTestIncomplete('persistModel is totally broken right now.');
|
|
|
|
|
2008-08-13 18:07:52 +00:00
|
|
|
Configure::write('Cache.disable', false);
|
2010-06-12 23:01:51 +00:00
|
|
|
$Controller = new Controller();
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller->modelClass = 'ControllerPost';
|
|
|
|
$Controller->persistModel = true;
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'persistent' . DS .'controllerpost.php'));
|
|
|
|
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
2008-08-13 18:07:52 +00:00
|
|
|
@unlink(CACHE . 'persistent' . DS . 'controllerpost.php');
|
|
|
|
@unlink(CACHE . 'persistent' . DS . 'controllerpostregistry.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($Controller);
|
2008-08-13 18:07:52 +00:00
|
|
|
Configure::write('Cache.disable', true);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFlash method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFlash() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2010-09-22 02:16:33 +00:00
|
|
|
$request->webroot = '/';
|
|
|
|
$request->base = '/';
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller($request);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller->flash('this should work', '/flash');
|
2010-08-01 05:43:41 +00:00
|
|
|
$result = $Controller->response->body();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
2008-07-21 02:40:58 +00:00
|
|
|
<title>this should work</title>
|
2008-05-30 11:40:08 +00:00
|
|
|
<style><!--
|
|
|
|
P { text-align:center; font:bold 1.1em sans-serif }
|
|
|
|
A { color:#444; text-decoration:none }
|
|
|
|
A:HOVER { text-decoration: underline; color:#44E }
|
|
|
|
--></style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p><a href="/flash">this should work</a></p>
|
|
|
|
</body>
|
|
|
|
</html>';
|
2008-06-20 20:17:23 +00:00
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-08-28 03:40:36 +00:00
|
|
|
|
2010-09-11 03:37:15 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
|
|
|
$Controller = new Controller($request);
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2009-08-28 03:40:36 +00:00
|
|
|
$Controller->flash('this should work', '/flash', 1, 'ajax2');
|
2010-08-01 05:43:41 +00:00
|
|
|
$result = $Controller->response->body();
|
2009-08-28 03:40:36 +00:00
|
|
|
$this->assertPattern('/Ajax!/', $result);
|
|
|
|
App::build();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testControllerSet method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testControllerSet() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
$Controller = new Controller($request);
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller->set('variable_with_underscores', null);
|
|
|
|
$this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
|
|
|
|
|
|
|
|
$Controller->viewVars = array();
|
|
|
|
$viewVars = array('ModelName' => array('id' => 1, 'name' => 'value'));
|
|
|
|
$Controller->set($viewVars);
|
2009-01-20 19:36:39 +00:00
|
|
|
$this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$Controller->viewVars = array();
|
|
|
|
$Controller->set('variable_with_underscores', 'value');
|
|
|
|
$this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
|
|
|
|
|
|
|
|
$Controller->viewVars = array();
|
|
|
|
$viewVars = array('ModelName' => 'name');
|
|
|
|
$Controller->set($viewVars);
|
2009-01-20 19:36:39 +00:00
|
|
|
$this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$Controller->set('title', 'someTitle');
|
2009-09-29 01:23:40 +00:00
|
|
|
$this->assertIdentical($Controller->viewVars['title'], 'someTitle');
|
2010-04-01 18:31:06 +00:00
|
|
|
$this->assertTrue(empty($Controller->pageTitle));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$Controller->viewVars = array();
|
|
|
|
$expected = array('ModelName' => 'name', 'ModelName2' => 'name2');
|
|
|
|
$Controller->set(array('ModelName', 'ModelName2'), array('name', 'name2'));
|
|
|
|
$this->assertIdentical($Controller->viewVars, $expected);
|
2010-09-18 04:13:03 +00:00
|
|
|
|
|
|
|
$Controller->viewVars = array();
|
|
|
|
$Controller->set(array(3 => 'three', 4 => 'four'));
|
|
|
|
$Controller->set(array(1 => 'one', 2 => 'two'));
|
|
|
|
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
|
|
|
|
$this->assertEqual($Controller->viewVars, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRender method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRender() {
|
2009-11-03 22:42:42 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
), true);
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2010-08-28 04:01:41 +00:00
|
|
|
$Controller = new Controller($request, $this->getMock('CakeResponse'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller->viewPath = 'posts';
|
|
|
|
|
|
|
|
$result = $Controller->render('index');
|
|
|
|
$this->assertPattern('/posts index/', $result);
|
|
|
|
|
|
|
|
$result = $Controller->render('/elements/test_element');
|
|
|
|
$this->assertPattern('/this is the test element/', $result);
|
2008-08-01 11:27:53 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller = new TestController($request);
|
2010-09-19 17:47:31 +00:00
|
|
|
$Controller->helpers = array('Html');
|
2008-07-15 02:13:14 +00:00
|
|
|
$Controller->constructClasses();
|
|
|
|
$Controller->ControllerComment->validationErrors = array('title' => 'tooShort');
|
|
|
|
$expected = $Controller->ControllerComment->validationErrors;
|
2008-08-01 11:27:53 +00:00
|
|
|
|
2008-07-15 02:13:14 +00:00
|
|
|
ClassRegistry::flush();
|
|
|
|
$Controller->viewPath = 'posts';
|
|
|
|
$result = $Controller->render('index');
|
2010-07-15 03:35:58 +00:00
|
|
|
$View = $Controller->View;
|
2008-07-15 02:13:14 +00:00
|
|
|
$this->assertTrue(isset($View->validationErrors['ControllerComment']));
|
|
|
|
$this->assertEqual($expected, $View->validationErrors['ControllerComment']);
|
2008-08-01 11:27:53 +00:00
|
|
|
|
2008-07-15 02:13:14 +00:00
|
|
|
$Controller->ControllerComment->validationErrors = array();
|
2008-08-01 11:27:53 +00:00
|
|
|
ClassRegistry::flush();
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2009-11-03 22:42:42 +00:00
|
|
|
App::build();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-16 01:52:24 +00:00
|
|
|
/**
|
|
|
|
* test that a component beforeRender can change the controller view class.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testComponentBeforeRenderChangingViewClass() {
|
2010-07-19 01:28:52 +00:00
|
|
|
$core = App::core('views');
|
2010-07-16 01:52:24 +00:00
|
|
|
App::build(array(
|
2010-07-19 01:28:52 +00:00
|
|
|
'views' => array(
|
|
|
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS,
|
|
|
|
$core[0]
|
|
|
|
)
|
2010-07-16 01:52:24 +00:00
|
|
|
), true);
|
2010-12-06 01:28:15 +00:00
|
|
|
$Controller = new Controller($this->getMock('CakeRequest'));
|
2010-07-16 01:52:24 +00:00
|
|
|
$Controller->uses = array();
|
|
|
|
$Controller->components = array('Test');
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$Controller->Test->viewclass = 'Theme';
|
|
|
|
$Controller->viewPath = 'posts';
|
|
|
|
$Controller->theme = 'test_theme';
|
|
|
|
$result = $Controller->render('index');
|
2010-07-19 01:28:52 +00:00
|
|
|
$this->assertPattern('/default test_theme layout/', $result);
|
2010-07-16 01:52:24 +00:00
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testToBeInheritedGuardmethods method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testToBeInheritedGuardmethods() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$Controller = new Controller($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($Controller->_beforeScaffold(''));
|
|
|
|
$this->assertTrue($Controller->_afterScaffoldSave(''));
|
|
|
|
$this->assertTrue($Controller->_afterScaffoldSaveError(''));
|
|
|
|
$this->assertFalse($Controller->_scaffoldError(''));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-12 23:01:51 +00:00
|
|
|
/**
|
|
|
|
* Generates status codes for redirect test.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function statusCodeProvider() {
|
|
|
|
return array(
|
|
|
|
array(300, "Multiple Choices"),
|
|
|
|
array(301, "Moved Permanently"),
|
|
|
|
array(302, "Found"),
|
|
|
|
array(303, "See Other"),
|
|
|
|
array(304, "Not Modified"),
|
|
|
|
array(305, "Use Proxy"),
|
2010-08-01 04:40:46 +00:00
|
|
|
array(307, "Temporary Redirect")
|
2010-06-12 23:01:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRedirect method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2010-06-12 23:01:51 +00:00
|
|
|
* @dataProvider statusCodeProvider
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-12 23:01:51 +00:00
|
|
|
function testRedirectByCode($code, $msg) {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
2010-08-22 16:31:55 +00:00
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('statusCode')
|
|
|
|
->with($code);
|
|
|
|
$Controller->response->expects($this->once())->method('header')
|
|
|
|
->with('Location', 'http://cakephp.org');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->redirect('http://cakephp.org', (int)$code, false);
|
|
|
|
$this->assertFalse($Controller->autoRender);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test redirecting by message
|
|
|
|
*
|
|
|
|
* @dataProvider statusCodeProvider
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRedirectByMessage($code, $msg) {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('statusCode')
|
|
|
|
->with($code);
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('header')
|
|
|
|
->with('Location', 'http://cakephp.org');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->redirect('http://cakephp.org', $msg, false);
|
|
|
|
$this->assertFalse($Controller->autoRender);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that redirect triggers methods on the components.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRedirectTriggeringComponentsReturnNull() {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components->expects($this->once())->method('trigger')
|
|
|
|
->will($this->returnValue(null));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('statusCode')
|
|
|
|
->with(301);
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('header')
|
|
|
|
->with('Location', 'http://cakephp.org');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->redirect('http://cakephp.org', 301, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that beforeRedirect callback returnning null doesn't affect things.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRedirectBeforeRedirectModifyingParams() {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components->expects($this->once())->method('trigger')
|
2010-06-12 23:01:51 +00:00
|
|
|
->will($this->returnValue(array('http://book.cakephp.org')));
|
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('statusCode')
|
|
|
|
->with(301);
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2010-08-01 04:40:46 +00:00
|
|
|
$Controller->response->expects($this->once())->method('header')
|
|
|
|
->with('Location', 'http://book.cakephp.org');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->redirect('http://cakephp.org', 301, false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-08-12 02:47:54 +00:00
|
|
|
/**
|
|
|
|
* test that beforeRedirect callback returnning null doesn't affect things.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRedirectBeforeRedirectModifyingParamsArrayReturn() {
|
|
|
|
$Controller = $this->getMock('Controller', array('header', '_stop'));
|
2010-08-28 04:01:41 +00:00
|
|
|
$Controller->response = $this->getMock('CakeResponse');
|
2010-08-12 02:47:54 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
|
|
|
|
|
|
|
$return = array(
|
|
|
|
array(
|
|
|
|
'url' => 'http://example.com/test/1',
|
|
|
|
'exit' => false,
|
|
|
|
'status' => 302
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'url' => 'http://example.com/test/2',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$Controller->Components->expects($this->once())->method('trigger')
|
|
|
|
->will($this->returnValue($return));
|
|
|
|
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->response->expects($this->at(0))->method('header')
|
|
|
|
->with('Location', 'http://example.com/test/2');
|
2010-08-12 02:47:54 +00:00
|
|
|
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->response->expects($this->at(1))->method('statusCode')
|
|
|
|
->with(302);
|
2010-08-12 02:47:54 +00:00
|
|
|
|
|
|
|
$Controller->expects($this->never())->method('_stop');
|
|
|
|
$Controller->redirect('http://cakephp.org', 301);
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMergeVars method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMergeVars() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$TestController = new TestController($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$TestController->constructClasses();
|
|
|
|
|
|
|
|
$testVars = get_class_vars('TestController');
|
2010-12-16 05:01:43 +00:00
|
|
|
$appVars = get_class_vars('ControllerTestAppController');
|
2008-06-23 20:09:24 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$components = is_array($appVars['components'])
|
|
|
|
? array_merge($appVars['components'], $testVars['components'])
|
|
|
|
: $testVars['components'];
|
|
|
|
if (!in_array('Session', $components)) {
|
|
|
|
$components[] = 'Session';
|
|
|
|
}
|
|
|
|
$helpers = is_array($appVars['helpers'])
|
|
|
|
? array_merge($appVars['helpers'], $testVars['helpers'])
|
|
|
|
: $testVars['helpers'];
|
|
|
|
$uses = is_array($appVars['uses'])
|
|
|
|
? array_merge($appVars['uses'], $testVars['uses'])
|
|
|
|
: $testVars['uses'];
|
2008-06-23 20:09:24 +00:00
|
|
|
|
2010-12-11 04:17:42 +00:00
|
|
|
$this->assertEqual(count(array_diff_key($TestController->helpers, array_flip($helpers))), 0);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
|
2008-06-04 02:39:05 +00:00
|
|
|
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
|
2008-10-09 17:03:44 +00:00
|
|
|
|
2010-11-25 03:44:12 +00:00
|
|
|
$expected = array('ControllerComment', 'ControllerAlias', 'ControllerPost');
|
2010-12-16 05:01:43 +00:00
|
|
|
$this->assertEquals($expected, $TestController->uses, '$uses was merged incorrectly, ControllerTestAppController models should be last.');
|
2010-12-11 04:17:42 +00:00
|
|
|
|
|
|
|
$TestController = new AnotherTestController($request);
|
2008-10-09 17:03:44 +00:00
|
|
|
$TestController->constructClasses();
|
|
|
|
|
2010-12-16 05:01:43 +00:00
|
|
|
$appVars = get_class_vars('ControllerTestAppController');
|
2008-10-09 17:03:44 +00:00
|
|
|
$testVars = get_class_vars('AnotherTestController');
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(in_array('ControllerPost', $appVars['uses']));
|
|
|
|
$this->assertNull($testVars['uses']);
|
|
|
|
|
|
|
|
$this->assertFalse(isset($TestController->ControllerPost));
|
|
|
|
|
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$TestController = new ControllerCommentsController($request);
|
2008-10-09 17:03:44 +00:00
|
|
|
$TestController->constructClasses();
|
|
|
|
|
2010-12-16 05:01:43 +00:00
|
|
|
$appVars = get_class_vars('ControllerTestAppController');
|
2008-10-09 17:03:44 +00:00
|
|
|
$testVars = get_class_vars('ControllerCommentsController');
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(in_array('ControllerPost', $appVars['uses']));
|
|
|
|
$this->assertEqual(array('ControllerPost'), $testVars['uses']);
|
|
|
|
|
|
|
|
$this->assertTrue(isset($TestController->ControllerPost));
|
|
|
|
$this->assertTrue(isset($TestController->ControllerComment));
|
2009-02-12 13:36:20 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-28 01:32:20 +00:00
|
|
|
/**
|
|
|
|
* test that options from child classes replace those in the parent classes.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-04-28 01:32:20 +00:00
|
|
|
function testChildComponentOptionsSupercedeParents() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$TestController = new TestController($request);
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2009-04-28 01:32:20 +00:00
|
|
|
$expected = array('foo');
|
|
|
|
$TestController->components = array('Cookie' => $expected);
|
|
|
|
$TestController->constructClasses();
|
|
|
|
$this->assertEqual($TestController->components['Cookie'], $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-02-12 13:36:20 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* Ensure that __mergeVars is not being greedy and merging with
|
2010-12-16 05:01:43 +00:00
|
|
|
* ControllerTestAppController when you make an instance of Controller
|
2009-02-12 13:36:20 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-02-12 13:36:20 +00:00
|
|
|
function testMergeVarsNotGreedy() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$Controller = new Controller($request);
|
2009-02-12 13:36:20 +00:00
|
|
|
$Controller->components = array();
|
|
|
|
$Controller->uses = array();
|
|
|
|
$Controller->constructClasses();
|
2008-10-09 17:03:44 +00:00
|
|
|
|
2010-01-14 04:33:56 +00:00
|
|
|
$this->assertFalse(isset($Controller->Session));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testReferer method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testReferer() {
|
2010-06-29 03:41:48 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-29 03:41:48 +00:00
|
|
|
$request->expects($this->any())->method('referer')
|
|
|
|
->with(true)
|
|
|
|
->will($this->returnValue('/posts/index'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller = new Controller($request);
|
2010-05-08 04:06:13 +00:00
|
|
|
$result = $Controller->referer(null, true);
|
|
|
|
$this->assertEqual($result, '/posts/index');
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2010-05-15 04:53:15 +00:00
|
|
|
$Controller = new Controller($request);
|
|
|
|
$request->setReturnValue('referer', '/', array(true));
|
|
|
|
$result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
|
|
|
|
$this->assertEqual($result, '/posts/index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-29 03:41:48 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
|
|
|
|
|
|
|
$request->expects($this->any())->method('referer')
|
|
|
|
->with(false)
|
|
|
|
->will($this->returnValue('http://localhost/posts/index'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-29 03:41:48 +00:00
|
|
|
$Controller = new Controller($request);
|
|
|
|
$result = $Controller->referer();
|
|
|
|
$this->assertEqual($result, 'http://localhost/posts/index');
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2010-05-08 04:06:13 +00:00
|
|
|
$Controller = new Controller(null);
|
2008-08-13 18:07:52 +00:00
|
|
|
$result = $Controller->referer();
|
2010-05-08 04:06:13 +00:00
|
|
|
$this->assertEqual($result, '/');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSetAction method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSetAction() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$TestController = new TestController($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$TestController->setAction('index', 1, 2);
|
|
|
|
$expected = array('testId' => 1, 'test2Id' => 2);
|
|
|
|
$this->assertidentical($TestController->data, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testUnimplementedIsAuthorized method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2010-06-12 23:01:51 +00:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testUnimplementedIsAuthorized() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$TestController = new TestController($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$TestController->isAuthorized();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testValidateErrors method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testValidateErrors() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$TestController = new TestController($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$TestController->constructClasses();
|
|
|
|
$this->assertFalse($TestController->validateErrors());
|
|
|
|
$this->assertEqual($TestController->validate(), 0);
|
2008-05-31 03:54:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$TestController->ControllerComment->invalidate('some_field', 'error_message');
|
|
|
|
$TestController->ControllerComment->invalidate('some_field2', 'error_message2');
|
2010-06-28 03:21:11 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$comment = new ControllerComment($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$comment->set('someVar', 'data');
|
|
|
|
$result = $TestController->validateErrors($comment);
|
|
|
|
$expected = array('some_field' => 'error_message', 'some_field2' => 'error_message2');
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
$this->assertEqual($TestController->validate($comment), 2);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-21 01:47:34 +00:00
|
|
|
/**
|
|
|
|
* test that validateErrors works with any old model.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testValidateErrorsOnArbitraryModels() {
|
2010-12-06 01:28:15 +00:00
|
|
|
$TestController = new TestController();
|
2010-06-21 01:47:34 +00:00
|
|
|
|
|
|
|
$Post = new ControllerPost();
|
|
|
|
$Post->validate = array('title' => 'notEmpty');
|
|
|
|
$Post->set('title', '');
|
|
|
|
$result = $TestController->validateErrors($Post);
|
|
|
|
|
|
|
|
$expected = array('title' => 'This field cannot be left blank');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testPostConditions method
|
2008-06-23 20:09:24 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPostConditions() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller = new Controller($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'Model1' => array('field1' => '23'),
|
|
|
|
'Model2' => array('field2' => 'string'),
|
|
|
|
'Model3' => array('field3' => '23'),
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'Model1.field1' => '23',
|
|
|
|
'Model2.field2' => 'string',
|
|
|
|
'Model3.field3' => '23',
|
|
|
|
);
|
|
|
|
$result = $Controller->postConditions($data);
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$Controller->data = array(
|
|
|
|
'Model1' => array('field1' => '23'),
|
|
|
|
'Model2' => array('field2' => 'string'),
|
|
|
|
'Model3' => array('field3' => '23'),
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'Model1.field1' => '23',
|
|
|
|
'Model2.field2' => 'string',
|
|
|
|
'Model3.field3' => '23',
|
|
|
|
);
|
|
|
|
$result = $Controller->postConditions($data);
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$Controller->data = array();
|
|
|
|
$result = $Controller->postConditions($data);
|
|
|
|
$this->assertNull($result);
|
|
|
|
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$Controller->data = array(
|
|
|
|
'Model1' => array('field1' => '23'),
|
|
|
|
'Model2' => array('field2' => 'string'),
|
|
|
|
'Model3' => array('field3' => '23'),
|
|
|
|
);
|
|
|
|
$ops = array(
|
|
|
|
'Model1.field1' => '>',
|
|
|
|
'Model2.field2' => 'LIKE',
|
|
|
|
'Model3.field3' => '<=',
|
|
|
|
);
|
|
|
|
$expected = array(
|
2008-06-09 08:29:56 +00:00
|
|
|
'Model1.field1 >' => '23',
|
|
|
|
'Model2.field2 LIKE' => "%string%",
|
|
|
|
'Model3.field3 <=' => '23',
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$result = $Controller->postConditions($data, $ops);
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-12-13 22:48:01 +00:00
|
|
|
/**
|
2008-06-23 20:09:24 +00:00
|
|
|
* testRequestHandlerPrefers method
|
2009-12-13 22:48:01 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-23 20:09:24 +00:00
|
|
|
function testRequestHandlerPrefers(){
|
2008-07-04 13:26:43 +00:00
|
|
|
Configure::write('debug', 2);
|
2009-12-13 22:48:01 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2009-12-13 22:48:01 +00:00
|
|
|
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller = new Controller($request);
|
2009-12-13 22:48:01 +00:00
|
|
|
|
2008-06-23 20:09:24 +00:00
|
|
|
$Controller->components = array("RequestHandler");
|
|
|
|
$Controller->modelClass='ControllerPost';
|
2010-05-08 04:00:19 +00:00
|
|
|
$Controller->params['url'] = array('ext' => 'rss');
|
2008-06-23 20:09:24 +00:00
|
|
|
$Controller->constructClasses();
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->Components->trigger('initialize', array(&$Controller));
|
2008-06-23 20:09:24 +00:00
|
|
|
$Controller->beforeFilter();
|
2010-08-28 04:29:50 +00:00
|
|
|
$Controller->Components->trigger('startup', array(&$Controller));
|
2009-12-13 22:48:01 +00:00
|
|
|
|
2008-06-23 20:09:24 +00:00
|
|
|
$this->assertEqual($Controller->RequestHandler->prefers(), 'rss');
|
|
|
|
unset($Controller);
|
|
|
|
}
|
2009-12-13 22:48:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testControllerHttpCodes method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testControllerHttpCodes() {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('httpCodes'));
|
2010-08-01 04:39:09 +00:00
|
|
|
$Controller->response->expects($this->at(0))->method('httpCodes')->with(null);
|
|
|
|
$Controller->response->expects($this->at(1))->method('httpCodes')->with(100);
|
|
|
|
$Controller->httpCodes();
|
|
|
|
$Controller->httpCodes(100);
|
2009-12-13 22:48:01 +00:00
|
|
|
}
|
2010-02-28 17:25:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the startup process calls the correct functions
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testStartupProcess() {
|
2010-06-12 23:01:51 +00:00
|
|
|
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));
|
|
|
|
|
|
|
|
$Controller->components = array('MockStartup');
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->expects($this->once())->method('beforeFilter');
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components->expects($this->at(0))->method('trigger')
|
2010-09-15 03:02:38 +00:00
|
|
|
->with('initialize', array(&$Controller));
|
2010-07-05 00:49:47 +00:00
|
|
|
|
|
|
|
$Controller->Components->expects($this->at(1))->method('trigger')
|
|
|
|
->with('startup', array(&$Controller));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->startupProcess();
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Tests that the shutdown process calls the correct functions
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testShutdownProcess() {
|
2010-06-12 23:01:51 +00:00
|
|
|
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));
|
|
|
|
|
|
|
|
$Controller->components = array('MockShutdown');
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection');
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->expects($this->once())->method('afterFilter');
|
2010-07-05 00:49:47 +00:00
|
|
|
$Controller->Components->expects($this->once())->method('trigger')
|
|
|
|
->with('shutdown', array(&$Controller));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->shutdownProcess();
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
2010-09-11 03:15:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that BC works for attributes on the request object.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testPropertyBackwardsCompatibility() {
|
|
|
|
$request = new CakeRequest('posts/index', null);
|
|
|
|
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
$request->data = array('Post' => array('id' => 1));
|
|
|
|
$request->here = '/posts/index';
|
|
|
|
$request->webroot = '/';
|
|
|
|
|
|
|
|
$Controller = new TestController($request);
|
|
|
|
$this->assertEquals($request->data, $Controller->data);
|
|
|
|
$this->assertEquals($request->webroot, $Controller->webroot);
|
|
|
|
$this->assertEquals($request->here, $Controller->here);
|
|
|
|
$this->assertEquals($request->action, $Controller->action);
|
|
|
|
|
2010-11-01 00:02:26 +00:00
|
|
|
$this->assertFalse(empty($Controller->data));
|
|
|
|
$this->assertTrue(isset($Controller->data));
|
|
|
|
$this->assertTrue(empty($Controller->something));
|
|
|
|
$this->assertFalse(isset($Controller->something));
|
|
|
|
|
2010-09-11 03:15:32 +00:00
|
|
|
$this->assertEquals($request, $Controller->params);
|
|
|
|
$this->assertEquals($request->params['controller'], $Controller->params['controller']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that the BC wrapper doesn't interfere with models and components.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testPropertyCompatibilityAndModelsComponents() {
|
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$Controller = new TestController($request);
|
|
|
|
$Controller->constructClasses();
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('SecurityComponent', $Controller->Security);
|
|
|
|
$this->assertInstanceOf('ControllerComment', $Controller->ControllerComment);
|
2010-09-11 03:15:32 +00:00
|
|
|
}
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that using Controller::paginate() falls back to PaginatorComponent
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testPaginateBackwardsCompatibility() {
|
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
$request->params['pass'] = $request->params['named'] = array();
|
|
|
|
|
|
|
|
$Controller = new Controller($request);
|
|
|
|
$Controller->uses = array('ControllerPost', 'ControllerComment');
|
|
|
|
$Controller->passedArgs[] = '1';
|
|
|
|
$Controller->params['url'] = array();
|
|
|
|
$Controller->constructClasses();
|
2010-12-19 22:38:21 +00:00
|
|
|
$expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
|
|
|
|
$this->assertEqual($Controller->paginate, $expected);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
|
|
|
$this->assertEqual($results, array(1, 2, 3));
|
|
|
|
|
|
|
|
$Controller->passedArgs = array();
|
|
|
|
$Controller->paginate = array('limit' => '-1');
|
|
|
|
$this->assertEqual($Controller->paginate, array('limit' => '-1'));
|
|
|
|
$Controller->paginate('ControllerPost');
|
|
|
|
$this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
|
|
|
|
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
|
|
|
|
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
|
|
|
|
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|