2010-12-15 03:58:27 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ControllerTestCaseTest file
|
|
|
|
*
|
|
|
|
* Test Case for ControllerTestCase class
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc.
|
2010-12-15 03:58:27 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
|
2010-12-15 03:58:27 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.TestSuite
|
2010-12-15 03:58:27 +00:00
|
|
|
* @since CakePHP v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
2011-01-22 05:30:15 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('Model', 'Model');
|
|
|
|
App::uses('AppModel', 'Model');
|
|
|
|
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
|
|
|
|
2011-04-12 02:53:44 +00:00
|
|
|
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
|
2010-12-15 03:58:27 +00:00
|
|
|
|
2011-01-22 05:30:15 +00:00
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
/**
|
|
|
|
* AppController class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.TestSuite
|
2010-12-15 03:58:27 +00:00
|
|
|
*/
|
2011-01-22 05:30:15 +00:00
|
|
|
if (!class_exists('AppController', false)) {
|
2010-12-15 03:58:27 +00:00
|
|
|
/**
|
|
|
|
* AppController class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.TestSuite
|
2010-12-15 03:58:27 +00:00
|
|
|
*/
|
|
|
|
class AppController extends Controller {
|
|
|
|
/**
|
|
|
|
* helpers property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public $helpers = array('Html');
|
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public $uses = array('ControllerPost');
|
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public $components = array('Cookie');
|
|
|
|
}
|
|
|
|
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
|
|
|
|
define('APP_CONTROLLER_EXISTS', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PostsController class
|
|
|
|
*/
|
2010-12-15 04:27:12 +00:00
|
|
|
if (!class_exists('PostsController')) {
|
|
|
|
class PostsController extends AppController {
|
2010-12-15 03:58:27 +00:00
|
|
|
|
2010-12-15 04:27:12 +00:00
|
|
|
/**
|
|
|
|
* Components array
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $components = array(
|
|
|
|
'RequestHandler',
|
|
|
|
'Email',
|
|
|
|
'Auth'
|
|
|
|
);
|
|
|
|
}
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 02:32:51 +00:00
|
|
|
/**
|
|
|
|
* ControllerTestCaseTest controller
|
|
|
|
*/
|
|
|
|
class ControllerTestCaseTestController extends AppController {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses array
|
|
|
|
*
|
|
|
|
* @param array
|
|
|
|
*/
|
|
|
|
public $uses = array('TestPlugin.TestPluginComment');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
/**
|
|
|
|
* ControllerTestCaseTest
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.TestSuite
|
2010-12-15 03:58:27 +00:00
|
|
|
*/
|
|
|
|
class ControllerTestCaseTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fixtures property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-01-28 02:32:51 +00:00
|
|
|
public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reset environment.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-12-16 03:12:48 +00:00
|
|
|
parent::setUp();
|
2010-12-15 03:58:27 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
|
|
|
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
|
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
|
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2011-09-03 00:14:51 +00:00
|
|
|
), App::RESET);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
|
2011-08-20 13:46:01 +00:00
|
|
|
$this->Case = $this->getMockForAbstractClass('ControllerTestCase');
|
2010-12-15 03:58:27 +00:00
|
|
|
Router::reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown
|
2010-12-15 03:58:27 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-12-16 03:12:48 +00:00
|
|
|
parent::tearDown();
|
2011-05-09 03:55:32 +00:00
|
|
|
CakePlugin::unload();
|
2010-12-15 03:58:27 +00:00
|
|
|
$this->Case->controller = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that ControllerTestCase::generate() creates mock objects correctly
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGenerate() {
|
2010-12-16 04:33:00 +00:00
|
|
|
if (defined('APP_CONTROLLER_EXISTS')) {
|
|
|
|
$this->markTestSkipped('AppController exists, cannot run.');
|
|
|
|
}
|
2010-12-15 03:58:27 +00:00
|
|
|
$Posts = $this->Case->generate('Posts');
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($Posts->name, 'Posts');
|
|
|
|
$this->assertEquals($Posts->modelClass, 'Post');
|
|
|
|
$this->assertNull($Posts->response->send());
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$Posts = $this->Case->generate('Posts', array(
|
|
|
|
'methods' => array(
|
|
|
|
'render'
|
|
|
|
)
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertNull($Posts->render('index'));
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$Posts = $this->Case->generate('Posts', array(
|
|
|
|
'models' => array('Post'),
|
|
|
|
'components' => array('RequestHandler')
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
|
2010-12-16 04:33:00 +00:00
|
|
|
$this->assertInstanceOf('Post', $Posts->Post);
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertNull($Posts->Post->save(array()));
|
|
|
|
$this->assertNull($Posts->Post->find('all'));
|
|
|
|
$this->assertEquals($Posts->Post->useTable, 'posts');
|
|
|
|
$this->assertNull($Posts->RequestHandler->isAjax());
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$Posts = $this->Case->generate('Posts', array(
|
|
|
|
'models' => array(
|
|
|
|
'Post' => true
|
|
|
|
)
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertNull($Posts->Post->save(array()));
|
|
|
|
$this->assertNull($Posts->Post->find('all'));
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$Posts = $this->Case->generate('Posts', array(
|
|
|
|
'models' => array(
|
|
|
|
'Post' => array('save'),
|
|
|
|
)
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertNull($Posts->Post->save(array()));
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInternalType('array', $Posts->Post->find('all'));
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$Posts = $this->Case->generate('Posts', array(
|
|
|
|
'models' => array('Post'),
|
|
|
|
'components' => array(
|
|
|
|
'RequestHandler' => array('isPut'),
|
|
|
|
'Email' => array('send'),
|
|
|
|
'Session'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$Posts->RequestHandler->expects($this->once())
|
|
|
|
->method('isPut')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->assertTrue($Posts->RequestHandler->isPut());
|
|
|
|
|
|
|
|
$Posts->Auth->Session->expects($this->any())
|
|
|
|
->method('write')
|
|
|
|
->will($this->returnValue('written!'));
|
|
|
|
$this->assertEquals($Posts->Auth->Session->write('something'), 'written!');
|
|
|
|
}
|
|
|
|
|
2011-01-19 01:50:34 +00:00
|
|
|
/**
|
|
|
|
* Tests ControllerTestCase::generate() using classes from plugins
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGenerateWithPlugin() {
|
2011-01-19 01:50:34 +00:00
|
|
|
$Tests = $this->Case->generate('TestPlugin.Tests', array(
|
|
|
|
'models' => array(
|
|
|
|
'TestPlugin.TestPluginComment'
|
|
|
|
),
|
|
|
|
'components' => array(
|
2012-01-06 00:26:01 +00:00
|
|
|
'TestPlugin.Plugins'
|
2011-01-19 01:50:34 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
$this->assertEquals($Tests->name, 'Tests');
|
2012-01-06 00:26:01 +00:00
|
|
|
$this->assertInstanceOf('PluginsComponent', $Tests->Plugins);
|
2011-01-19 01:50:34 +00:00
|
|
|
|
|
|
|
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
|
|
|
|
$this->assertInstanceOf('TestPluginComment', $result);
|
2011-01-28 02:32:51 +00:00
|
|
|
|
|
|
|
$Tests = $this->Case->generate('ControllerTestCaseTest', array(
|
|
|
|
'models' => array(
|
|
|
|
'TestPlugin.TestPluginComment' => array('save')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('TestPluginComment', $Tests->TestPluginComment);
|
|
|
|
$Tests->TestPluginComment->expects($this->at(0))
|
|
|
|
->method('save')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$Tests->TestPluginComment->expects($this->at(1))
|
|
|
|
->method('save')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
$this->assertTrue($Tests->TestPluginComment->save(array()));
|
|
|
|
$this->assertFalse($Tests->TestPluginComment->save(array()));
|
|
|
|
|
2011-01-19 01:50:34 +00:00
|
|
|
}
|
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
/**
|
|
|
|
* Tests testAction
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTestAction() {
|
2010-12-15 03:58:27 +00:00
|
|
|
$Controller = $this->Case->generate('TestsApps');
|
|
|
|
$this->Case->testAction('/tests_apps/index');
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInternalType('array', $this->Case->controller->viewVars);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$this->Case->testAction('/tests_apps/set_action');
|
|
|
|
$results = $this->Case->controller->viewVars;
|
|
|
|
$expected = array(
|
|
|
|
'var' => 'string'
|
|
|
|
);
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($expected, $results);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
$result = $this->Case->controller->response->body();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/This is the TestsAppsController index view/', $result);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
2011-10-22 14:58:21 +00:00
|
|
|
$Controller = $this->Case->generate('TestsApps');
|
2010-12-15 03:58:27 +00:00
|
|
|
$this->Case->testAction('/tests_apps/redirect_to');
|
|
|
|
$results = $this->Case->headers;
|
|
|
|
$expected = array(
|
|
|
|
'Location' => 'http://cakephp.org'
|
|
|
|
);
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($expected, $results);
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 13:58:35 +00:00
|
|
|
/**
|
|
|
|
* Make sure testAction() can hit plugin controllers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTestActionWithPlugin() {
|
|
|
|
$Controller = $this->Case->generate('TestPlugin.Tests');
|
|
|
|
$this->Case->testAction('/test_plugin/tests/index');
|
|
|
|
$this->assertEquals('It is a variable', $this->Case->controller->viewVars['test_value']);
|
|
|
|
}
|
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
/**
|
|
|
|
* Tests using loaded routes during tests
|
2011-08-20 13:58:35 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2010-12-15 03:58:27 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUseRoutes() {
|
2011-07-18 11:33:16 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2011-04-17 10:35:21 +00:00
|
|
|
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
|
2011-07-18 11:33:16 +00:00
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
$controller = $this->Case->generate('TestsApps');
|
|
|
|
$controller->Components->load('RequestHandler');
|
2011-11-29 02:36:44 +00:00
|
|
|
$result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'contents'));
|
2010-12-15 03:58:27 +00:00
|
|
|
$result = json_decode($result, true);
|
|
|
|
$expected = array('cakephp' => 'cool');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
|
2010-12-15 03:58:27 +00:00
|
|
|
$result = $this->Case->testAction('/some_alias');
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($result, 5);
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests not using loaded routes during tests
|
2010-12-16 03:19:44 +00:00
|
|
|
*
|
|
|
|
* @expectedException MissingActionException
|
2010-12-15 03:58:27 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSkipRoutes() {
|
2011-07-18 11:33:16 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2011-04-17 10:35:21 +00:00
|
|
|
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$this->Case->loadRoutes = false;
|
2010-12-24 17:54:04 +00:00
|
|
|
$result = $this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests backwards compatibility with setting the return type
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBCSetReturn() {
|
2010-12-15 03:58:27 +00:00
|
|
|
$this->Case->autoMock = true;
|
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/some_method');
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($result, 5);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$data = array('var' => 'set');
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
|
|
|
'data' => $data,
|
|
|
|
'return' => 'vars'
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($result['data'], $data);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
|
|
|
'return' => 'view'
|
|
|
|
));
|
2011-10-22 14:58:21 +00:00
|
|
|
$this->assertEquals($result, 'This is the TestsAppsController index view string');
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
|
|
|
'return' => 'contents'
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/<html/', $result);
|
|
|
|
$this->assertRegExp('/This is the TestsAppsController index view/', $result);
|
|
|
|
$this->assertRegExp('/<\/html>/', $result);
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests sending POST data to testAction
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTestActionPostData() {
|
2010-12-15 03:58:27 +00:00
|
|
|
$this->Case->autoMock = true;
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'Post' => array(
|
|
|
|
'name' => 'Some Post'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Case->testAction('/tests_apps_posts/post_var', array(
|
|
|
|
'data' => $data
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($this->Case->controller->viewVars['data'], $data);
|
|
|
|
$this->assertEquals($this->Case->controller->data, $data);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$this->Case->testAction('/tests_apps_posts/post_var/named:param', array(
|
|
|
|
'data' => $data
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'named' => 'param'
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Case->controller->request->named, $expected);
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($this->Case->controller->data, $data);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
|
|
|
'return' => 'vars',
|
|
|
|
'method' => 'post',
|
|
|
|
'data' => array(
|
|
|
|
'name' => 'is jonas',
|
|
|
|
'pork' => 'and beans',
|
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_keys($result['data']), array('name', 'pork'));
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
|
|
|
|
$this->assertTrue(array_key_exists('posts', $result));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(count($result['posts']), 4);
|
2011-08-29 21:24:22 +00:00
|
|
|
$this->assertTrue($this->Case->controller->request->is('post'));
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests sending GET data to testAction
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTestActionGetData() {
|
2010-12-15 03:58:27 +00:00
|
|
|
$this->Case->autoMock = true;
|
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
|
|
|
|
'method' => 'get',
|
|
|
|
'data' => array(
|
|
|
|
'some' => 'var',
|
|
|
|
'lackof' => 'creativity'
|
|
|
|
)
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($this->Case->controller->request->query['some'], 'var');
|
|
|
|
$this->assertEquals($this->Case->controller->request->query['lackof'], 'creativity');
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/url_var/var1:value1/var2:val2', array(
|
|
|
|
'return' => 'vars',
|
|
|
|
'method' => 'get',
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_keys($result['params']['named']), array('var1', 'var2'));
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array(
|
|
|
|
'return' => 'vars',
|
|
|
|
'method' => 'get',
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($result['params']['pass'], array('gogo', 'val2'));
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
|
|
|
|
'return' => 'vars',
|
|
|
|
'method' => 'get',
|
|
|
|
'data' => array(
|
|
|
|
'red' => 'health',
|
|
|
|
'blue' => 'mana'
|
|
|
|
)
|
|
|
|
));
|
2011-05-09 03:55:32 +00:00
|
|
|
$query = $this->Case->controller->request->query;
|
|
|
|
$this->assertTrue(isset($query['red']));
|
|
|
|
$this->assertTrue(isset($query['blue']));
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
2011-11-12 02:26:46 +00:00
|
|
|
/**
|
|
|
|
* Test that REST actions with XML/JSON input work.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTestActionJsonData() {
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/input_data', array(
|
|
|
|
'return' => 'vars',
|
|
|
|
'method' => 'post',
|
|
|
|
'data' => '{"key":"value","json":true}'
|
|
|
|
));
|
|
|
|
$this->assertEquals('value', $result['data']['key']);
|
|
|
|
$this->assertTrue($result['data']['json']);
|
|
|
|
}
|
|
|
|
|
2010-12-15 03:58:27 +00:00
|
|
|
/**
|
|
|
|
* Tests autoMock ability
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoMock() {
|
2010-12-15 03:58:27 +00:00
|
|
|
$this->Case->autoMock = true;
|
|
|
|
$this->Case->testAction('/tests_apps/set_action');
|
|
|
|
$results = $this->Case->controller->viewVars;
|
|
|
|
$expected = array(
|
|
|
|
'var' => 'string'
|
|
|
|
);
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($expected, $results);
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test using testAction and not mocking
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNoMocking() {
|
2010-12-15 03:58:27 +00:00
|
|
|
$result = $this->Case->testAction('/tests_apps/some_method');
|
|
|
|
$this->Case->assertEquals($result, 5);
|
|
|
|
|
|
|
|
$data = array('var' => 'set');
|
|
|
|
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
|
|
|
'data' => $data,
|
|
|
|
'return' => 'vars'
|
|
|
|
));
|
2010-12-16 03:19:44 +00:00
|
|
|
$this->assertEquals($result['data'], $data);
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
|
|
|
'return' => 'view'
|
|
|
|
));
|
2011-10-22 14:58:21 +00:00
|
|
|
$this->assertEquals($result, 'This is the TestsAppsController index view string');
|
2010-12-15 03:58:27 +00:00
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/set_action', array(
|
|
|
|
'return' => 'contents'
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/<html/', $result);
|
|
|
|
$this->assertRegExp('/This is the TestsAppsController index view/', $result);
|
|
|
|
$this->assertRegExp('/<\/html>/', $result);
|
2010-12-15 03:58:27 +00:00
|
|
|
}
|
|
|
|
|
2011-10-22 14:58:21 +00:00
|
|
|
/**
|
|
|
|
* Test that controllers don't get reused.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNoControllerReuse() {
|
2011-11-05 21:27:55 +00:00
|
|
|
$this->Case->autoMock = true;
|
2011-10-22 14:58:21 +00:00
|
|
|
$result = $this->Case->testAction('/tests_apps/index', array(
|
|
|
|
'data' => array('var' => 'first call'),
|
|
|
|
'method' => 'get',
|
|
|
|
'return' => 'contents',
|
|
|
|
));
|
|
|
|
$this->assertContains('<html', $result);
|
|
|
|
$this->assertContains('This is the TestsAppsController index view', $result);
|
|
|
|
$this->assertContains('first call', $result);
|
|
|
|
$this->assertContains('</html>', $result);
|
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/index', array(
|
|
|
|
'data' => array('var' => 'second call'),
|
|
|
|
'method' => 'get',
|
|
|
|
'return' => 'contents'
|
|
|
|
));
|
|
|
|
$this->assertContains('second call', $result);
|
|
|
|
|
|
|
|
$result = $this->Case->testAction('/tests_apps/index', array(
|
|
|
|
'data' => array('var' => 'third call'),
|
|
|
|
'method' => 'get',
|
|
|
|
'return' => 'contents'
|
|
|
|
));
|
|
|
|
$this->assertContains('third call', $result);
|
|
|
|
}
|
|
|
|
|
2011-11-05 21:27:55 +00:00
|
|
|
/**
|
|
|
|
* Test that multiple calls to redirect in the same test method don't cause issues.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTestActionWithMultipleRedirect() {
|
|
|
|
$Controller = $this->Case->generate('TestsApps');
|
|
|
|
|
|
|
|
$options = array('method' => 'get');
|
|
|
|
$this->Case->testAction('/tests_apps/redirect_to', $options);
|
|
|
|
$this->Case->testAction('/tests_apps/redirect_to', $options);
|
|
|
|
}
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
}
|