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
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-06-24 18:09:14 +00:00
|
|
|
*
|
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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2009-06-24 18:09:14 +00:00
|
|
|
*
|
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
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2009-06-24 18:09:14 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
2010-11-20 18:11:26 +00:00
|
|
|
|
2009-11-14 12:19:25 +00:00
|
|
|
/**
|
|
|
|
* Test case AppController
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller
|
|
|
|
*/
|
2010-12-16 04:49:54 +00:00
|
|
|
class MergeVarsAppController extends Controller {
|
2009-11-14 12:19:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* components
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-12-16 04:49:54 +00:00
|
|
|
public $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false));
|
2009-11-14 12:19:25 +00:00
|
|
|
/**
|
|
|
|
* helpers
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-12-16 04:49:54 +00:00
|
|
|
public $helpers = array('MergeVar' => array('format' => 'html', 'terse'));
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 04:49:54 +00:00
|
|
|
|
2009-06-24 18:09:14 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2010-12-16 04:49:54 +00:00
|
|
|
class MergeVariablesController extends MergeVarsAppController {
|
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
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $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
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2010-12-16 04:49:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parent for mergeVars
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_mergeParent = 'MergeVarsAppController';
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeVarPlugin App Controller
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-12-16 04:49:54 +00:00
|
|
|
class MergeVarPluginAppController extends MergeVarsAppController {
|
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
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $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
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $helpers = array('Javascript');
|
2010-12-16 04:49:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parent for mergeVars
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_mergeParent = 'MergeVarsAppController';
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $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
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Case for Controller Merging of Vars.
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-06-13 14:06:00 +00:00
|
|
|
class ControllerMergeVarsTest extends CakeTestCase {
|
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() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Controller = new MergeVariablesController();
|
2009-06-24 18:09:14 +00:00
|
|
|
$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() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Controller = new MergeVariablesController();
|
2009-06-24 18:09:14 +00:00
|
|
|
$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() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Controller = new MergeVariablesController();
|
2009-06-24 18:09:14 +00:00
|
|
|
$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() {
|
2010-12-16 04:49:54 +00:00
|
|
|
$Controller = new MergeVariablesController();
|
2010-11-21 03:34:24 +00:00
|
|
|
$Controller->helpers = array('Custom', 'Foo' => array('something'));
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'MergeVar' => array('format' => 'html', 'terse'),
|
|
|
|
'Custom' => null,
|
|
|
|
'Foo' => array('something')
|
|
|
|
);
|
2010-11-21 05:47:42 +00:00
|
|
|
$this->assertSame($Controller->helpers, $expected, 'Order is incorrect.');
|
2010-11-21 03:34:24 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Controller = new MergePostsController();
|
2009-06-24 18:09:14 +00:00
|
|
|
$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')
|
|
|
|
);
|
2010-11-20 18:11:26 +00:00
|
|
|
$this->assertEquals($expected, $Controller->components, 'Components are unexpected.');
|
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
|
|
|
);
|
2010-11-20 18:11:26 +00:00
|
|
|
$this->assertEquals($expected, $Controller->helpers, 'Helpers are unexpected.');
|
2009-06-24 18:09:14 +00:00
|
|
|
|
2010-11-13 04:05:44 +00:00
|
|
|
$Controller = new MergePostsController();
|
2009-06-24 18:09:14 +00:00
|
|
|
$Controller->components = array();
|
|
|
|
$Controller->plugin = 'MergeVarPlugin';
|
|
|
|
$Controller->constructClasses();
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'MergeVar' => array('flag', 'otherFlag', 'redirect' => false),
|
|
|
|
'Auth' => array('setting' => 'val', 'otherVal'),
|
|
|
|
);
|
2010-11-21 05:47:42 +00:00
|
|
|
$this->assertEquals($expected, $Controller->components, 'Components are unexpected.');
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
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() {
|
2010-12-16 04:49:54 +00:00
|
|
|
$Controller = new Controller();
|
2009-06-24 18:09:14 +00:00
|
|
|
$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
|
|
|
}
|