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
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-06-24 18:09:14 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2009-06-24 18:09:14 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2009-06-24 18:09:14 +00:00
|
|
|
* @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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
|
|
|
* @package Cake.Test.Case.Controller
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
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));
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeVar Component
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $Controller->components, 'Duplication of settings occurred. %s');
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $Controller->components, 'Merging of settings is wrong. %s');
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $Controller->helpers, 'Duplication of settings occurred. %s');
|
2009-06-24 18:09:14 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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')
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame($expected, $Controller->helpers, '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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
/**
|
2011-08-20 05:39:30 +00:00
|
|
|
* Ensure that _mergeControllerVars is not being greedy and merging with
|
2009-06-24 18:09:14 +00:00
|
|
|
* AppController when you make an instance of Controller
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
}
|
2013-05-24 08:16:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that $modelClass is correct even when Controller::$uses
|
|
|
|
* has been iterated, eg: by a Component, or event handlers.
|
|
|
|
*/
|
|
|
|
public function testMergeVarsModelClass() {
|
|
|
|
$Controller = new MergeVariablescontroller();
|
|
|
|
$Controller->uses = array('Test', 'TestAlias');
|
|
|
|
$lastModel = end($Controller->uses);
|
|
|
|
$Controller->constructClasses();
|
|
|
|
$this->assertEquals($Controller->uses[0], $Controller->modelClass);
|
|
|
|
}
|
|
|
|
|
2010-05-10 22:07:49 +00:00
|
|
|
}
|