a grand renaming so that the most significant portion of the name comes first
This commit is contained in:
@@ -0,0 +1,587 @@
|
||||
<?php
|
||||
/**
|
||||
* ComponentTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
* @since CakePHP(tm) v 1.2.0.5436
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Controller', 'Controller', false);
|
||||
App::import('Controller', 'Component', false);
|
||||
|
||||
if (!class_exists('AppController')) {
|
||||
|
||||
/**
|
||||
* AppController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class AppController extends Controller {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'App'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'App';
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
|
||||
/**
|
||||
* helpers property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $helpers = array();
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Orange' => array('colour' => 'blood orange'));
|
||||
}
|
||||
} elseif (!defined('APP_CONTROLLER_EXISTS')){
|
||||
define('APP_CONTROLLER_EXISTS', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* ParamTestComponent
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ParamTestComponent extends Object {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'ParamTest'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ParamTest';
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Banana' => array('config' => 'value'));
|
||||
|
||||
/**
|
||||
* initialize method
|
||||
*
|
||||
* @param mixed $controller
|
||||
* @param mixed $settings
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function initialize(&$controller, $settings) {
|
||||
foreach ($settings as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
$this->{$value} = true;
|
||||
} else {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ComponentTestController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ComponentTestController extends AppController {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'ComponentTest'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ComponentTest';
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* AppleComponent class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class AppleComponent extends Object {
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Orange');
|
||||
|
||||
/**
|
||||
* testName property
|
||||
*
|
||||
* @var mixed null
|
||||
* @access public
|
||||
*/
|
||||
var $testName = null;
|
||||
|
||||
/**
|
||||
* startup method
|
||||
*
|
||||
* @param mixed $controller
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startup(&$controller) {
|
||||
$this->testName = $controller->name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OrangeComponent class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class OrangeComponent extends Object {
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Banana');
|
||||
|
||||
/**
|
||||
* initialize method
|
||||
*
|
||||
* @param mixed $controller
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function initialize(&$controller, $settings) {
|
||||
$this->Controller = $controller;
|
||||
$this->Banana->testField = 'OrangeField';
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* startup method
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function startup(&$controller) {
|
||||
$controller->foo = 'pass';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BananaComponent class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class BananaComponent extends Object {
|
||||
|
||||
/**
|
||||
* testField property
|
||||
*
|
||||
* @var string 'BananaField'
|
||||
* @access public
|
||||
*/
|
||||
var $testField = 'BananaField';
|
||||
|
||||
/**
|
||||
* startup method
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function startup(&$controller) {
|
||||
$controller->bar = 'fail';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MutuallyReferencingOneComponent class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class MutuallyReferencingOneComponent extends Object {
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('MutuallyReferencingTwo');
|
||||
}
|
||||
|
||||
/**
|
||||
* MutuallyReferencingTwoComponent class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class MutuallyReferencingTwoComponent extends Object {
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('MutuallyReferencingOne');
|
||||
}
|
||||
|
||||
/**
|
||||
* SomethingWithEmailComponent class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class SomethingWithEmailComponent extends Object {
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Email');
|
||||
}
|
||||
|
||||
Mock::generate('Object', 'ComponentMockComponent', array('startup', 'beforeFilter', 'beforeRender', 'other'));
|
||||
|
||||
/**
|
||||
* ComponentTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ComponentTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setUp() {
|
||||
$this->_pluginPaths = App::path('plugins');
|
||||
App::build(array(
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
App::build();
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* testLoadComponents method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testLoadComponents() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('RequestHandler');
|
||||
|
||||
$Component =& new Component();
|
||||
$Component->init($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->RequestHandler, 'RequestHandlerComponent'));
|
||||
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->plugin = 'test_plugin';
|
||||
$Controller->components = array('RequestHandler', 'TestPluginComponent');
|
||||
|
||||
$Component =& new Component();
|
||||
$Component->init($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->RequestHandler, 'RequestHandlerComponent'));
|
||||
$this->assertTrue(is_a($Controller->TestPluginComponent, 'TestPluginComponentComponent'));
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->TestPluginComponent->TestPluginOtherComponent,
|
||||
'TestPluginOtherComponentComponent'
|
||||
));
|
||||
$this->assertFalse(isset($Controller->TestPluginOtherComponent));
|
||||
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('Security');
|
||||
|
||||
$Component =& new Component();
|
||||
$Component->init($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->Security, 'SecurityComponent'));
|
||||
$this->assertTrue(is_a($Controller->Security->Session, 'SessionComponent'));
|
||||
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('Security', 'Cookie', 'RequestHandler');
|
||||
|
||||
$Component =& new Component();
|
||||
$Component->init($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->Security, 'SecurityComponent'));
|
||||
$this->assertTrue(is_a($Controller->Security->RequestHandler, 'RequestHandlerComponent'));
|
||||
$this->assertTrue(is_a($Controller->RequestHandler, 'RequestHandlerComponent'));
|
||||
$this->assertTrue(is_a($Controller->Cookie, 'CookieComponent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test component loading
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testNestedComponentLoading() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('Apple');
|
||||
$Controller->uses = false;
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
|
||||
$this->assertTrue(is_a($Controller->Apple->Orange, 'OrangeComponent'));
|
||||
$this->assertTrue(is_a($Controller->Apple->Orange->Banana, 'BananaComponent'));
|
||||
$this->assertTrue(is_a($Controller->Apple->Orange->Controller, 'ComponentTestController'));
|
||||
$this->assertTrue(empty($Controller->Apple->Session));
|
||||
$this->assertTrue(empty($Controller->Apple->Orange->Session));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Component::startup() and only running callbacks for components directly attached to
|
||||
* the controller.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testComponentStartup() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('Apple');
|
||||
$Controller->uses = false;
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
$Controller->beforeFilter();
|
||||
$Controller->Component->startup($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
|
||||
$this->assertEqual($Controller->Apple->testName, 'ComponentTest');
|
||||
|
||||
$expected = !(defined('APP_CONTROLLER_EXISTS') && APP_CONTROLLER_EXISTS);
|
||||
$this->assertEqual(isset($Controller->foo), $expected);
|
||||
$this->assertFalse(isset($Controller->bar));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that triggerCallbacks fires methods on all the components, and can trigger any method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testTriggerCallback() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('ComponentMock');
|
||||
$Controller->uses = null;
|
||||
$Controller->constructClasses();
|
||||
|
||||
$Controller->ComponentMock->expectOnce('beforeRender');
|
||||
$Controller->Component->triggerCallback('beforeRender', $Controller);
|
||||
|
||||
$Controller->ComponentMock->expectNever('beforeFilter');
|
||||
$Controller->ComponentMock->enabled = false;
|
||||
$Controller->Component->triggerCallback('beforeFilter', $Controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* test a component being used more than once.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMultipleComponentInitialize() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->uses = false;
|
||||
$Controller->components = array('Orange', 'Banana');
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertEqual($Controller->Banana->testField, 'OrangeField');
|
||||
$this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Component declarations with Parameters
|
||||
* tests merging of component parameters and merging / construction of components.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testComponentsWithParams() {
|
||||
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple');
|
||||
$Controller->uses = false;
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent'));
|
||||
$this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent'));
|
||||
$this->assertTrue(is_a($Controller->Orange, 'OrangeComponent'));
|
||||
$this->assertFalse(isset($Controller->Session));
|
||||
$this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange'));
|
||||
$this->assertEqual($Controller->ParamTest->test, 'value');
|
||||
$this->assertEqual($Controller->ParamTest->flag, true);
|
||||
|
||||
//Settings are merged from app controller and current controller.
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array(
|
||||
'ParamTest' => array('test' => 'value'),
|
||||
'Orange' => array('ripeness' => 'perfect')
|
||||
);
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$expected = array('colour' => 'blood orange', 'ripeness' => 'perfect');
|
||||
$this->assertEqual($Controller->Orange->settings, $expected);
|
||||
$this->assertEqual($Controller->ParamTest->test, 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that settings are not duplicated when passed into component initialize.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testComponentParamsNoDuplication() {
|
||||
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
|
||||
return;
|
||||
}
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('Orange' => array('setting' => array('itemx')));
|
||||
$Controller->uses = false;
|
||||
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
$expected = array('setting' => array('itemx'), 'colour' => 'blood orange');
|
||||
$this->assertEqual($Controller->Orange->settings, $expected, 'Params duplication has occured %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test mutually referencing components.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMutuallyReferencingComponents() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('MutuallyReferencingOne');
|
||||
$Controller->uses = false;
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->MutuallyReferencingOne,
|
||||
'MutuallyReferencingOneComponent'
|
||||
));
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->MutuallyReferencingOne->MutuallyReferencingTwo,
|
||||
'MutuallyReferencingTwoComponent'
|
||||
));
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->MutuallyReferencingOne->MutuallyReferencingTwo->MutuallyReferencingOne,
|
||||
'MutuallyReferencingOneComponent'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test mutually referencing components.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSomethingReferencingEmailComponent() {
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('SomethingWithEmail');
|
||||
$Controller->uses = false;
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
$Controller->beforeFilter();
|
||||
$Controller->Component->startup($Controller);
|
||||
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->SomethingWithEmail,
|
||||
'SomethingWithEmailComponent'
|
||||
));
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->SomethingWithEmail->Email,
|
||||
'EmailComponent'
|
||||
));
|
||||
$this->assertTrue(is_a(
|
||||
$Controller->SomethingWithEmail->Email->Controller,
|
||||
'ComponentTestController'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that SessionComponent doesn't get added if its already in the components array.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testDoubleLoadingOfSessionComponent() {
|
||||
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$Controller =& new ComponentTestController();
|
||||
$Controller->uses = false;
|
||||
$Controller->components = array('Session');
|
||||
$Controller->constructClasses();
|
||||
|
||||
$this->assertEqual($Controller->components, array('Session' => '', 'Orange' => array('colour' => 'blood orange')));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,646 @@
|
||||
<?php
|
||||
/**
|
||||
* AclComponentTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
* @since CakePHP(tm) v 1.2.0.5435
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
||||
}
|
||||
App::import(array('controller' .DS . 'components' . DS . 'acl', 'model' . DS . 'db_acl'));
|
||||
|
||||
/**
|
||||
* AclNodeTwoTestBase class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class AclNodeTwoTestBase extends AclNode {
|
||||
|
||||
/**
|
||||
* useDbConfig property
|
||||
*
|
||||
* @var string 'test_suite'
|
||||
* @access public
|
||||
*/
|
||||
var $useDbConfig = 'test_suite';
|
||||
|
||||
/**
|
||||
* cacheSources property
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
var $cacheSources = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* AroTwoTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class AroTwoTest extends AclNodeTwoTestBase {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'AroTwoTest'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'AroTwoTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'aro_twos'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'aro_twos';
|
||||
|
||||
/**
|
||||
* hasAndBelongsToMany property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasAndBelongsToMany = array('AcoTwoTest' => array('with' => 'PermissionTwoTest'));
|
||||
}
|
||||
|
||||
/**
|
||||
* AcoTwoTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class AcoTwoTest extends AclNodeTwoTestBase {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'AcoTwoTest'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'AcoTwoTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'aco_twos'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'aco_twos';
|
||||
|
||||
/**
|
||||
* hasAndBelongsToMany property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasAndBelongsToMany = array('AroTwoTest' => array('with' => 'PermissionTwoTest'));
|
||||
}
|
||||
|
||||
/**
|
||||
* PermissionTwoTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class PermissionTwoTest extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PermissionTwoTest'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'PermissionTwoTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'aros_aco_twos'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'aros_aco_twos';
|
||||
|
||||
/**
|
||||
* cacheQueries property
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
var $cacheQueries = false;
|
||||
|
||||
/**
|
||||
* belongsTo property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
|
||||
|
||||
/**
|
||||
* actsAs property
|
||||
*
|
||||
* @var mixed null
|
||||
* @access public
|
||||
*/
|
||||
var $actsAs = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* DbAclTwoTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class DbAclTwoTest extends DbAcl {
|
||||
|
||||
/**
|
||||
* construct method
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
$this->Aro =& new AroTwoTest();
|
||||
$this->Aro->Permission =& new PermissionTwoTest();
|
||||
$this->Aco =& new AcoTwoTest();
|
||||
$this->Aro->Permission =& new PermissionTwoTest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IniAclTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class IniAclTest extends IniAcl {
|
||||
}
|
||||
|
||||
/**
|
||||
* ACL Component Text case
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class AclComponentTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Acl =& new AclComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* before method
|
||||
*
|
||||
* @param mixed $method
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function before($method) {
|
||||
Configure::write('Acl.classname', 'DbAclTwoTest');
|
||||
Configure::write('Acl.database', 'test_suite');
|
||||
parent::before($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
unset($this->Acl);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAclCreate method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAclCreate() {
|
||||
$this->Acl->Aro->create(array('alias' => 'Chotchkey'));
|
||||
$this->assertTrue($this->Acl->Aro->save());
|
||||
|
||||
$parent = $this->Acl->Aro->id;
|
||||
|
||||
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
|
||||
$this->assertTrue($this->Acl->Aro->save());
|
||||
|
||||
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
|
||||
$this->assertTrue($this->Acl->Aro->save());
|
||||
|
||||
$root = $this->Acl->Aco->node('ROOT');
|
||||
$parent = $root[0]['AcoTwoTest']['id'];
|
||||
|
||||
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
|
||||
$this->assertTrue($this->Acl->Aco->save());
|
||||
|
||||
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
|
||||
$this->assertTrue($this->Acl->Aco->save());
|
||||
}
|
||||
|
||||
/**
|
||||
* testAclCreateWithParent method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAclCreateWithParent() {
|
||||
$parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1);
|
||||
$this->Acl->Aro->create();
|
||||
$this->Acl->Aro->save(array(
|
||||
'alias' => 'Subordinate',
|
||||
'model' => 'User',
|
||||
'foreign_key' => 7,
|
||||
'parent_id' => $parent['AroTwoTest']['id']
|
||||
));
|
||||
$result = $this->Acl->Aro->findByAlias('Subordinate', null, null, -1);
|
||||
$this->assertEqual($result['AroTwoTest']['lft'], 16);
|
||||
$this->assertEqual($result['AroTwoTest']['rght'], 17);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbAclAllow method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbAclAllow() {
|
||||
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'read'));
|
||||
$this->assertTrue($this->Acl->allow('Micheal', 'tpsReports', array('read', 'delete', 'update')));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'update'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'create'));
|
||||
$this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
||||
$this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
|
||||
// Michael no longer has his delete permission for tpsReports!
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
|
||||
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
|
||||
$this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
|
||||
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
|
||||
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
|
||||
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
|
||||
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
|
||||
// Samir should still have his tpsReports/view permissions, but does not
|
||||
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
||||
|
||||
$this->expectError('DbAcl::allow() - Invalid node');
|
||||
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
||||
|
||||
$this->expectError('DbAcl::allow() - Invalid node');
|
||||
$this->assertFalse($this->Acl->allow('Homer', 'tpsReports', 'create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbAclCheck method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbAclCheck() {
|
||||
$this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
|
||||
$this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
|
||||
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
|
||||
$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
|
||||
|
||||
$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: WRONG\nAco: tpsReports");
|
||||
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
|
||||
|
||||
$this->expectError("ACO permissions key foobar does not exist in DbAcl::check()");
|
||||
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
|
||||
|
||||
$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: users\nAco: NonExistant");
|
||||
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
|
||||
|
||||
$this->assertFalse($this->Acl->check(null, 'printers', 'create'));
|
||||
$this->assertFalse($this->Acl->check('managers', null, 'read'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('Bobs', 'ROOT/tpsReports/view/current', 'read'));
|
||||
$this->assertFalse($this->Acl->check('Samir', 'ROOT/tpsReports/update', 'read'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbAclCascadingDeny function
|
||||
*
|
||||
* Setup the acl permissions such that Bobs inherits from admin.
|
||||
* deny Admin delete access to a specific resource, check the permisssions are inherited.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbAclCascadingDeny() {
|
||||
$this->Acl->inherit('Bobs', 'ROOT', '*');
|
||||
$this->assertTrue($this->Acl->check('admin', 'tpsReports', 'delete'));
|
||||
$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'delete'));
|
||||
$this->Acl->deny('admin', 'tpsReports', 'delete');
|
||||
$this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));
|
||||
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbAclDeny method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbAclDeny() {
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));
|
||||
$this->Acl->deny('Micheal', 'smash', 'delete');
|
||||
$this->assertFalse($this->Acl->check('Micheal', 'smash', 'delete'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'read'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'create'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'update'));
|
||||
$this->assertFalse($this->Acl->check('Micheal', 'smash', '*'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('Samir', 'refill', '*'));
|
||||
$this->Acl->deny('Samir', 'refill', '*');
|
||||
$this->assertFalse($this->Acl->check('Samir', 'refill', 'create'));
|
||||
$this->assertFalse($this->Acl->check('Samir', 'refill', 'update'));
|
||||
$this->assertFalse($this->Acl->check('Samir', 'refill', 'read'));
|
||||
$this->assertFalse($this->Acl->check('Samir', 'refill', 'delete'));
|
||||
|
||||
$result = $this->Acl->Aro->Permission->find('all', array('conditions' => array('AroTwoTest.alias' => 'Samir')));
|
||||
$expected = '-1';
|
||||
$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
|
||||
|
||||
$this->expectError('DbAcl::allow() - Invalid node');
|
||||
$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testAclNodeLookup method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAclNodeLookup() {
|
||||
$result = $this->Acl->Aro->node('root/users/Samir');
|
||||
$expected = array(
|
||||
array('AroTwoTest' => array('id' => '7', 'parent_id' => '4', 'model' => 'User', 'foreign_key' => 3, 'alias' => 'Samir')),
|
||||
array('AroTwoTest' => array('id' => '4', 'parent_id' => '1', 'model' => 'Group', 'foreign_key' => 3, 'alias' => 'users')),
|
||||
array('AroTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'root'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Acl->Aco->node('ROOT/tpsReports/view/current');
|
||||
$expected = array(
|
||||
array('AcoTwoTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'current')),
|
||||
array('AcoTwoTest' => array('id' => '3', 'parent_id' => '2', 'model' => null, 'foreign_key' => null, 'alias' => 'view')),
|
||||
array('AcoTwoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'tpsReports')),
|
||||
array('AcoTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT')),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbInherit method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbInherit() {
|
||||
//parent doesn't have access inherit should still deny
|
||||
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
|
||||
$this->Acl->inherit('Milton', 'smash', 'delete');
|
||||
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
|
||||
|
||||
//inherit parent
|
||||
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
|
||||
$this->Acl->inherit('Milton', 'smash', 'read');
|
||||
$this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbGrant method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbGrant() {
|
||||
$this->assertFalse($this->Acl->check('Samir', 'tpsReports', 'create'));
|
||||
$this->Acl->grant('Samir', 'tpsReports', 'create');
|
||||
$this->assertTrue($this->Acl->check('Samir', 'tpsReports', 'create'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('Micheal', 'view', 'read'));
|
||||
$this->Acl->grant('Micheal', 'view', array('read', 'create', 'update'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'view', 'read'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'view', 'create'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
|
||||
$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
|
||||
|
||||
$this->expectError('DbAcl::allow() - Invalid node');
|
||||
$this->assertFalse($this->Acl->grant('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDbRevoke method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDbRevoke() {
|
||||
$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'read'));
|
||||
$this->Acl->revoke('Bobs', 'tpsReports', 'read');
|
||||
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'read'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('users', 'printers', 'read'));
|
||||
$this->Acl->revoke('users', 'printers', 'read');
|
||||
$this->assertFalse($this->Acl->check('users', 'printers', 'read'));
|
||||
$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
|
||||
$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
|
||||
|
||||
$this->expectError('DbAcl::allow() - Invalid node');
|
||||
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testStartup method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testStartup() {
|
||||
$controller = new Controller();
|
||||
$this->assertTrue($this->Acl->startup($controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* testIniReadConfigFile
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIniReadConfigFile() {
|
||||
Configure::write('Acl.classname', 'IniAclTest');
|
||||
unset($this->Acl);
|
||||
$this->Acl = new AclComponent();
|
||||
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||
$result = $this->Acl->_Instance->readConfigFile($iniFile);
|
||||
$expected = array(
|
||||
'admin' => array(
|
||||
'groups' => 'administrators',
|
||||
'allow' => '',
|
||||
'deny' => 'ads',
|
||||
),
|
||||
'paul' => array(
|
||||
'groups' => 'users',
|
||||
'allow' =>'',
|
||||
'deny' => '',
|
||||
),
|
||||
'jenny' => array(
|
||||
'groups' => 'users',
|
||||
'allow' => 'ads',
|
||||
'deny' => 'images, files',
|
||||
),
|
||||
'nobody' => array(
|
||||
'groups' => 'anonymous',
|
||||
'allow' => '',
|
||||
'deny' => '',
|
||||
),
|
||||
'administrators' => array(
|
||||
'deny' => '',
|
||||
'allow' => 'posts, comments, images, files, stats, ads',
|
||||
),
|
||||
'users' => array(
|
||||
'allow' => 'posts, comments, images, files',
|
||||
'deny' => 'stats, ads',
|
||||
),
|
||||
'anonymous' => array(
|
||||
'allow' => '',
|
||||
'deny' => 'posts, comments, images, files, stats, ads',
|
||||
),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIniCheck method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIniCheck() {
|
||||
Configure::write('Acl.classname', 'IniAclTest');
|
||||
unset($this->Acl);
|
||||
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||
|
||||
$this->Acl = new AclComponent();
|
||||
$this->Acl->_Instance->config= $this->Acl->_Instance->readConfigFile($iniFile);
|
||||
|
||||
$this->assertFalse($this->Acl->check('admin', 'ads'));
|
||||
$this->assertTrue($this->Acl->check('admin', 'posts'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('jenny', 'posts'));
|
||||
$this->assertTrue($this->Acl->check('jenny', 'ads'));
|
||||
|
||||
$this->assertTrue($this->Acl->check('paul', 'posts'));
|
||||
$this->assertFalse($this->Acl->check('paul', 'ads'));
|
||||
|
||||
$this->assertFalse($this->Acl->check('nobody', 'comments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* debug function - to help editing/creating test cases for the ACL component
|
||||
*
|
||||
* To check the overal ACL status at any time call $this->__debug();
|
||||
* Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined
|
||||
* Only designed to work with the db based ACL
|
||||
*
|
||||
* @param bool $treesToo
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __debug ($printTreesToo = false) {
|
||||
$this->Acl->Aro->displayField = 'alias';
|
||||
$this->Acl->Aco->displayField = 'alias';
|
||||
$aros = $this->Acl->Aro->find('list', array('order' => 'lft'));
|
||||
$acos = $this->Acl->Aco->find('list', array('order' => 'lft'));
|
||||
$rights = array('*', 'create', 'read', 'update', 'delete');
|
||||
$permissions['Aros v Acos >'] = $acos;
|
||||
foreach ($aros as $aro) {
|
||||
$row = array();
|
||||
foreach ($acos as $aco) {
|
||||
$perms = '';
|
||||
foreach ($rights as $right) {
|
||||
if ($this->Acl->check($aro, $aco, $right)) {
|
||||
if ($right == '*') {
|
||||
$perms .= '****';
|
||||
break;
|
||||
}
|
||||
$perms .= $right[0];
|
||||
} elseif ($right != '*') {
|
||||
$perms .= ' ';
|
||||
}
|
||||
}
|
||||
$row[] = $perms;
|
||||
}
|
||||
$permissions[$aro] = $row;
|
||||
}
|
||||
foreach ($permissions as $key => $values) {
|
||||
array_unshift($values, $key);
|
||||
$values = array_map(array(&$this, '__pad'), $values);
|
||||
$permissions[$key] = implode (' ', $values);
|
||||
}
|
||||
$permisssions = array_map(array(&$this, '__pad'), $permissions);
|
||||
array_unshift($permissions, 'Current Permissions :');
|
||||
if ($printTreesToo) {
|
||||
debug (array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
|
||||
}
|
||||
debug (implode("\r\n", $permissions));
|
||||
}
|
||||
|
||||
/**
|
||||
* pad function
|
||||
* Used by debug to format strings used in the data dump
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $len
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __pad($string = '', $len = 14) {
|
||||
return str_pad($string, $len);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,468 @@
|
||||
<?php
|
||||
/**
|
||||
* CookieComponentTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
* @since CakePHP(tm) v 1.2.0.5435
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Controller', array('Component', 'Controller'), false);
|
||||
App::import('Component', 'Cookie');
|
||||
|
||||
/**
|
||||
* CookieComponentTestController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class CookieComponentTestController extends Controller {
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Cookie');
|
||||
|
||||
/**
|
||||
* beforeFilter method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function beforeFilter() {
|
||||
$this->Cookie->name = 'CakeTestCookie';
|
||||
$this->Cookie->time = 10;
|
||||
$this->Cookie->path = '/';
|
||||
$this->Cookie->domain = '';
|
||||
$this->Cookie->secure = false;
|
||||
$this->Cookie->key = 'somerandomhaskey';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CookieComponentTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class CookieComponentTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* Controller property
|
||||
*
|
||||
* @var CookieComponentTestController
|
||||
* @access public
|
||||
*/
|
||||
var $Controller;
|
||||
|
||||
/**
|
||||
* start
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function start() {
|
||||
$this->Controller = new CookieComponentTestController();
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->beforeFilter();
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Cookie->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* end
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function end() {
|
||||
$this->Controller->Cookie->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that initialize sets settings from components array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testInitialize() {
|
||||
$settings = array(
|
||||
'time' => '5 days',
|
||||
'path' => '/'
|
||||
);
|
||||
$this->Controller->Cookie->initialize($this->Controller, $settings);
|
||||
$this->assertEqual($this->Controller->Cookie->time, $settings['time']);
|
||||
$this->assertEqual($this->Controller->Cookie->path, $settings['path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testCookieName
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testCookieName() {
|
||||
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettingEncryptedCookieData
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSettingEncryptedCookieData() {
|
||||
$this->Controller->Cookie->write('Encrytped_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'));
|
||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.name', 'CakePHP');
|
||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.version', '1.2.0.x');
|
||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.tag', 'CakePHP Rocks!');
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadEncryptedCookieData
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadEncryptedCookieData() {
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettingPlainCookieData
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSettingPlainCookieData() {
|
||||
$this->Controller->Cookie->write('Plain_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'), false);
|
||||
$this->Controller->Cookie->write('Plain_multi_cookies.name', 'CakePHP', false);
|
||||
$this->Controller->Cookie->write('Plain_multi_cookies.version', '1.2.0.x', false);
|
||||
$this->Controller->Cookie->write('Plain_multi_cookies.tag', 'CakePHP Rocks!', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadPlainCookieData
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadPlainCookieData() {
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testWritePlainCookieArray
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testWritePlainCookieArray() {
|
||||
$this->Controller->Cookie->write(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!'), null, false);
|
||||
|
||||
$this->assertEqual($this->Controller->Cookie->read('name'), 'CakePHP');
|
||||
$this->assertEqual($this->Controller->Cookie->read('version'), '1.2.0.x');
|
||||
$this->assertEqual($this->Controller->Cookie->read('tag'), 'CakePHP Rocks!');
|
||||
|
||||
$this->Controller->Cookie->delete('name');
|
||||
$this->Controller->Cookie->delete('version');
|
||||
$this->Controller->Cookie->delete('tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadingCookieValue
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadingCookieValue() {
|
||||
$data = $this->Controller->Cookie->read();
|
||||
$expected = array(
|
||||
'Encrytped_array' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'),
|
||||
'Encrytped_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'),
|
||||
'Plain_array' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'),
|
||||
'Plain_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'));
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteCookieValue
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteCookieValue() {
|
||||
$this->Controller->Cookie->delete('Encrytped_multi_cookies.name');
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$this->Controller->Cookie->delete('Encrytped_array');
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$this->Controller->Cookie->delete('Plain_multi_cookies.name');
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$this->Controller->Cookie->delete('Plain_array');
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSettingCookiesWithArray
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSettingCookiesWithArray() {
|
||||
$this->Controller->Cookie->destroy();
|
||||
|
||||
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
|
||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
|
||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
|
||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
|
||||
|
||||
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
|
||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
|
||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
|
||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadingCookieArray
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadingCookieArray() {
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadingCookieDataOnStartup
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadingCookieDataOnStartup() {
|
||||
$this->Controller->Cookie->destroy();
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$_COOKIE['CakeTestCookie'] = array(
|
||||
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
|
||||
'Encrytped_multi_cookies' => array(
|
||||
'name' => $this->__encrypt('CakePHP'),
|
||||
'version' => $this->__encrypt('1.2.0.x'),
|
||||
'tag' => $this->__encrypt('CakePHP Rocks!')),
|
||||
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
|
||||
'Plain_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'));
|
||||
$this->Controller->Cookie->startup();
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
$this->Controller->Cookie->destroy();
|
||||
unset($_COOKIE['CakeTestCookie']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadingCookieDataWithoutStartup
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadingCookieDataWithoutStartup() {
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$_COOKIE['CakeTestCookie'] = array(
|
||||
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
|
||||
'Encrytped_multi_cookies' => array(
|
||||
'name' => $this->__encrypt('CakePHP'),
|
||||
'version' => $this->__encrypt('1.2.0.x'),
|
||||
'tag' => $this->__encrypt('CakePHP Rocks!')),
|
||||
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
|
||||
'Plain_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'));
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
$this->Controller->Cookie->destroy();
|
||||
unset($_COOKIE['CakeTestCookie']);
|
||||
}
|
||||
|
||||
/**
|
||||
* encrypt method
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function __encrypt($value) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->__implode($value);
|
||||
}
|
||||
return "Q2FrZQ==." . base64_encode(Security::cipher($value, $this->Controller->Cookie->key));
|
||||
}
|
||||
|
||||
/**
|
||||
* implode method
|
||||
*
|
||||
* @param array $value
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function __implode($array) {
|
||||
$string = '';
|
||||
foreach ($array as $key => $value) {
|
||||
$string .= ',' . $key . '|' . $value;
|
||||
}
|
||||
return substr($string, 1);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,731 @@
|
||||
<?php
|
||||
/**
|
||||
* RequestHandlerComponentTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
* @since CakePHP(tm) v 1.2.0.5435
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Controller', 'Controller', false);
|
||||
App::import('Component', array('RequestHandler'));
|
||||
|
||||
Mock::generatePartial('RequestHandlerComponent', 'NoStopRequestHandler', array('_stop', '_header'));
|
||||
Mock::generatePartial('Controller', 'RequestHandlerMockController', array('header'));
|
||||
|
||||
/**
|
||||
* RequestHandlerTestController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class RequestHandlerTestController extends Controller {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'RequestHandlerTest';
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var mixed null
|
||||
* @access public
|
||||
*/
|
||||
var $uses = null;
|
||||
|
||||
/**
|
||||
* construct method
|
||||
*
|
||||
* @param array $params
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __construct($params = array()) {
|
||||
foreach ($params as $key => $val) {
|
||||
$this->{$key} = $val;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* test method for ajax redirection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function destination() {
|
||||
$this->viewPath = 'posts';
|
||||
$this->render('index');
|
||||
}
|
||||
/**
|
||||
* test method for ajax redirection + parameter parsing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function param_method($one = null, $two = null) {
|
||||
echo "one: $one two: $two";
|
||||
$this->autoRender = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* test method for testing layout rendering when isAjax()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ajax2_layout() {
|
||||
if ($this->autoLayout) {
|
||||
$this->layout = 'ajax2';
|
||||
}
|
||||
$this->destination();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RequestHandlerTestDisabledController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class RequestHandlerTestDisabledController extends Controller {
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var mixed null
|
||||
* @access public
|
||||
*/
|
||||
var $uses = null;
|
||||
|
||||
/**
|
||||
* construct method
|
||||
*
|
||||
* @param array $params
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __construct($params = array()) {
|
||||
foreach ($params as $key => $val) {
|
||||
$this->{$key} = $val;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* beforeFilter method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function beforeFilter() {
|
||||
$this->RequestHandler->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RequestHandlerComponentTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class RequestHandlerComponentTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* Controller property
|
||||
*
|
||||
* @var RequestHandlerTestController
|
||||
* @access public
|
||||
*/
|
||||
var $Controller;
|
||||
|
||||
/**
|
||||
* RequestHandler property
|
||||
*
|
||||
* @var RequestHandlerComponent
|
||||
* @access public
|
||||
*/
|
||||
var $RequestHandler;
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
$this->_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* init method
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
function _init() {
|
||||
$this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler')));
|
||||
$this->Controller->constructClasses();
|
||||
$this->RequestHandler =& $this->Controller->RequestHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->RequestHandler);
|
||||
unset($this->Controller);
|
||||
if (!headers_sent()) {
|
||||
header('Content-type: text/html'); //reset content type.
|
||||
}
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* testInitializeCallback method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testInitializeCallback() {
|
||||
$this->assertNull($this->RequestHandler->ext);
|
||||
|
||||
$this->_init();
|
||||
$this->Controller->params['url']['ext'] = 'rss';
|
||||
$this->RequestHandler->initialize($this->Controller);
|
||||
$this->assertEqual($this->RequestHandler->ext, 'rss');
|
||||
|
||||
$settings = array(
|
||||
'ajaxLayout' => 'test_ajax'
|
||||
);
|
||||
$this->RequestHandler->initialize($this->Controller, $settings);
|
||||
$this->assertEqual($this->RequestHandler->ajaxLayout, 'test_ajax');
|
||||
}
|
||||
|
||||
/**
|
||||
* testDisabling method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDisabling() {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$this->_init();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->beforeFilter();
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->assertEqual($this->Controller->params, array('isAjax' => true));
|
||||
|
||||
$this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler')));
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->beforeFilter();
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->assertEqual($this->Controller->params, array());
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAutoResponseType method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAutoResponseType() {
|
||||
$this->Controller->ext = '.thtml';
|
||||
$this->Controller->params['url']['ext'] = 'rss';
|
||||
$this->RequestHandler->initialize($this->Controller);
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertEqual($this->Controller->ext, '.ctp');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testAutoAjaxLayout method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAutoAjaxLayout() {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertTrue($this->Controller->layout, $this->RequestHandler->ajaxLayout);
|
||||
|
||||
$this->_init();
|
||||
$this->Controller->params['url']['ext'] = 'js';
|
||||
$this->RequestHandler->initialize($this->Controller);
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertNotEqual($this->Controller->layout, 'ajax');
|
||||
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testStartupCallback method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testStartupCallback() {
|
||||
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
||||
$_SERVER['CONTENT_TYPE'] = 'application/xml';
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertTrue(is_array($this->Controller->data));
|
||||
$this->assertFalse(is_object($this->Controller->data));
|
||||
}
|
||||
|
||||
/**
|
||||
* testStartupCallback with charset.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testStartupCallbackCharset() {
|
||||
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
||||
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertTrue(is_array($this->Controller->data));
|
||||
$this->assertFalse(is_object($this->Controller->data));
|
||||
}
|
||||
|
||||
/**
|
||||
* testNonAjaxRedirect method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testNonAjaxRedirect() {
|
||||
$this->RequestHandler->initialize($this->Controller);
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, '/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testRenderAs method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRenderAs() {
|
||||
$this->assertFalse(in_array('Xml', $this->Controller->helpers));
|
||||
$this->RequestHandler->renderAs($this->Controller, 'xml');
|
||||
$this->assertTrue(in_array('Xml', $this->Controller->helpers));
|
||||
|
||||
$this->Controller->viewPath = 'request_handler_test\\xml';
|
||||
$this->RequestHandler->renderAs($this->Controller, 'js');
|
||||
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that respondAs works as expected.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testRespondAs() {
|
||||
$RequestHandler = new NoStopRequestHandler();
|
||||
$RequestHandler->expectAt(0, '_header', array('Content-Type: application/json'));
|
||||
$RequestHandler->expectAt(1, '_header', array('Content-Type: text/xml'));
|
||||
|
||||
$result = $RequestHandler->respondAs('json');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $RequestHandler->respondAs('text/xml');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that attachment headers work with respondAs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testRespondAsWithAttachment() {
|
||||
$RequestHandler = new NoStopRequestHandler();
|
||||
$RequestHandler->expectAt(0, '_header', array('Content-Disposition: attachment; filename="myfile.xml"'));
|
||||
$RequestHandler->expectAt(1, '_header', array('Content-Type: text/xml'));
|
||||
|
||||
$result = $RequestHandler->respondAs('xml', array('attachment' => 'myfile.xml'));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that calling renderAs() more than once continues to work.
|
||||
*
|
||||
* @link #6466
|
||||
* @return void
|
||||
*/
|
||||
function testRenderAsCalledTwice() {
|
||||
$this->RequestHandler->renderAs($this->Controller, 'xml');
|
||||
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'xml');
|
||||
$this->assertEqual($this->Controller->layoutPath, 'xml');
|
||||
|
||||
$this->assertTrue(in_array('Xml', $this->Controller->helpers));
|
||||
|
||||
$this->RequestHandler->renderAs($this->Controller, 'js');
|
||||
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
|
||||
$this->assertEqual($this->Controller->layoutPath, 'js');
|
||||
$this->assertTrue(in_array('Js', $this->Controller->helpers));
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestClientTypes method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRequestClientTypes() {
|
||||
$this->assertFalse($this->RequestHandler->isFlash());
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Shockwave Flash';
|
||||
$this->assertTrue($this->RequestHandler->isFlash());
|
||||
unset($_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
|
||||
$this->assertFalse($this->RequestHandler->isAjax());
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$_SERVER['HTTP_X_PROTOTYPE_VERSION'] = '1.5';
|
||||
$this->assertTrue($this->RequestHandler->isAjax());
|
||||
$this->assertEqual($this->RequestHandler->getAjaxVersion(), '1.5');
|
||||
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH'], $_SERVER['HTTP_X_PROTOTYPE_VERSION']);
|
||||
$this->assertFalse($this->RequestHandler->isAjax());
|
||||
$this->assertFalse($this->RequestHandler->getAjaxVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the detection of various Flash versions
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testFlashDetection() {
|
||||
$_agent = env('HTTP_USER_AGENT');
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Shockwave Flash';
|
||||
$this->assertTrue($this->RequestHandler->isFlash());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Adobe Flash';
|
||||
$this->assertTrue($this->RequestHandler->isFlash());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Adobe Flash Player 9';
|
||||
$this->assertTrue($this->RequestHandler->isFlash());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Adobe Flash Player 10';
|
||||
$this->assertTrue($this->RequestHandler->isFlash());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Shock Flash';
|
||||
$this->assertFalse($this->RequestHandler->isFlash());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $_agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestContentTypes method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRequestContentTypes() {
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$this->assertNull($this->RequestHandler->requestedWith());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
$_SERVER['CONTENT_TYPE'] = 'application/json';
|
||||
$this->assertEqual($this->RequestHandler->requestedWith(), 'json');
|
||||
|
||||
$result = $this->RequestHandler->requestedWith(array('json', 'xml'));
|
||||
$this->assertEqual($result, 'json');
|
||||
|
||||
$result =$this->RequestHandler->requestedWith(array('rss', 'atom'));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
||||
$this->_init();
|
||||
$this->assertTrue($this->RequestHandler->isXml());
|
||||
$this->assertFalse($this->RequestHandler->isAtom());
|
||||
$this->assertFalse($this->RequestHandler->isRSS());
|
||||
|
||||
$_SERVER['HTTP_ACCEPT'] = 'application/atom+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
||||
$this->_init();
|
||||
$this->assertTrue($this->RequestHandler->isAtom());
|
||||
$this->assertFalse($this->RequestHandler->isRSS());
|
||||
|
||||
$_SERVER['HTTP_ACCEPT'] = 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
||||
$this->_init();
|
||||
$this->assertFalse($this->RequestHandler->isAtom());
|
||||
$this->assertTrue($this->RequestHandler->isRSS());
|
||||
|
||||
$this->assertFalse($this->RequestHandler->isWap());
|
||||
$_SERVER['HTTP_ACCEPT'] = 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*';
|
||||
$this->_init();
|
||||
$this->assertTrue($this->RequestHandler->isWap());
|
||||
|
||||
$_SERVER['HTTP_ACCEPT'] = 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
||||
}
|
||||
|
||||
/**
|
||||
* testResponseContentType method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testResponseContentType() {
|
||||
$this->assertNull($this->RequestHandler->responseType());
|
||||
$this->assertTrue($this->RequestHandler->respondAs('atom'));
|
||||
$this->assertEqual($this->RequestHandler->responseType(), 'atom');
|
||||
}
|
||||
|
||||
/**
|
||||
* testMobileDeviceDetection method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testMobileDeviceDetection() {
|
||||
$this->assertFalse($this->RequestHandler->isMobile());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3';
|
||||
$this->assertTrue($this->RequestHandler->isMobile());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Some imaginary UA';
|
||||
$this->RequestHandler->mobileUA []= 'imaginary';
|
||||
$this->assertTrue($this->RequestHandler->isMobile());
|
||||
array_pop($this->RequestHandler->mobileUA);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestProperties method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRequestProperties() {
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
$this->assertTrue($this->RequestHandler->isSSL());
|
||||
|
||||
unset($_SERVER['HTTPS']);
|
||||
$this->assertFalse($this->RequestHandler->isSSL());
|
||||
|
||||
$_ENV['SCRIPT_URI'] = 'https://localhost/';
|
||||
$s = $_SERVER;
|
||||
$_SERVER = array();
|
||||
$this->assertTrue($this->RequestHandler->isSSL());
|
||||
$_SERVER = $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestMethod method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRequestMethod() {
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$this->assertTrue($this->RequestHandler->isGet());
|
||||
$this->assertFalse($this->RequestHandler->isPost());
|
||||
$this->assertFalse($this->RequestHandler->isPut());
|
||||
$this->assertFalse($this->RequestHandler->isDelete());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
$this->assertFalse($this->RequestHandler->isGet());
|
||||
$this->assertTrue($this->RequestHandler->isPost());
|
||||
$this->assertFalse($this->RequestHandler->isPut());
|
||||
$this->assertFalse($this->RequestHandler->isDelete());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
||||
$this->assertFalse($this->RequestHandler->isGet());
|
||||
$this->assertFalse($this->RequestHandler->isPost());
|
||||
$this->assertTrue($this->RequestHandler->isPut());
|
||||
$this->assertFalse($this->RequestHandler->isDelete());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'DELETE';
|
||||
$this->assertFalse($this->RequestHandler->isGet());
|
||||
$this->assertFalse($this->RequestHandler->isPost());
|
||||
$this->assertFalse($this->RequestHandler->isPut());
|
||||
$this->assertTrue($this->RequestHandler->isDelete());
|
||||
}
|
||||
|
||||
/**
|
||||
* testClientContentPreference method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testClientContentPreference() {
|
||||
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
||||
$this->_init();
|
||||
$this->assertNotEqual($this->RequestHandler->prefers(), 'rss');
|
||||
$this->RequestHandler->ext = 'rss';
|
||||
$this->assertEqual($this->RequestHandler->prefers(), 'rss');
|
||||
$this->assertFalse($this->RequestHandler->prefers('xml'));
|
||||
$this->assertEqual($this->RequestHandler->prefers(array('js', 'xml', 'xhtml')), 'xml');
|
||||
$this->assertTrue($this->RequestHandler->accepts('xml'));
|
||||
|
||||
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
|
||||
$this->_init();
|
||||
$this->assertEqual($this->RequestHandler->prefers(), 'xml');
|
||||
$this->assertEqual($this->RequestHandler->accepts(array('js', 'xml', 'html')), 'xml');
|
||||
$this->assertFalse($this->RequestHandler->accepts(array('gif', 'jpeg', 'foo')));
|
||||
|
||||
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5';
|
||||
$this->_init();
|
||||
$this->assertEqual($this->RequestHandler->prefers(), 'html');
|
||||
$this->assertFalse($this->RequestHandler->prefers('rss'));
|
||||
$this->assertFalse($this->RequestHandler->accepts('rss'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testCustomContent method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testCustomContent() {
|
||||
$_SERVER['HTTP_ACCEPT'] = 'text/x-mobile,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5';
|
||||
$this->_init();
|
||||
$this->RequestHandler->setContent('mobile', 'text/x-mobile');
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertEqual($this->RequestHandler->prefers(), 'mobile');
|
||||
|
||||
$this->_init();
|
||||
$this->RequestHandler->setContent(array('mobile' => 'text/x-mobile'));
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->assertEqual($this->RequestHandler->prefers(), 'mobile');
|
||||
}
|
||||
|
||||
/**
|
||||
* testClientProperties method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testClientProperties() {
|
||||
$_SERVER['HTTP_HOST'] = 'localhost:80';
|
||||
$this->assertEqual($this->RequestHandler->getReferer(), 'localhost');
|
||||
$_SERVER['HTTP_HOST'] = null;
|
||||
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
|
||||
$this->assertEqual($this->RequestHandler->getReferer(), 'cakephp.org');
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com';
|
||||
$_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2';
|
||||
$_SERVER['REMOTE_ADDR'] = '192.168.1.3';
|
||||
$this->assertEqual($this->RequestHandler->getClientIP(false), '192.168.1.5');
|
||||
$this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2');
|
||||
|
||||
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
$this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2');
|
||||
|
||||
unset($_SERVER['HTTP_CLIENT_IP']);
|
||||
$this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.3');
|
||||
|
||||
$_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1';
|
||||
$this->assertEqual($this->RequestHandler->getClientIP(), '10.0.1.2');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that ajax requests involving redirects trigger requestAction instead.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testAjaxRedirectAsRequestAction() {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$this->_init();
|
||||
App::build(array(
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||
), true);
|
||||
|
||||
$this->Controller->RequestHandler = new NoStopRequestHandler($this);
|
||||
$this->Controller->RequestHandler->expectOnce('_stop');
|
||||
|
||||
ob_start();
|
||||
$this->Controller->RequestHandler->beforeRedirect(
|
||||
$this->Controller, array('controller' => 'request_handler_test', 'action' => 'destination')
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');
|
||||
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that ajax requests involving redirects don't force no layout
|
||||
* this would cause the ajax layout to not be rendered.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testAjaxRedirectAsRequestActionStillRenderingLayout() {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$this->_init();
|
||||
App::build(array(
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||
), true);
|
||||
|
||||
$this->Controller->RequestHandler = new NoStopRequestHandler($this);
|
||||
$this->Controller->RequestHandler->expectOnce('_stop');
|
||||
|
||||
ob_start();
|
||||
$this->Controller->RequestHandler->beforeRedirect(
|
||||
$this->Controller, array('controller' => 'request_handler_test', 'action' => 'ajax2_layout')
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');
|
||||
$this->assertPattern('/Ajax!/', $result, 'Layout was not rendered.');
|
||||
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the beforeRedirect callback properly converts
|
||||
* array urls into their correct string ones, and adds base => false so
|
||||
* the correct urls are generated.
|
||||
*
|
||||
* @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
|
||||
* @return void
|
||||
*/
|
||||
function testBeforeRedirectCallbackWithArrayUrl() {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
|
||||
Router::setRequestInfo(array(
|
||||
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
|
||||
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
|
||||
));
|
||||
|
||||
$RequestHandler =& new NoStopRequestHandler();
|
||||
|
||||
ob_start();
|
||||
$RequestHandler->beforeRedirect(
|
||||
$this->Controller,
|
||||
array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second')
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual($result, 'one: first two: second');
|
||||
}
|
||||
|
||||
/**
|
||||
* assure that beforeRedirect with a status code will correctly set the status header
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testBeforeRedirectCallingHeader() {
|
||||
$controller =& new RequestHandlerMockController();
|
||||
$RequestHandler =& new NoStopRequestHandler();
|
||||
|
||||
$controller->expectOnce('header', array('HTTP/1.1 403 Forbidden'));
|
||||
|
||||
ob_start();
|
||||
$RequestHandler->beforeRedirect($controller, 'request_handler_test/param_method/first/second', 403);
|
||||
$result = ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
/**
|
||||
* SessionComponentTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
* @since CakePHP(tm) v 1.2.0.5436
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Controller', 'Controller', false);
|
||||
App::import('Component', 'Session');
|
||||
|
||||
/**
|
||||
* SessionTestController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class SessionTestController extends Controller {
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
|
||||
/**
|
||||
* session_id method
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function session_id() {
|
||||
return $this->Session->id();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OrangeSessionTestController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class OrangeSessionTestController extends Controller {
|
||||
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
|
||||
/**
|
||||
* session_id method
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function session_id() {
|
||||
return $this->Session->id();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SessionComponentTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class SessionComponentTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setUp() {
|
||||
$this->_session = Configure::read('Session');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
Configure::write('Session', $this->_session);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionAutoStart method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionAutoStart() {
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->__active);
|
||||
$this->assertFalse($Session->started());
|
||||
$Session->startup(new SessionTestController());
|
||||
|
||||
Configure::write('Session.start', true);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertTrue($Session->__active);
|
||||
$this->assertFalse($Session->started());
|
||||
$Session->startup(new SessionTestController());
|
||||
$this->assertTrue(isset($_SESSION));
|
||||
|
||||
$Object = new Object();
|
||||
$Session =& new SessionComponent();
|
||||
$Session->start();
|
||||
$expected = $Session->id();
|
||||
|
||||
$result = $Object->requestAction('/session_test/session_id');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $Object->requestAction('/orange_session_test/session_id');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionActivate method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionActivate() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertTrue($Session->__active);
|
||||
$this->assertNull($Session->activate());
|
||||
$this->assertTrue($Session->__active);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->__active);
|
||||
$this->assertNull($Session->activate());
|
||||
$this->assertTrue($Session->__active);
|
||||
Configure::write('Session.start', true);
|
||||
$Session->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionValid method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionValid() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertTrue($Session->valid());
|
||||
|
||||
$Session->_userAgent = 'rweerw';
|
||||
$this->assertFalse($Session->valid());
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->__active);
|
||||
$this->assertFalse($Session->valid());
|
||||
Configure::write('Session.start', true);
|
||||
|
||||
$Session =& new SessionComponent();
|
||||
$Session->time = $Session->read('Config.time') + 1;
|
||||
$this->assertFalse($Session->valid());
|
||||
|
||||
Configure::write('Session.checkAgent', false);
|
||||
$Session =& new SessionComponent();
|
||||
$Session->time = $Session->read('Config.time') + 1;
|
||||
$this->assertFalse($Session->valid());
|
||||
Configure::write('Session.checkAgent', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionError method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionError() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertFalse($Session->error());
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->__active);
|
||||
$this->assertFalse($Session->error());
|
||||
Configure::write('Session.start', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionReadWrite method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionReadWrite() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertFalse($Session->read('Test'));
|
||||
|
||||
$this->assertTrue($Session->write('Test', 'some value'));
|
||||
$this->assertEqual($Session->read('Test'), 'some value');
|
||||
$this->assertFalse($Session->write('Test.key', 'some value'));
|
||||
$Session->delete('Test');
|
||||
|
||||
$this->assertTrue($Session->write('Test.key.path', 'some value'));
|
||||
$this->assertEqual($Session->read('Test.key.path'), 'some value');
|
||||
$this->assertEqual($Session->read('Test.key'), array('path' => 'some value'));
|
||||
$this->assertTrue($Session->write('Test.key.path2', 'another value'));
|
||||
$this->assertEqual($Session->read('Test.key'), array('path' => 'some value', 'path2' => 'another value'));
|
||||
$Session->delete('Test');
|
||||
|
||||
$array = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
|
||||
$this->assertTrue($Session->write('Test', $array));
|
||||
$this->assertEqual($Session->read('Test'), $array);
|
||||
$Session->delete('Test');
|
||||
|
||||
$this->assertFalse($Session->write(array('Test'), 'some value'));
|
||||
$this->assertTrue($Session->write(array('Test' => 'some value')));
|
||||
$this->assertEqual($Session->read('Test'), 'some value');
|
||||
$Session->delete('Test');
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->write('Test', 'some value'));
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->read('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionDelete method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionDelete() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertFalse($Session->delete('Test'));
|
||||
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertTrue($Session->delete('Test'));
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->delete('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionCheck method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionCheck() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertFalse($Session->check('Test'));
|
||||
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertTrue($Session->check('Test'));
|
||||
$Session->delete('Test');
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->check('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionFlash method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionFlash() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertNull($Session->read('Message.flash'));
|
||||
|
||||
$Session->setFlash('This is a test message');
|
||||
$this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array()));
|
||||
|
||||
$Session->setFlash('This is a test message', 'test', array('name' => 'Joel Moss'));
|
||||
$this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'element' => 'test', 'params' => array('name' => 'Joel Moss')));
|
||||
|
||||
$Session->setFlash('This is a test message', 'default', array(), 'myFlash');
|
||||
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array()));
|
||||
|
||||
$Session->setFlash('This is a test message', 'non_existing_layout');
|
||||
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array()));
|
||||
|
||||
$Session->delete('Message');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionId method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionId() {
|
||||
unset($_SESSION);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertNull($Session->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionDestroy method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionDestroy() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertEqual($Session->read('Test'), 'some value');
|
||||
$Session->destroy('Test');
|
||||
$this->assertNull($Session->read('Test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testSessionTimeout method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionTimeout() {
|
||||
Configure::write('debug', 2);
|
||||
Configure::write('Security.level', 'low');
|
||||
|
||||
session_destroy();
|
||||
$Session =& new SessionComponent();
|
||||
$Session->destroy();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertEqual($Session->sessionTime, time() + (300 * Configure::read('Session.timeout')));
|
||||
$this->assertEqual($_SESSION['Config']['timeout'], 10);
|
||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||
$this->assertEqual($Session->time, time());
|
||||
$this->assertEqual($_SESSION['Config']['time'], $Session->time + (300 * Configure::read('Session.timeout')));
|
||||
|
||||
Configure::write('Security.level', 'medium');
|
||||
$Session =& new SessionComponent();
|
||||
$Session->destroy();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertEqual($Session->sessionTime, mktime() + (100 * Configure::read('Session.timeout')));
|
||||
$this->assertEqual($_SESSION['Config']['timeout'], 10);
|
||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||
$this->assertEqual($Session->time, time());
|
||||
$this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout')));
|
||||
|
||||
Configure::write('Security.level', 'high');
|
||||
$Session =& new SessionComponent();
|
||||
$Session->destroy();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertEqual($Session->sessionTime, time() + (10 * Configure::read('Session.timeout')));
|
||||
$this->assertEqual($_SESSION['Config']['timeout'], 10);
|
||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||
$this->assertEqual($Session->time, time());
|
||||
$this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout')));
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Controller Merge vars Test file
|
||||
*
|
||||
* Isolated from the Controller and Component test as to not pollute their AppController class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
* @since CakePHP(tm) v 1.2.3
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
if (!class_exists('AppController')) {
|
||||
|
||||
/**
|
||||
* Test case AppController
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class AppController extends Controller {
|
||||
|
||||
/**
|
||||
* components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false));
|
||||
/**
|
||||
* helpers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $helpers = array('MergeVar' => array('format' => 'html', 'terse'));
|
||||
}
|
||||
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
|
||||
define('APP_CONTROLLER_EXISTS', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* MergeVar Component
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller
|
||||
*/
|
||||
class MergeVarComponent extends Object {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional controller for testing
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller
|
||||
*/
|
||||
class MergeVariablesController extends AppController {
|
||||
|
||||
/**
|
||||
* name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $name = 'MergeVariables';
|
||||
|
||||
/**
|
||||
* uses
|
||||
*
|
||||
* @var arrays
|
||||
*/
|
||||
var $uses = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* MergeVarPlugin App Controller
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller
|
||||
*/
|
||||
class MergeVarPluginAppController extends AppController {
|
||||
|
||||
/**
|
||||
* components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $components = array('Auth' => array('setting' => 'val', 'otherVal'));
|
||||
|
||||
/**
|
||||
* helpers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $helpers = array('Javascript');
|
||||
}
|
||||
|
||||
/**
|
||||
* MergePostsController
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller
|
||||
*/
|
||||
class MergePostsController extends MergeVarPluginAppController {
|
||||
|
||||
/**
|
||||
* name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $name = 'MergePosts';
|
||||
|
||||
/**
|
||||
* uses
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $uses = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test Case for Controller Merging of Vars.
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||
/**
|
||||
* Skips the case if APP_CONTROLLER_EXISTS is defined
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function skip() {
|
||||
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), 'APP_CONTROLLER_EXISTS cannot run. %s');
|
||||
}
|
||||
/**
|
||||
* end test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that component settings are not duplicated when merging component settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testComponentParamMergingNoDuplication() {
|
||||
$Controller =& new MergeVariablesController();
|
||||
$Controller->constructClasses();
|
||||
|
||||
$expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false));
|
||||
$this->assertEqual($Controller->components, $expected, 'Duplication of settings occured. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test component merges with redeclared components
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testComponentMergingWithRedeclarations() {
|
||||
$Controller =& new MergeVariablesController();
|
||||
$Controller->components['MergeVar'] = array('remote', 'redirect' => true);
|
||||
$Controller->constructClasses();
|
||||
|
||||
$expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => true, 'remote'));
|
||||
$this->assertEqual($Controller->components, $expected, 'Merging of settings is wrong. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test merging of helpers array, ensure no duplication occurs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testHelperSettingMergingNoDuplication() {
|
||||
$Controller =& new MergeVariablesController();
|
||||
$Controller->constructClasses();
|
||||
|
||||
$expected = array('MergeVar' => array('format' => 'html', 'terse'));
|
||||
$this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test merging of vars with plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMergeVarsWithPlugin() {
|
||||
$Controller =& new MergePostsController();
|
||||
$Controller->components = array('Email' => array('ports' => 'open'));
|
||||
$Controller->plugin = 'MergeVarPlugin';
|
||||
$Controller->constructClasses();
|
||||
|
||||
$expected = array(
|
||||
'MergeVar' => array('flag', 'otherFlag', 'redirect' => false),
|
||||
'Auth' => array('setting' => 'val', 'otherVal'),
|
||||
'Email' => array('ports' => 'open')
|
||||
);
|
||||
$this->assertEqual($Controller->components, $expected, 'Components are unexpected %s');
|
||||
|
||||
$expected = array(
|
||||
'Javascript',
|
||||
'MergeVar' => array('format' => 'html', 'terse')
|
||||
);
|
||||
$this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s');
|
||||
|
||||
$Controller =& new MergePostsController();
|
||||
$Controller->components = array();
|
||||
$Controller->plugin = 'MergeVarPlugin';
|
||||
$Controller->constructClasses();
|
||||
|
||||
$expected = array(
|
||||
'MergeVar' => array('flag', 'otherFlag', 'redirect' => false),
|
||||
'Auth' => array('setting' => 'val', 'otherVal'),
|
||||
);
|
||||
$this->assertEqual($Controller->components, $expected, 'Components are unexpected %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that __mergeVars is not being greedy and merging with
|
||||
* AppController when you make an instance of Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMergeVarsNotGreedy() {
|
||||
$Controller =& new Controller();
|
||||
$Controller->components = array();
|
||||
$Controller->uses = array();
|
||||
$Controller->constructClasses();
|
||||
|
||||
$this->assertFalse(isset($Controller->Session));
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* PagesControllerTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
* @since CakePHP(tm) v 1.2.0.5436
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
if (!class_exists('AppController')) {
|
||||
require_once LIBS . 'controller' . DS . 'app_controller.php';
|
||||
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
|
||||
define('APP_CONTROLLER_EXISTS', true);
|
||||
}
|
||||
App::import('Controller', 'Pages');
|
||||
|
||||
/**
|
||||
* PagesControllerTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class PagesControllerTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* testDisplay method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDisplay() {
|
||||
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
|
||||
return;
|
||||
}
|
||||
|
||||
App::build(array(
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS)
|
||||
));
|
||||
$Pages =& new PagesController();
|
||||
|
||||
$Pages->viewPath = 'posts';
|
||||
$Pages->display('index');
|
||||
$this->assertPattern('/posts index/', $Pages->output);
|
||||
$this->assertEqual($Pages->viewVars['page'], 'index');
|
||||
|
||||
$Pages->viewPath = 'themed';
|
||||
$Pages->display('test_theme', 'posts', 'index');
|
||||
$this->assertPattern('/posts index themed view/', $Pages->output);
|
||||
$this->assertEqual($Pages->viewVars['page'], 'test_theme');
|
||||
$this->assertEqual($Pages->viewVars['subpage'], 'posts');
|
||||
}
|
||||
}
|
@@ -0,0 +1,897 @@
|
||||
<?php
|
||||
/**
|
||||
* ScaffoldTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
* @since CakePHP(tm) v 1.2.0.5436
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Core', 'Scaffold');
|
||||
|
||||
/**
|
||||
* ScaffoldMockController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldMockController extends Controller {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'ScaffoldMock'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ScaffoldMock';
|
||||
|
||||
/**
|
||||
* scaffold property
|
||||
*
|
||||
* @var mixed
|
||||
* @access public
|
||||
*/
|
||||
var $scaffold;
|
||||
}
|
||||
|
||||
/**
|
||||
* ScaffoldMockControllerWithFields class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldMockControllerWithFields extends Controller {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'ScaffoldMock'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ScaffoldMock';
|
||||
|
||||
/**
|
||||
* scaffold property
|
||||
*
|
||||
* @var mixed
|
||||
* @access public
|
||||
*/
|
||||
var $scaffold;
|
||||
|
||||
/**
|
||||
* function _beforeScaffold
|
||||
*
|
||||
* @param string method
|
||||
*/
|
||||
function _beforeScaffold($method) {
|
||||
$this->set('scaffoldFields', array('title'));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TestScaffoldMock class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class TestScaffoldMock extends Scaffold {
|
||||
|
||||
/**
|
||||
* Overload __scaffold
|
||||
*
|
||||
* @param unknown_type $params
|
||||
*/
|
||||
function __scaffold($params) {
|
||||
$this->_params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Params from the Controller.
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function getParams() {
|
||||
return $this->_params;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ScaffoldMock class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldMock extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'articles';
|
||||
|
||||
/**
|
||||
* belongsTo property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $belongsTo = array(
|
||||
'User' => array(
|
||||
'className' => 'ScaffoldUser',
|
||||
'foreignKey' => 'user_id',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* hasMany property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasMany = array(
|
||||
'Comment' => array(
|
||||
'className' => 'ScaffoldComment',
|
||||
'foreignKey' => 'article_id',
|
||||
)
|
||||
);
|
||||
/**
|
||||
* hasAndBelongsToMany property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $hasAndBelongsToMany = array(
|
||||
'ScaffoldTag' => array(
|
||||
'className' => 'ScaffoldTag',
|
||||
'foreignKey' => 'something_id',
|
||||
'associationForeignKey' => 'something_else_id',
|
||||
'joinTable' => 'join_things'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ScaffoldUser class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldUser extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'users';
|
||||
|
||||
/**
|
||||
* hasMany property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasMany = array(
|
||||
'Article' => array(
|
||||
'className' => 'ScaffoldMock',
|
||||
'foreignKey' => 'article_id',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ScaffoldComment class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldComment extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'comments';
|
||||
|
||||
/**
|
||||
* belongsTo property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $belongsTo = array(
|
||||
'Article' => array(
|
||||
'className' => 'ScaffoldMock',
|
||||
'foreignKey' => 'article_id',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ScaffoldTag class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldTag extends CakeTestModel {
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'tags';
|
||||
}
|
||||
/**
|
||||
* TestScaffoldView class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class TestScaffoldView extends ScaffoldView {
|
||||
|
||||
/**
|
||||
* testGetFilename method
|
||||
*
|
||||
* @param mixed $action
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testGetFilename($action) {
|
||||
return $this->_getViewFileName($action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ScaffoldViewTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldViewTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Controller =& new ScaffoldMockController();
|
||||
|
||||
App::build(array(
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Controller);
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* testGetViewFilename method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testGetViewFilename() {
|
||||
$_admin = Configure::read('Routing.prefixes');
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
|
||||
$this->Controller->action = 'index';
|
||||
$ScaffoldView =& new TestScaffoldView($this->Controller);
|
||||
$result = $ScaffoldView->testGetFilename('index');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'index.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('edit');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('add');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('view');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'view.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('admin_index');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'index.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('admin_view');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'view.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('admin_edit');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('admin_add');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('error');
|
||||
$expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$Controller =& new ScaffoldMockController();
|
||||
$Controller->scaffold = 'admin';
|
||||
$Controller->viewPath = 'posts';
|
||||
$Controller->action = 'admin_edit';
|
||||
$ScaffoldView =& new TestScaffoldView($Controller);
|
||||
$result = $ScaffoldView->testGetFilename('admin_edit');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('edit');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$Controller =& new ScaffoldMockController();
|
||||
$Controller->scaffold = 'admin';
|
||||
$Controller->viewPath = 'tests';
|
||||
$Controller->plugin = 'test_plugin';
|
||||
$Controller->action = 'admin_add';
|
||||
$ScaffoldView =& new TestScaffoldView($Controller);
|
||||
$result = $ScaffoldView->testGetFilename('admin_add');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'
|
||||
. DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('add');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'
|
||||
. DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('Routing.prefixes', $_admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting the view file name for themed scaffolds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetViewFileNameWithTheme() {
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->theme = 'test_theme';
|
||||
$ScaffoldView =& new TestScaffoldView($this->Controller);
|
||||
|
||||
$result = $ScaffoldView->testGetFilename('index');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS
|
||||
. 'themed' . DS . 'test_theme' . DS . 'posts' . DS . 'scaffold.index.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test default index scaffold generation
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testIndexScaffold() {
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'index',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
ob_start();
|
||||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('#<h2>Scaffold Mock</h2>#', $result);
|
||||
$this->assertPattern('#<table cellpadding="0" cellspacing="0">#', $result);
|
||||
|
||||
$this->assertPattern('#<a href="/scaffold_users/view/1">1</a>#', $result); //belongsTo links
|
||||
$this->assertPattern('#<li><a href="/scaffold_mock/add">New Scaffold Mock</a></li>#', $result);
|
||||
$this->assertPattern('#<li><a href="/scaffold_users">List Scaffold Users</a></li>#', $result);
|
||||
$this->assertPattern('#<li><a href="/scaffold_comments/add">New Comment</a></li>#', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test default view scaffold generation
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testViewScaffold() {
|
||||
$this->Controller->action = 'view';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(1),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'view',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
|
||||
ob_start();
|
||||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>View Scaffold Mock<\/h2>/', $result);
|
||||
$this->assertPattern('/<dl>/', $result);
|
||||
//TODO: add specific tests for fields.
|
||||
$this->assertPattern('/<a href="\/scaffold_users\/view\/1">1<\/a>/', $result); //belongsTo links
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit Scaffold Mock<\/a>\s<\/li>/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete Scaffold Mock<\/a>\s*<\/li>/', $result);
|
||||
//check related table
|
||||
$this->assertPattern('/<div class="related">\s*<h3>Related Scaffold Comments<\/h3>\s*<table cellpadding="0" cellspacing="0">/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_comments\/add">New Comment<\/a><\/li>/', $result);
|
||||
$this->assertNoPattern('/<th>JoinThing<\/th>/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test default view scaffold generation
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testEditScaffold() {
|
||||
$this->Controller->action = 'edit';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(1),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'edit',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
ob_start();
|
||||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<form id="ScaffoldMockEditForm" method="post" action="\/scaffold_mock\/edit\/1"/', $result);
|
||||
$this->assertPattern('/<legend>Edit Scaffold Mock<\/legend>/', $result);
|
||||
|
||||
$this->assertPattern('/input type="hidden" name="data\[ScaffoldMock\]\[id\]" value="1" id="ScaffoldMockId"/', $result);
|
||||
$this->assertPattern('/select name="data\[ScaffoldMock\]\[user_id\]" id="ScaffoldMockUserId"/', $result);
|
||||
$this->assertPattern('/input name="data\[ScaffoldMock\]\[title\]" type="text" maxlength="255" value="First Article" id="ScaffoldMockTitle"/', $result);
|
||||
$this->assertPattern('/input name="data\[ScaffoldMock\]\[published\]" type="text" maxlength="1" value="Y" id="ScaffoldMockPublished"/', $result);
|
||||
$this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete<\/a>\s*<\/li>/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Admin Index Scaffolding.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAdminIndexScaffold() {
|
||||
$_backAdmin = Configure::read('Routing.prefixes');
|
||||
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'prefix' => 'admin',
|
||||
'url' => array('url' =>'admin/scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'admin_index',
|
||||
'admin' => 1,
|
||||
);
|
||||
//reset, and set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/admin/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->action = 'admin_index';
|
||||
$this->Controller->here = '/tests/admin/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$this->Controller->scaffold = 'admin';
|
||||
$this->Controller->constructClasses();
|
||||
|
||||
ob_start();
|
||||
$Scaffold = new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
|
||||
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
|
||||
//TODO: add testing for table generation
|
||||
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add">New Scaffold Mock<\/a><\/li>/', $result);
|
||||
|
||||
Configure::write('Routing.prefixes', $_backAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Admin Index Scaffolding.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAdminEditScaffold() {
|
||||
$_backAdmin = Configure::read('Routing.prefixes');
|
||||
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'prefix' => 'admin',
|
||||
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'admin_edit',
|
||||
'admin' => 1,
|
||||
);
|
||||
//reset, and set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/admin/scaffold_mock/edit', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->action = 'admin_index';
|
||||
$this->Controller->here = '/tests/admin/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$this->Controller->scaffold = 'admin';
|
||||
$this->Controller->constructClasses();
|
||||
|
||||
ob_start();
|
||||
$Scaffold = new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('#admin/scaffold_mock/edit/1#', $result);
|
||||
$this->assertPattern('#Scaffold Mock#', $result);
|
||||
|
||||
Configure::write('Routing.prefixes', $_backAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Admin Index Scaffolding.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testMultiplePrefixScaffold() {
|
||||
$_backAdmin = Configure::read('Routing.prefixes');
|
||||
|
||||
Configure::write('Routing.prefixes', array('admin', 'member'));
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'prefix' => 'member',
|
||||
'url' => array('url' =>'member/scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'member_index',
|
||||
'member' => 1,
|
||||
);
|
||||
//reset, and set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/member/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->action = 'member_index';
|
||||
$this->Controller->here = '/tests/member/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$this->Controller->scaffold = 'member';
|
||||
$this->Controller->constructClasses();
|
||||
|
||||
ob_start();
|
||||
$Scaffold = new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
|
||||
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
|
||||
//TODO: add testing for table generation
|
||||
$this->assertPattern('/<li><a href="\/member\/scaffold_mock\/add">New Scaffold Mock<\/a><\/li>/', $result);
|
||||
|
||||
Configure::write('Routing.prefixes', $_backAdmin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Scaffold Test class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller
|
||||
*/
|
||||
class ScaffoldTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* Controller property
|
||||
*
|
||||
* @var SecurityTestController
|
||||
* @access public
|
||||
*/
|
||||
var $Controller;
|
||||
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Controller =& new ScaffoldMockController();
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the correct Generation of Scaffold Params.
|
||||
* This ensures that the correct action and view will be generated
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testScaffoldParams() {
|
||||
$this->Controller->action = 'admin_edit';
|
||||
$this->Controller->here = '/admin/scaffold_mock/edit';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'admin_edit',
|
||||
'admin' => true,
|
||||
);
|
||||
//set router.
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/')));
|
||||
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
$Scaffold =& new TestScaffoldMock($this->Controller, $params);
|
||||
$result = $Scaffold->getParams();
|
||||
$this->assertEqual($result['action'], 'admin_edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the proper names and variable values are set by Scaffold
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testScaffoldVariableSetting() {
|
||||
$this->Controller->action = 'admin_edit';
|
||||
$this->Controller->here = '/admin/scaffold_mock/edit';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'admin_edit',
|
||||
'admin' => true,
|
||||
);
|
||||
//set router.
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/')));
|
||||
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
$Scaffold =& new TestScaffoldMock($this->Controller, $params);
|
||||
$result = $Scaffold->controller->viewVars;
|
||||
|
||||
$this->assertEqual($result['title_for_layout'], 'Scaffold :: Admin Edit :: Scaffold Mock');
|
||||
$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
|
||||
$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
|
||||
$this->assertEqual($result['modelClass'], 'ScaffoldMock');
|
||||
$this->assertEqual($result['primaryKey'], 'id');
|
||||
$this->assertEqual($result['displayField'], 'title');
|
||||
$this->assertEqual($result['singularVar'], 'scaffoldMock');
|
||||
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
|
||||
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
|
||||
}
|
||||
function getTests() {
|
||||
return array('start', 'startCase', 'testScaffoldChangingViewProperty', 'endCase', 'end');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that Scaffold overrides the view property even if its set to 'Theme'
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testScaffoldChangingViewProperty() {
|
||||
$this->Controller->action = 'edit';
|
||||
$this->Controller->theme = 'test_theme';
|
||||
$this->Controller->view = 'Theme';
|
||||
$this->Controller->constructClasses();
|
||||
$Scaffold =& new TestScaffoldMock($this->Controller, array());
|
||||
|
||||
$this->assertEqual($this->Controller->view, 'Scaffold');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that scaffold outputs flash messages when sessions are unset.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testScaffoldFlashMessages() {
|
||||
$this->Controller->action = 'edit';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(1),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'edit',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->data = array(
|
||||
'ScaffoldMock' => array(
|
||||
'id' => 1,
|
||||
'title' => 'New title',
|
||||
'body' => 'new body'
|
||||
)
|
||||
);
|
||||
$this->Controller->constructClasses();
|
||||
unset($this->Controller->Session);
|
||||
|
||||
ob_start();
|
||||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/Scaffold Mock has been updated/', $result);
|
||||
}
|
||||
/**
|
||||
* test that habtm relationship keys get added to scaffoldFields.
|
||||
*
|
||||
* @see http://code.cakephp.org/tickets/view/48
|
||||
* @return void
|
||||
*/
|
||||
function testHabtmFieldAdditionWithScaffoldForm() {
|
||||
$this->Controller->action = 'edit';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(1),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'edit',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
ob_start();
|
||||
$Scaffold = new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result);
|
||||
|
||||
$result = $Scaffold->controller->viewVars;
|
||||
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated', 'ScaffoldTag'));
|
||||
}
|
||||
/**
|
||||
* test that the proper names and variable values are set by Scaffold
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testEditScaffoldWithScaffoldFields() {
|
||||
$this->Controller = new ScaffoldMockControllerWithFields();
|
||||
$this->Controller->action = 'edit';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(1),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'edit',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
ob_start();
|
||||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user