2009-06-24 18:09:14 +00:00
|
|
|
<?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
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-06-24 18:09:14 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2009-06-24 18:09:14 +00:00
|
|
|
* @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')) {
|
2009-11-14 12:19:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case AppController
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller
|
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
class AppController extends Controller {
|
2009-11-14 12:19:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* components
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false));
|
2009-11-14 12:19:25 +00:00
|
|
|
/**
|
|
|
|
* helpers
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
class MergeVarComponent extends Object {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additional controller for testing
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
class MergeVariablesController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* name
|
|
|
|
*
|
|
|
|
* @var string
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $name = 'MergeVariables';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* uses
|
|
|
|
*
|
|
|
|
* @var arrays
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $uses = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeVarPlugin App Controller
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
class MergeVarPluginAppController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* components
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $components = array('Auth' => array('setting' => 'val', 'otherVal'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* helpers
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $helpers = array('Javascript');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MergePostsController
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
class MergePostsController extends MergeVarPluginAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* name
|
|
|
|
*
|
|
|
|
* @var string
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $name = 'MergePosts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* uses
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
var $uses = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Case for Controller Merging of Vars.
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
class ControllerMergeVarsTestCase extends CakeTestCase {
|
2009-10-31 18:55:04 +00:00
|
|
|
/**
|
|
|
|
* Skips the case if APP_CONTROLLER_EXISTS is defined
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-10-31 18:55:04 +00:00
|
|
|
function skip() {
|
|
|
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), 'APP_CONTROLLER_EXISTS cannot run. %s');
|
|
|
|
}
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* end test
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
function endTest() {
|
|
|
|
ClassRegistry::flush();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* test that component settings are not duplicated when merging component settings
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
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');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* test component merges with redeclared components
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
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');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* test merging of helpers array, ensure no duplication occurs
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
function testHelperSettingMergingNoDuplication() {
|
|
|
|
$Controller =& new MergeVariablesController();
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
|
|
|
$expected = array('MergeVar' => array('format' => 'html', 'terse'));
|
|
|
|
$this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-21 03:34:24 +00:00
|
|
|
/**
|
|
|
|
* Test that helpers declared in appcontroller come before those in the subclass
|
|
|
|
* orderwise
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testHelperOrderPrecedence() {
|
|
|
|
$Controller =& new MergeVariablesController();
|
|
|
|
$Controller->helpers = array('Custom', 'Foo' => array('something'));
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'MergeVar' => array('format' => 'html', 'terse'),
|
|
|
|
'Custom' => null,
|
|
|
|
'Foo' => array('something')
|
|
|
|
);
|
|
|
|
$this->assertIdentical($Controller->helpers, $expected, 'Order is incorrect. %s');
|
|
|
|
}
|
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* test merging of vars with plugin
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
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');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
$expected = array(
|
2010-11-21 03:34:24 +00:00
|
|
|
'MergeVar' => array('format' => 'html', 'terse'),
|
|
|
|
'Javascript' => null
|
2009-06-24 18:09:14 +00:00
|
|
|
);
|
|
|
|
$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');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* Ensure that __mergeVars is not being greedy and merging with
|
|
|
|
* AppController when you make an instance of Controller
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-06-24 18:09:14 +00:00
|
|
|
function testMergeVarsNotGreedy() {
|
|
|
|
$Controller =& new Controller();
|
|
|
|
$Controller->components = array();
|
|
|
|
$Controller->uses = array();
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
2010-01-14 04:48:57 +00:00
|
|
|
$this->assertFalse(isset($Controller->Session));
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
2010-05-10 22:07:49 +00:00
|
|
|
}
|