2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ObjectTest 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
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
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
|
|
|
*
|
2010-10-03 16:31:21 +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
|
2010-10-03 16:31:21 +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)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
|
|
|
|
App::uses('Object', 'Core');
|
2011-05-10 05:16:24 +00:00
|
|
|
App::uses('Router', 'Routing');
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('Model', 'Model');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-09-07 13:43:39 +00:00
|
|
|
* RequestActionPost class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-09-07 13:43:39 +00:00
|
|
|
class RequestActionPost extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-09-07 13:43:39 +00:00
|
|
|
* useTable property
|
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-09-07 13:43:39 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'posts';
|
2008-09-07 13:43:39 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
|
|
|
* RequestActionController class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-09-07 13:43:39 +00:00
|
|
|
*/
|
|
|
|
class RequestActionController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
2012-03-13 01:17:50 +00:00
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array('RequestActionPost');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
2012-03-13 01:17:50 +00:00
|
|
|
* test_request_action method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function test_request_action() {
|
2008-09-07 13:43:39 +00:00
|
|
|
return 'This is a test';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
2012-03-13 01:17:50 +00:00
|
|
|
* another_ra_test method
|
|
|
|
*
|
|
|
|
* @param mixed $id
|
|
|
|
* @param mixed $other
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function another_ra_test($id, $other) {
|
2008-09-07 13:43:39 +00:00
|
|
|
return $id + $other;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
|
|
|
* normal_request_action method
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function normal_request_action() {
|
2008-09-07 13:43:39 +00:00
|
|
|
return 'Hello World';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-08-05 03:16:26 +00:00
|
|
|
/**
|
|
|
|
* returns $this->here
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function return_here() {
|
2010-08-05 03:16:26 +00:00
|
|
|
return $this->here;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
|
|
|
* paginate_request_action method
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function paginate_request_action() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->paginate();
|
2008-09-07 13:43:39 +00:00
|
|
|
return true;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-21 02:04:42 +00:00
|
|
|
/**
|
|
|
|
* post pass, testing post passing
|
|
|
|
*
|
2008-10-22 17:12:30 +00:00
|
|
|
* @return array
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function post_pass() {
|
2011-11-13 14:44:48 +00:00
|
|
|
return $this->request->data;
|
2008-10-21 02:04:42 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-22 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* test param passing and parsing.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function params_pass() {
|
2011-10-06 00:55:17 +00:00
|
|
|
return $this->request;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function param_check() {
|
|
|
|
$this->autoRender = false;
|
|
|
|
$content = '';
|
|
|
|
if (isset($this->request->params[0])) {
|
|
|
|
$content = 'return found';
|
|
|
|
}
|
|
|
|
$this->response->body($content);
|
2008-10-22 17:12:30 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-03-13 01:17:50 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestObject class
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestObject extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* firstName property
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $firstName = 'Joel';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* lastName property
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $lastName = 'Moss';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* methodCalls property
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $methodCalls = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* emptyMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function emptyMethod() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->methodCalls[] = 'emptyMethod';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* oneParamMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function oneParamMethod($param) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->methodCalls[] = array('oneParamMethod' => array($param));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* twoParamMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2012-03-13 01:17:50 +00:00
|
|
|
* @param mixed $paramTwo
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-13 01:17:50 +00:00
|
|
|
public function twoParamMethod($param, $paramTwo) {
|
|
|
|
$this->methodCalls[] = array('twoParamMethod' => array($param, $paramTwo));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* threeParamMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2012-03-13 01:17:50 +00:00
|
|
|
* @param mixed $paramTwo
|
|
|
|
* @param mixed $paramThree
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-13 01:17:50 +00:00
|
|
|
public function threeParamMethod($param, $paramTwo, $paramThree) {
|
|
|
|
$this->methodCalls[] = array('threeParamMethod' => array($param, $paramTwo, $paramThree));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-13 01:17:50 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* fourParamMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2012-03-13 01:17:50 +00:00
|
|
|
* @param mixed $paramTwo
|
|
|
|
* @param mixed $paramThree
|
|
|
|
* @param mixed $paramFour
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-13 01:17:50 +00:00
|
|
|
public function fourParamMethod($param, $paramTwo, $paramThree, $paramFour) {
|
|
|
|
$this->methodCalls[] = array('fourParamMethod' => array($param, $paramTwo, $paramThree, $paramFour));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-13 01:17:50 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* fiveParamMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2012-03-13 01:17:50 +00:00
|
|
|
* @param mixed $paramTwo
|
|
|
|
* @param mixed $paramThree
|
|
|
|
* @param mixed $paramFour
|
|
|
|
* @param mixed $paramFive
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-13 01:17:50 +00:00
|
|
|
public function fiveParamMethod($param, $paramTwo, $paramThree, $paramFour, $paramFive) {
|
|
|
|
$this->methodCalls[] = array('fiveParamMethod' => array($param, $paramTwo, $paramThree, $paramFour, $paramFive));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* crazyMethod method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2012-03-13 01:17:50 +00:00
|
|
|
* @param mixed $paramTwo
|
|
|
|
* @param mixed $paramThree
|
|
|
|
* @param mixed $paramFour
|
|
|
|
* @param mixed $paramFive
|
|
|
|
* @param mixed $paramSix
|
|
|
|
* @param mixed $paramSeven
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-13 01:17:50 +00:00
|
|
|
public function crazyMethod($param, $paramTwo, $paramThree, $paramFour, $paramFive, $paramSix, $paramSeven = null) {
|
|
|
|
$this->methodCalls[] = array('crazyMethod' => array($param, $paramTwo, $paramThree, $paramFour, $paramFive, $paramSix, $paramSeven));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* methodWithOptionalParam method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $param
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function methodWithOptionalParam($param = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->methodCalls[] = array('methodWithOptionalParam' => array($param));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-22 15:28:22 +00:00
|
|
|
/**
|
|
|
|
* undocumented function
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function set($properties = array()) {
|
|
|
|
return parent::_set($properties);
|
|
|
|
}
|
2012-03-13 01:17:50 +00:00
|
|
|
|
2008-07-09 03:15:01 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-09 03:15:01 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ObjectTestModel class
|
2008-07-09 03:15:01 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-07-09 03:15:01 +00:00
|
|
|
*/
|
|
|
|
class ObjectTestModel extends CakeTestModel {
|
2012-03-13 01:17:50 +00:00
|
|
|
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2012-03-13 01:17:50 +00:00
|
|
|
|
2008-05-30 11:40:08 +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
|
|
|
* Object Test class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class ObjectTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-07 13:43:39 +00:00
|
|
|
/**
|
|
|
|
* fixtures
|
|
|
|
*
|
|
|
|
* @var string
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.post', 'core.test_plugin_comment', 'core.comment');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->object = new TestObject();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::tearDown();
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::unload();
|
|
|
|
unset($this->object);
|
2009-06-11 16:13:16 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLog method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLog() {
|
2011-05-28 21:08:22 +00:00
|
|
|
if (file_exists(LOGS . 'error.log')) {
|
|
|
|
unlink(LOGS . 'error.log');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($this->object->log('Test warning 1'));
|
|
|
|
$this->assertTrue($this->object->log(array('Test' => 'warning 2')));
|
|
|
|
$result = file(LOGS . 'error.log');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]);
|
|
|
|
$this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]);
|
|
|
|
$this->assertRegExp('/^\($/', $result[2]);
|
|
|
|
$this->assertRegExp('/\[Test\] => warning 2$/', $result[3]);
|
|
|
|
$this->assertRegExp('/^\)$/', $result[4]);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink(LOGS . 'error.log');
|
|
|
|
|
2008-06-20 20:17:23 +00:00
|
|
|
$this->assertTrue($this->object->log('Test warning 1', LOG_WARNING));
|
|
|
|
$this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = file(LOGS . 'error.log');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]);
|
|
|
|
$this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Array$/', $result[1]);
|
|
|
|
$this->assertRegExp('/^\($/', $result[2]);
|
|
|
|
$this->assertRegExp('/\[Test\] => warning 2$/', $result[3]);
|
|
|
|
$this->assertRegExp('/^\)$/', $result[4]);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink(LOGS . 'error.log');
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSet method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSet() {
|
2010-05-22 15:28:22 +00:00
|
|
|
$this->object->set('a string');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Joel', $this->object->firstName);
|
2008-06-20 20:17:23 +00:00
|
|
|
|
2010-05-22 15:28:22 +00:00
|
|
|
$this->object->set(array('firstName'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Joel', $this->object->firstName);
|
2008-06-20 20:17:23 +00:00
|
|
|
|
2010-05-22 15:28:22 +00:00
|
|
|
$this->object->set(array('firstName' => 'Ashley'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Ashley', $this->object->firstName);
|
2008-06-20 20:17:23 +00:00
|
|
|
|
2010-05-22 15:28:22 +00:00
|
|
|
$this->object->set(array('firstName' => 'Joel', 'lastName' => 'Moose'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Joel', $this->object->firstName);
|
|
|
|
$this->assertEquals('Moose', $this->object->lastName);
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testToString method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testToString() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = strtolower($this->object->toString());
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('testobject', $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
|
|
|
/**
|
|
|
|
* testMethodDispatching method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMethodDispatching() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->object->emptyMethod();
|
|
|
|
$expected = array('emptyMethod');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->oneParamMethod('Hello');
|
|
|
|
$expected[] = array('oneParamMethod' => array('Hello'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->twoParamMethod(true, false);
|
|
|
|
$expected[] = array('twoParamMethod' => array(true, false));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->threeParamMethod(true, false, null);
|
|
|
|
$expected[] = array('threeParamMethod' => array(true, false, null));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->crazyMethod(1, 2, 3, 4, 5, 6, 7);
|
|
|
|
$expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object = new TestObject();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, array());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('emptyMethod');
|
|
|
|
$expected = array('emptyMethod');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('oneParamMethod', array('Hello'));
|
|
|
|
$expected[] = array('oneParamMethod' => array('Hello'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('twoParamMethod', array(true, false));
|
|
|
|
$expected[] = array('twoParamMethod' => array(true, false));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('threeParamMethod', array(true, false, null));
|
|
|
|
$expected[] = array('threeParamMethod' => array(true, false, null));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4));
|
|
|
|
$expected[] = array('fourParamMethod' => array(1, 2, 3, 4));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5));
|
|
|
|
$expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('crazyMethod', array(1, 2, 3, 4, 5, 6, 7));
|
|
|
|
$expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('methodWithOptionalParam', array('Hello'));
|
|
|
|
$expected[] = array('methodWithOptionalParam' => array("Hello"));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->object->dispatchMethod('methodWithOptionalParam');
|
|
|
|
$expected[] = array('methodWithOptionalParam' => array(null));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->object->methodCalls, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRequestAction method
|
2008-09-07 13:43:39 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestAction() {
|
2010-08-05 03:16:26 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
|
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
|
|
|
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2011-08-13 01:21:05 +00:00
|
|
|
$this->assertNull(Router::getRequest(), 'request stack should be empty.');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->object->requestAction('');
|
|
|
|
$this->assertFalse($result);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->object->requestAction('/request_action/test_request_action');
|
|
|
|
$expected = 'This is a test';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-05-30 14:07:26 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
Configure::read('App.fullBaseURL') . '/request_action/test_request_action'
|
|
|
|
);
|
2012-03-24 22:10:52 +00:00
|
|
|
$expected = 'This is a test';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->object->requestAction('/request_action/another_ra_test/2/5');
|
|
|
|
$expected = 7;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->object->requestAction('/tests_apps/index', array('return'));
|
2011-10-22 16:53:10 +00:00
|
|
|
$expected = 'This is the TestsAppsController index view ';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->object->requestAction('/tests_apps/some_method');
|
|
|
|
$expected = 5;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 03:16:26 +00:00
|
|
|
$result = $this->object->requestAction('/request_action/paginate_request_action');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->object->requestAction('/request_action/normal_request_action');
|
|
|
|
$expected = 'Hello World';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-08-13 01:21:05 +00:00
|
|
|
|
|
|
|
$this->assertNull(Router::getRequest(), 'requests were not popped off the stack, this will break url generation');
|
2010-08-05 03:16:26 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 03:16:26 +00:00
|
|
|
/**
|
|
|
|
* test requestAction() and plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestActionPlugins() {
|
2010-08-05 03:16:26 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2011-11-13 02:40:51 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2010-08-05 03:16:26 +00:00
|
|
|
Router::reload();
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2008-07-31 00:16:16 +00:00
|
|
|
$result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
|
|
|
|
$expected = 'test plugin index';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-07-31 00:16:16 +00:00
|
|
|
$result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return'));
|
|
|
|
$expected = 'test plugin index';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return')
|
|
|
|
);
|
2008-07-31 00:16:16 +00:00
|
|
|
$expected = 'test plugin index';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-07-31 00:16:16 +00:00
|
|
|
$result = $this->object->requestAction('/test_plugin/tests/some_method');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = 25;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = 25;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-08-05 03:16:26 +00:00
|
|
|
}
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2010-08-05 03:16:26 +00:00
|
|
|
/**
|
|
|
|
* test requestAction() with arrays.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestActionArray() {
|
2010-08-05 03:16:26 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
|
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
|
|
|
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
|
2012-03-13 01:17:50 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2011-05-10 05:16:24 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'test_request_action')
|
|
|
|
);
|
2010-08-05 03:16:26 +00:00
|
|
|
$expected = 'This is a test';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
2011-04-17 10:35:21 +00:00
|
|
|
array('controller' => 'request_action', 'action' => 'another_ra_test'),
|
2010-08-05 03:18:33 +00:00
|
|
|
array('pass' => array('5', '7'))
|
|
|
|
);
|
2010-08-05 03:16:26 +00:00
|
|
|
$expected = 12;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'tests_apps', 'action' => 'index'), array('return')
|
|
|
|
);
|
2011-10-22 16:53:10 +00:00
|
|
|
$expected = 'This is the TestsAppsController index view ';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2010-08-05 03:16:26 +00:00
|
|
|
$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
|
|
|
|
$expected = 5;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-08-05 03:16:26 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'normal_request_action')
|
|
|
|
);
|
2008-09-07 13:43:39 +00:00
|
|
|
$expected = 'Hello World';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-09-07 13:43:39 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'paginate_request_action')
|
|
|
|
);
|
2008-09-07 13:43:39 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'paginate_request_action'),
|
|
|
|
array('pass' => array(5), 'named' => array('param' => 'value'))
|
|
|
|
);
|
2009-02-25 01:36:13 +00:00
|
|
|
$this->assertTrue($result);
|
2008-07-09 03:15:01 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-10-06 00:55:17 +00:00
|
|
|
/**
|
|
|
|
* Test that requestAction() does not forward the 0 => return value.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequestActionRemoveReturnParam() {
|
|
|
|
$result = $this->object->requestAction(
|
|
|
|
'/request_action/param_check', array('return')
|
|
|
|
);
|
|
|
|
$this->assertEquals('', $result, 'Return key was found');
|
|
|
|
}
|
|
|
|
|
2008-10-22 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* Test that requestAction() is populating $this->params properly
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestActionParamParseAndPass() {
|
2008-10-22 17:12:30 +00:00
|
|
|
$result = $this->object->requestAction('/request_action/params_pass');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('request_action/params_pass', $result->url);
|
|
|
|
$this->assertEquals('request_action', $result['controller']);
|
|
|
|
$this->assertEquals('params_pass', $result['action']);
|
|
|
|
$this->assertEquals(null, $result['plugin']);
|
2009-02-25 01:36:13 +00:00
|
|
|
|
2009-01-07 20:16:52 +00:00
|
|
|
$result = $this->object->requestAction('/request_action/params_pass/sort:desc/limit:5');
|
|
|
|
$expected = array('sort' => 'desc', 'limit' => 5,);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $result['named']);
|
2009-02-25 01:36:13 +00:00
|
|
|
|
2010-08-05 03:18:33 +00:00
|
|
|
$result = $this->object->requestAction(
|
2011-04-17 10:35:21 +00:00
|
|
|
array('controller' => 'request_action', 'action' => 'params_pass'),
|
2010-08-05 03:18:33 +00:00
|
|
|
array('named' => array('sort' => 'desc', 'limit' => 5))
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $result['named']);
|
2008-10-22 17:12:30 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-11-02 20:46:36 +00:00
|
|
|
/**
|
|
|
|
* Test that requestAction handles get parameters correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequestActionGetParameters() {
|
|
|
|
$result = $this->object->requestAction(
|
|
|
|
'/request_action/params_pass?get=value&limit=5'
|
|
|
|
);
|
|
|
|
$this->assertEquals('value', $result->query['get']);
|
|
|
|
|
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'params_pass'),
|
|
|
|
array('url' => array('get' => 'value', 'limit' => 5))
|
|
|
|
);
|
|
|
|
$this->assertEquals('value', $result->query['get']);
|
|
|
|
}
|
|
|
|
|
2008-10-21 02:04:42 +00:00
|
|
|
/**
|
2011-11-13 14:44:48 +00:00
|
|
|
* test that requestAction does not fish data out of the POST
|
|
|
|
* superglobal.
|
2008-10-21 02:04:42 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-11-13 14:44:48 +00:00
|
|
|
public function testRequestActionNoPostPassing() {
|
2008-10-21 02:04:42 +00:00
|
|
|
$_tmp = $_POST;
|
2008-10-22 17:12:30 +00:00
|
|
|
|
2008-10-21 02:04:42 +00:00
|
|
|
$_POST = array('data' => array(
|
|
|
|
'item' => 'value'
|
|
|
|
));
|
|
|
|
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
|
2010-11-14 06:01:11 +00:00
|
|
|
$this->assertEmpty($result);
|
2008-10-22 17:12:30 +00:00
|
|
|
|
2010-11-14 06:01:11 +00:00
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'post_pass'),
|
|
|
|
array('data' => $_POST['data'])
|
|
|
|
);
|
2008-10-21 02:04:42 +00:00
|
|
|
$expected = $_POST['data'];
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-22 17:12:30 +00:00
|
|
|
|
2008-10-21 02:04:42 +00:00
|
|
|
$result = $this->object->requestAction('/request_action/post_pass');
|
|
|
|
$expected = $_POST['data'];
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-22 17:12:30 +00:00
|
|
|
|
2008-10-21 02:04:42 +00:00
|
|
|
$_POST = $_tmp;
|
|
|
|
}
|
2011-11-13 14:44:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test requestAction with post data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequestActionPostWithData() {
|
|
|
|
$data = array(
|
|
|
|
'Post' => array('id' => 2)
|
|
|
|
);
|
|
|
|
$result = $this->object->requestAction(
|
|
|
|
array('controller' => 'request_action', 'action' => 'post_pass'),
|
|
|
|
array('data' => $data)
|
|
|
|
);
|
|
|
|
$this->assertEquals($data, $result);
|
|
|
|
|
|
|
|
$result = $this->object->requestAction(
|
|
|
|
'/request_action/post_pass',
|
|
|
|
array('data' => $data)
|
|
|
|
);
|
|
|
|
$this->assertEquals($data, $result);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|