2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-05-01 21:05:46 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) 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
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-05-01 21:05:46 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:54:34 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
2011-02-23 03:33:04 +00:00
|
|
|
App::uses('Router', 'Routing');
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('CakeRequest', 'Network');
|
|
|
|
App::uses('CakeResponse', 'Network');
|
|
|
|
App::uses('SecurityComponent', 'Controller/Component');
|
|
|
|
App::uses('CookieComponent', 'Controller/Component');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* AppController class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-10-09 17:03:44 +00:00
|
|
|
*/
|
2010-12-16 05:01:43 +00:00
|
|
|
class ControllerTestAppController extends Controller {
|
2012-03-12 02:20:25 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
2010-12-16 05:01:43 +00:00
|
|
|
* helpers property
|
2008-10-09 17:03:44 +00:00
|
|
|
*
|
2010-12-16 05:01:43 +00:00
|
|
|
* @var array
|
2008-10-09 17:03:44 +00:00
|
|
|
*/
|
2010-12-16 05:01:43 +00:00
|
|
|
public $helpers = array('Html');
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-12-16 05:01:43 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $uses = array('ControllerPost');
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-12-16 05:01:43 +00:00
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeFind($query) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string $type
|
2008-06-23 20:09:24 +00:00
|
|
|
* @param array $options
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-11-13 01:43:55 +00:00
|
|
|
public function find($type = 'first', $options = array()) {
|
2013-02-12 02:38:08 +00:00
|
|
|
if ($type === 'popular') {
|
2012-03-12 02:20:25 +00:00
|
|
|
$conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
|
2012-03-11 01:57:18 +00:00
|
|
|
$options = Hash::merge($options, compact('conditions'));
|
2010-12-20 04:03:37 +00:00
|
|
|
return parent::find('all', $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-12-20 04:03:37 +00:00
|
|
|
return parent::find($type, $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-12 02:20:25 +00:00
|
|
|
|
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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ControllerComments';
|
2011-02-12 20:54:39 +00:00
|
|
|
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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'
|
|
|
|
*/
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
*/
|
2011-07-10 14:52:54 +00:00
|
|
|
public $name = 'Test';
|
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
|
|
|
|
*/
|
2011-07-10 14:52:54 +00:00
|
|
|
public $helpers = array('Session');
|
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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array('ControllerComment', 'ControllerAlias');
|
2011-02-12 20:54:39 +00:00
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-12 02:20:25 +00:00
|
|
|
public function index($testId, $testTwoId) {
|
2010-09-11 03:37:15 +00:00
|
|
|
$this->data = array(
|
|
|
|
'testId' => $testId,
|
2012-03-12 02:20:25 +00:00
|
|
|
'test2Id' => $testTwoId
|
2010-09-11 03:37:15 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-07-10 15:02:16 +00:00
|
|
|
|
2012-01-15 20:00:30 +00:00
|
|
|
/**
|
|
|
|
* view method
|
|
|
|
*
|
|
|
|
* @param mixed $testId
|
|
|
|
* @param mixed $test2Id
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-12 02:20:25 +00:00
|
|
|
public function view($testId, $testTwoId) {
|
2012-01-15 20:00:30 +00:00
|
|
|
$this->data = array(
|
|
|
|
'testId' => $testId,
|
2012-03-12 02:20:25 +00:00
|
|
|
'test2Id' => $testTwoId
|
2012-01-15 20:00:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-10 15:02:16 +00:00
|
|
|
public function returner() {
|
|
|
|
return 'I am from the controller.';
|
|
|
|
}
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2012-04-09 01:01:25 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2011-07-10 14:52:54 +00:00
|
|
|
protected function protected_m() {
|
|
|
|
}
|
|
|
|
|
|
|
|
private function private_m() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function _hidden() {
|
|
|
|
}
|
2012-04-09 01:01:25 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2011-07-10 14:52:54 +00:00
|
|
|
|
|
|
|
public function admin_add() {
|
|
|
|
}
|
2012-03-12 02:20:25 +00:00
|
|
|
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestComponent extends Object {
|
2012-03-12 02:20:25 +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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeRedirect() {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-02-28 17:25:35 +00:00
|
|
|
/**
|
|
|
|
* initialize method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 14:06:25 +00:00
|
|
|
public function initialize(Controller $controller) {
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* startup method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 14:06:25 +00:00
|
|
|
public function startup(Controller $controller) {
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-02-28 17:25:35 +00:00
|
|
|
/**
|
|
|
|
* shutdown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 14:06:25 +00:00
|
|
|
public function shutdown(Controller $controller) {
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-07-16 01:52:24 +00:00
|
|
|
/**
|
|
|
|
* beforeRender callback
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 14:06:25 +00:00
|
|
|
public function beforeRender(Controller $controller) {
|
2010-07-16 01:52:24 +00:00
|
|
|
if ($this->viewclass) {
|
2011-02-12 20:54:39 +00:00
|
|
|
$controller->viewClass = $this->viewclass;
|
2010-07-16 01:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-12 02:20:25 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-01-19 04:33:36 +00:00
|
|
|
class Test2Component extends TestComponent {
|
|
|
|
|
2012-02-23 14:06:25 +00:00
|
|
|
public function beforeRender(Controller $controller) {
|
2012-01-19 04:33:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-03-12 02:20:25 +00:00
|
|
|
|
2012-01-19 04:33:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* AnotherTestController class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'AnotherTest';
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-10-09 17:03:44 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-02-29 00:35:06 +00:00
|
|
|
public $uses = false;
|
2011-02-12 20:54:39 +00:00
|
|
|
|
2011-12-06 20:52:48 +00:00
|
|
|
/**
|
|
|
|
* merge parent
|
2012-05-04 14:58:51 +00:00
|
|
|
*
|
2011-12-06 20:52:48 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
|
*/
|
2012-06-18 14:40:37 +00:00
|
|
|
public $fixtures = array(
|
|
|
|
'core.post',
|
|
|
|
'core.comment'
|
|
|
|
);
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::setUp();
|
2010-09-19 17:47:31 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown
|
2009-06-11 16:13:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2012-04-16 02:20:34 +00:00
|
|
|
CakePlugin::unload();
|
2009-07-24 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 00:02:53 +00:00
|
|
|
/**
|
|
|
|
* testLoadModel method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadModel() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2011-07-03 18:51:58 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
$Controller = new Controller($request, $response);
|
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'));
|
2011-07-12 05:49:14 +00:00
|
|
|
$this->assertTrue(in_array('ControllerPost', $Controller->uses));
|
2010-05-02 00:02:53 +00:00
|
|
|
|
|
|
|
ClassRegistry::flush();
|
|
|
|
unset($Controller);
|
|
|
|
}
|
|
|
|
|
2010-07-14 00:19:31 +00:00
|
|
|
/**
|
|
|
|
* testLoadModel method from a plugin controller
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadModelInPlugins() {
|
2010-07-14 00:19:31 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2011-04-17 10:35:21 +00:00
|
|
|
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
|
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS)
|
2010-07-14 00:19:31 +00:00
|
|
|
));
|
2011-05-10 16:13:38 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2011-02-23 03:33:04 +00:00
|
|
|
App::uses('TestPluginAppController', 'TestPlugin.Controller');
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('TestPluginController', 'TestPlugin.Controller');
|
2010-07-14 00:19:31 +00:00
|
|
|
|
|
|
|
$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);
|
2011-07-12 05:49:14 +00:00
|
|
|
$this->assertTrue(in_array('Comment', $Controller->uses));
|
2010-07-14 00:19:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConstructClasses() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2010-06-29 03:41:48 +00:00
|
|
|
|
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->constructClasses();
|
|
|
|
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
|
|
|
$this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment'));
|
2008-09-26 01:37:17 +00:00
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Comment', $Controller->ControllerComment->name);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($Controller);
|
2008-09-22 04:10:49 +00:00
|
|
|
|
2012-02-18 12:31:29 +00:00
|
|
|
App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
|
2011-05-10 16:13:38 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
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->assertTrue(isset($Controller->TestPluginPost));
|
|
|
|
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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();
|
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Name', $Controller->NameTest->name);
|
|
|
|
$this->assertEquals('Name', $Controller->NameTest->alias);
|
2008-08-27 01:30:09 +00:00
|
|
|
|
|
|
|
unset($Controller);
|
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
2011-07-08 01:31:28 +00:00
|
|
|
$Controller = new Controller($request, $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
|
|
|
|
2012-12-22 22:02:25 +00:00
|
|
|
$expected = '<!DOCTYPE html>
|
|
|
|
<html>
|
2008-05-30 11:40:08 +00:00
|
|
|
<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);
|
2012-03-12 02:20:25 +00:00
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-08-28 03:40:36 +00:00
|
|
|
|
2010-09-11 03:37:15 +00:00
|
|
|
App::build(array(
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2010-09-11 03:37:15 +00:00
|
|
|
));
|
|
|
|
$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();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Ajax!/', $result);
|
2009-08-28 03:40:36 +00:00
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($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'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame($expected, $Controller->viewVars);
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $Controller->viewVars);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRender() {
|
2009-11-03 22:42:42 +00:00
|
|
|
App::build(array(
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2011-07-12 05:49:14 +00:00
|
|
|
ClassRegistry::flush();
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2011-02-12 20:54:39 +00:00
|
|
|
$request->params['action'] = 'index';
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2011-07-03 18:51:58 +00:00
|
|
|
$Controller = new Controller($request, new CakeResponse());
|
2011-05-16 21:36:55 +00:00
|
|
|
$Controller->viewPath = 'Posts';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $Controller->render('index');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/posts index/', (string)$result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-02-12 20:54:39 +00:00
|
|
|
$Controller->view = 'index';
|
|
|
|
$result = $Controller->render();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/posts index/', (string)$result);
|
2011-02-12 20:54:39 +00:00
|
|
|
|
2011-05-16 21:36:55 +00:00
|
|
|
$result = $Controller->render('/Elements/test_element');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/this is the test element/', (string)$result);
|
2011-02-12 20:54:39 +00:00
|
|
|
$Controller->view = null;
|
2008-08-01 11:27:53 +00:00
|
|
|
|
2011-07-03 18:51:58 +00:00
|
|
|
$Controller = new TestController($request, new CakeResponse());
|
2011-07-23 18:49:39 +00:00
|
|
|
$Controller->uses = array('ControllerAlias', 'TestPlugin.ControllerComment', 'ControllerPost');
|
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
|
|
|
|
2011-05-16 21:36:55 +00:00
|
|
|
$Controller->viewPath = 'Posts';
|
2008-07-15 02:13:14 +00:00
|
|
|
$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']));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $View->validationErrors['ControllerComment']);
|
2008-08-01 11:27:53 +00:00
|
|
|
|
2011-07-12 05:49:14 +00:00
|
|
|
$expectedModels = array(
|
2011-07-14 22:08:02 +00:00
|
|
|
'ControllerAlias' => array('plugin' => null, 'className' => 'ControllerAlias'),
|
2011-07-23 18:49:39 +00:00
|
|
|
'ControllerComment' => array('plugin' => 'TestPlugin', 'className' => 'ControllerComment'),
|
2011-07-14 22:08:02 +00:00
|
|
|
'ControllerPost' => array('plugin' => null, 'className' => 'ControllerPost')
|
2011-07-12 05:49:14 +00:00
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expectedModels, $Controller->request->params['models']);
|
2011-07-12 05:49:14 +00:00
|
|
|
|
2008-08-01 11:27:53 +00:00
|
|
|
ClassRegistry::flush();
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testComponentBeforeRenderChangingViewClass() {
|
2010-07-16 01:52:24 +00:00
|
|
|
App::build(array(
|
2011-03-22 05:16:51 +00:00
|
|
|
'View' => array(
|
2012-03-12 02:20:25 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
|
2010-07-19 01:28:52 +00:00
|
|
|
)
|
2010-07-16 01:52:24 +00:00
|
|
|
), true);
|
2011-07-03 18:51:58 +00:00
|
|
|
$Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
|
2010-07-16 01:52:24 +00:00
|
|
|
$Controller->uses = array();
|
|
|
|
$Controller->components = array('Test');
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$Controller->Test->viewclass = 'Theme';
|
2011-05-16 21:36:55 +00:00
|
|
|
$Controller->viewPath = 'Posts';
|
2011-05-15 04:44:41 +00:00
|
|
|
$Controller->theme = 'TestTheme';
|
2010-07-16 01:52:24 +00:00
|
|
|
$result = $Controller->render('index');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/default test_theme layout/', (string)$result);
|
2010-07-16 01:52:24 +00:00
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2012-01-19 04:33:36 +00:00
|
|
|
/**
|
|
|
|
* test that a component beforeRender can change the controller view class.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testComponentCancelRender() {
|
|
|
|
$Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
|
|
|
|
$Controller->uses = array();
|
|
|
|
$Controller->components = array('Test2');
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$result = $Controller->render('index');
|
|
|
|
$this->assertInstanceOf('CakeResponse', $result);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testToBeInheritedGuardmethods() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
2011-07-03 18:51:58 +00:00
|
|
|
$Controller = new Controller($request, $this->getMock('CakeResponse'));
|
2011-08-22 03:18:55 +00:00
|
|
|
$this->assertTrue($Controller->beforeScaffold(''));
|
|
|
|
$this->assertTrue($Controller->afterScaffoldSave(''));
|
|
|
|
$this->assertTrue($Controller->afterScaffoldSaveError(''));
|
|
|
|
$this->assertFalse($Controller->scaffoldError(''));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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"),
|
2012-05-04 14:58:51 +00:00
|
|
|
array(307, "Temporary Redirect"),
|
|
|
|
array(403, "Forbidden"),
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRedirectTriggeringComponentsReturnNull() {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-26 03:47:08 +00:00
|
|
|
* test that beforeRedirect callback returning null doesn't affect things.
|
2010-06-12 23:01:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRedirectBeforeRedirectModifyingParams() {
|
2010-08-22 16:31:55 +00:00
|
|
|
$Controller = new Controller(null);
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
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
|
|
|
/**
|
2011-12-26 03:47:08 +00:00
|
|
|
* test that beforeRedirect callback returning null doesn't affect things.
|
2010-08-12 02:47:54 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRedirectBeforeRedirectModifyingParamsArrayReturn() {
|
2010-08-12 02:47:54 +00:00
|
|
|
$Controller = $this->getMock('Controller', array('header', '_stop'));
|
2010-08-28 04:01:41 +00:00
|
|
|
$Controller->response = $this->getMock('CakeResponse');
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
2010-08-12 02:47:54 +00:00
|
|
|
|
|
|
|
$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));
|
|
|
|
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->response->expects($this->once())->method('header')
|
2010-08-28 04:29:50 +00:00
|
|
|
->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);
|
|
|
|
}
|
|
|
|
|
2011-01-20 00:46:31 +00:00
|
|
|
/**
|
2011-12-26 03:47:08 +00:00
|
|
|
* test that beforeRedirect callback returning false in controller
|
2011-01-20 00:46:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRedirectBeforeRedirectInController() {
|
2011-01-20 00:46:31 +00:00
|
|
|
$Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header'));
|
2011-12-26 03:18:27 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
2011-01-20 00:46:31 +00:00
|
|
|
|
|
|
|
$Controller->expects($this->once())->method('beforeRedirect')
|
2011-12-26 03:47:08 +00:00
|
|
|
->with('http://cakephp.org')
|
2011-01-20 00:46:31 +00:00
|
|
|
->will($this->returnValue(false));
|
|
|
|
$Controller->response->expects($this->never())->method('header');
|
|
|
|
$Controller->expects($this->never())->method('_stop');
|
|
|
|
$Controller->redirect('http://cakephp.org');
|
|
|
|
}
|
|
|
|
|
2012-06-24 15:59:18 +00:00
|
|
|
/**
|
|
|
|
* Test that beforeRedirect works with returning an array from the controller method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectBeforeRedirectInControllerWithArray() {
|
|
|
|
$Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
|
|
|
|
$Controller->response = $this->getMock('CakeResponse', array('header'));
|
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
|
|
|
|
|
|
|
$Controller->expects($this->once())
|
|
|
|
->method('beforeRedirect')
|
|
|
|
->with('http://cakephp.org', null, true)
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
'url' => 'http://example.org',
|
|
|
|
'status' => 302,
|
|
|
|
'exit' => true
|
|
|
|
)));
|
|
|
|
|
|
|
|
$Controller->response->expects($this->at(0))
|
|
|
|
->method('header')
|
|
|
|
->with('Location', 'http://example.org');
|
|
|
|
|
|
|
|
$Controller->expects($this->once())->method('_stop');
|
|
|
|
$Controller->redirect('http://cakephp.org');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(0, count(array_diff_key($TestController->helpers, array_flip($helpers))));
|
|
|
|
$this->assertEquals(0, count(array_diff($TestController->uses, $uses)));
|
2012-03-11 01:57:18 +00:00
|
|
|
$this->assertEquals(count(array_diff_assoc(Hash::normalize($TestController->components), Hash::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-06-29 03:41:48 +00:00
|
|
|
|
2010-05-08 04:00:19 +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']));
|
2012-02-29 00:35:06 +00:00
|
|
|
$this->assertFalse($testVars['uses']);
|
2008-10-09 17:03:44 +00:00
|
|
|
|
2011-04-27 04:14:32 +00:00
|
|
|
$this->assertFalse(property_exists($TestController, 'ControllerPost'));
|
2008-10-09 17:03:44 +00:00
|
|
|
|
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']));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array('ControllerPost'), $testVars['uses']);
|
2008-10-09 17:03:44 +00:00
|
|
|
|
|
|
|
$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.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $TestController->components['Cookie']);
|
2009-04-28 01:32:20 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-02-12 13:36:20 +00:00
|
|
|
/**
|
2011-08-20 05:39:30 +00:00
|
|
|
* Ensure that _mergeControllerVars 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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/posts/index', $result);
|
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);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/posts/index', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-29 03:41:48 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
2011-02-12 20:54:39 +00:00
|
|
|
|
2010-06-29 03:41:48 +00:00
|
|
|
$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();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('http://localhost/posts/index', $result);
|
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();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetAction() {
|
2010-05-08 04:00:19 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
|
|
|
|
$TestController = new TestController($request);
|
2012-01-15 20:00:30 +00:00
|
|
|
$TestController->setAction('view', 1, 2);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('testId' => 1, 'test2Id' => 2);
|
2011-11-04 00:13:22 +00:00
|
|
|
$this->assertSame($expected, $TestController->request->data);
|
2012-01-15 20:00:30 +00:00
|
|
|
$this->assertSame('view', $TestController->request->params['action']);
|
2012-01-15 20:16:49 +00:00
|
|
|
$this->assertSame('view', $TestController->view);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testValidateErrors() {
|
2011-07-12 05:49:14 +00:00
|
|
|
ClassRegistry::flush();
|
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());
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(0, $TestController->validate());
|
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);
|
2011-04-22 21:46:38 +00:00
|
|
|
$expected = array('some_field' => array('error_message'), 'some_field2' => array('error_message2'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(2, $TestController->validate($comment));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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);
|
|
|
|
|
2011-04-22 21:46:38 +00:00
|
|
|
$expected = array('title' => array('This field cannot be left blank'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-06-21 01:47:34 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-12-13 22:48:01 +00:00
|
|
|
/**
|
|
|
|
* testControllerHttpCodes method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testControllerHttpCodes() {
|
2011-07-03 18:51:58 +00:00
|
|
|
$response = $this->getMock('CakeResponse', array('httpCodes'));
|
|
|
|
$Controller = new Controller(null, $response);
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStartupProcess() {
|
2011-12-25 01:30:39 +00:00
|
|
|
$Controller = $this->getMock('Controller', array('getEventManager'));
|
|
|
|
|
|
|
|
$eventManager = $this->getMock('CakeEventManager');
|
2011-12-26 02:22:12 +00:00
|
|
|
$eventManager->expects($this->at(0))->method('dispatch')
|
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'Controller.initialize'),
|
|
|
|
$this->attributeEqualTo('_subject', $Controller)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$eventManager->expects($this->at(1))->method('dispatch')
|
2011-12-25 01:30:39 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'Controller.startup'),
|
|
|
|
$this->attributeEqualTo('_subject', $Controller)
|
|
|
|
)
|
|
|
|
);
|
2011-12-26 02:22:12 +00:00
|
|
|
$Controller->expects($this->exactly(2))->method('getEventManager')
|
2011-12-25 01:30:39 +00:00
|
|
|
->will($this->returnValue($eventManager));
|
|
|
|
$Controller->startupProcess();
|
|
|
|
}
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2011-12-25 01:30:39 +00:00
|
|
|
/**
|
|
|
|
* Tests that the shutdown process calls the correct functions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testStartupProcessIndirect() {
|
|
|
|
$Controller = $this->getMock('Controller', array('beforeFilter'));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
2011-12-25 01:30:39 +00:00
|
|
|
$Controller->components = array('MockShutdown');
|
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
2010-07-05 00:49:47 +00:00
|
|
|
|
2011-12-25 01:30:39 +00:00
|
|
|
$Controller->expects($this->once())->method('beforeFilter');
|
|
|
|
$Controller->Components->expects($this->exactly(2))->method('trigger')->with($this->isInstanceOf('CakeEvent'));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->startupProcess();
|
2010-02-28 17:25:35 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-02-28 17:25:35 +00:00
|
|
|
/**
|
|
|
|
* Tests that the shutdown process calls the correct functions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testShutdownProcess() {
|
2011-12-25 01:30:39 +00:00
|
|
|
$Controller = $this->getMock('Controller', array('getEventManager'));
|
|
|
|
|
|
|
|
$eventManager = $this->getMock('CakeEventManager');
|
|
|
|
$eventManager->expects($this->once())->method('dispatch')
|
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'Controller.shutdown'),
|
|
|
|
$this->attributeEqualTo('_subject', $Controller)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$Controller->expects($this->once())->method('getEventManager')
|
|
|
|
->will($this->returnValue($eventManager));
|
|
|
|
$Controller->shutdownProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the shutdown process calls the correct functions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testShutdownProcessIndirect() {
|
|
|
|
$Controller = $this->getMock('Controller', array('afterFilter'));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->components = array('MockShutdown');
|
2011-12-25 01:30:39 +00:00
|
|
|
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
2010-06-12 23:01:51 +00:00
|
|
|
|
|
|
|
$Controller->expects($this->once())->method('afterFilter');
|
2011-12-25 01:30:39 +00:00
|
|
|
$Controller->Components->expects($this->exactly(1))->method('trigger')->with($this->isInstanceOf('CakeEvent'));
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPropertyBackwardsCompatibility() {
|
2012-12-28 20:54:00 +00:00
|
|
|
$request = new CakeRequest('posts/index', false);
|
2010-09-11 03:15:32 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPropertyCompatibilityAndModelsComponents() {
|
2010-09-11 03:15:32 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPaginateBackwardsCompatibility() {
|
2010-12-15 02:21:39 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
|
|
|
$request->params['pass'] = $request->params['named'] = array();
|
2011-07-03 18:51:58 +00:00
|
|
|
$response = $this->getMock('CakeResponse', array('httpCodes'));
|
2010-12-15 02:21:39 +00:00
|
|
|
|
2011-07-03 18:51:58 +00:00
|
|
|
$Controller = new Controller($request, $response);
|
2010-12-15 02:21:39 +00:00
|
|
|
$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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $Controller->paginate);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$results = Hash::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(1, 2, 3), $results);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
$Controller->passedArgs = array();
|
2012-11-28 14:01:41 +00:00
|
|
|
$Controller->paginate = array('limit' => '1');
|
|
|
|
$this->assertEquals(array('limit' => '1'), $Controller->paginate);
|
2010-12-15 02:21:39 +00:00
|
|
|
$Controller->paginate('ControllerPost');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($Controller->params['paging']['ControllerPost']['page'], 1);
|
|
|
|
$this->assertSame($Controller->params['paging']['ControllerPost']['pageCount'], 3);
|
|
|
|
$this->assertSame($Controller->params['paging']['ControllerPost']['prevPage'], false);
|
|
|
|
$this->assertSame($Controller->params['paging']['ControllerPost']['nextPage'], true);
|
2010-12-15 02:21:39 +00:00
|
|
|
}
|
2011-07-10 14:52:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testMissingAction method
|
|
|
|
*
|
|
|
|
* @expectedException MissingActionException
|
|
|
|
* @expectedExceptionMessage Action TestController::missing() could not be found.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionMissingAction() {
|
|
|
|
$url = new CakeRequest('test/missing');
|
|
|
|
$url->addParams(array('controller' => 'test_controller', 'action' => 'missing'));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$Controller->invokeAction($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test invoking private methods.
|
|
|
|
*
|
|
|
|
* @expectedException PrivateActionException
|
|
|
|
* @expectedExceptionMessage Private Action TestController::private_m() is not directly accessible.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionPrivate() {
|
|
|
|
$url = new CakeRequest('test/private_m/');
|
|
|
|
$url->addParams(array('controller' => 'test_controller', 'action' => 'private_m'));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$Controller->invokeAction($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test invoking protected methods.
|
|
|
|
*
|
|
|
|
* @expectedException PrivateActionException
|
|
|
|
* @expectedExceptionMessage Private Action TestController::protected_m() is not directly accessible.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionProtected() {
|
|
|
|
$url = new CakeRequest('test/protected_m/');
|
|
|
|
$url->addParams(array('controller' => 'test_controller', 'action' => 'protected_m'));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$Controller->invokeAction($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test invoking hidden methods.
|
|
|
|
*
|
|
|
|
* @expectedException PrivateActionException
|
|
|
|
* @expectedExceptionMessage Private Action TestController::_hidden() is not directly accessible.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionHidden() {
|
|
|
|
$url = new CakeRequest('test/_hidden/');
|
|
|
|
$url->addParams(array('controller' => 'test_controller', 'action' => '_hidden'));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$Controller->invokeAction($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test invoking controller methods.
|
|
|
|
*
|
|
|
|
* @expectedException PrivateActionException
|
|
|
|
* @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionBaseMethods() {
|
|
|
|
$url = new CakeRequest('test/redirect/');
|
|
|
|
$url->addParams(array('controller' => 'test_controller', 'action' => 'redirect'));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$Controller->invokeAction($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test invoking controller methods.
|
|
|
|
*
|
|
|
|
* @expectedException PrivateActionException
|
|
|
|
* @expectedExceptionMessage Private Action TestController::admin_add() is not directly accessible.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionPrefixProtection() {
|
|
|
|
Router::reload();
|
2011-12-01 07:21:31 +00:00
|
|
|
Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin'));
|
2011-07-10 14:52:54 +00:00
|
|
|
|
|
|
|
$url = new CakeRequest('test/admin_add/');
|
|
|
|
$url->addParams(array('controller' => 'test_controller', 'action' => 'admin_add'));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$Controller->invokeAction($url);
|
|
|
|
}
|
2011-07-10 15:02:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test invoking controller methods.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvokeActionReturnValue() {
|
|
|
|
$url = new CakeRequest('test/returner/');
|
|
|
|
$url->addParams(array(
|
|
|
|
'controller' => 'test_controller',
|
|
|
|
'action' => 'returner',
|
|
|
|
'pass' => array()
|
|
|
|
));
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$Controller = new TestController($url, $response);
|
|
|
|
$result = $Controller->invokeAction($url);
|
|
|
|
$this->assertEquals('I am from the controller.', $result);
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|