Skip to content
Permalink
Browse files

Update Controller to use MergeVariablesTrait

Remove a test case that handled the many edge cases with controller
merge vars as those cases should be covered by tests for the trait now.
  • Loading branch information...
markstory committed Oct 13, 2012
1 parent 933a7e6 commit f1080891df3465e77a860275f7d8a083ac103d7a
@@ -8,12 +8,12 @@
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Controller;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Object;
@@ -27,6 +27,7 @@
use Cake\Routing\Router;
use Cake\Utility\ClassRegistry;
use Cake\Utility\Inflector;
use Cake\Utility\MergeVariablesTrait;
use Cake\View\View;
/**
@@ -63,6 +64,8 @@
*/
class Controller extends Object implements EventListener {
use MergeVariablesTrait;
/**
* The name of this controller. Controller names are plural, named after the model they manipulate.
*
@@ -298,15 +301,6 @@ class Controller extends Object implements EventListener {
*/
public $validationErrors = null;
/**
* The class name of the parent class you wish to merge with.
* Typically this is AppController, but you may wish to merge vars with a different
* parent class.
*
* @var string
*/
protected $_mergeParent = null;
/**
* Instance of the Cake\Event\EventManager this controller is using
* to dispatch inner events.
@@ -539,71 +533,32 @@ protected function _getScaffold(Request $request) {
* @return void
*/
protected function _mergeControllerVars() {
$pluginController = $pluginDot = null;
$mergeParent = is_subclass_of($this, $this->_mergeParent);
$pluginVars = array();
$appVars = array();
$pluginDot = null;
if (!empty($this->plugin)) {
$pluginController = Plugin::getNamespace($this->plugin) . '\Controller\Controller';
if (!is_subclass_of($this, $pluginController)) {
$pluginController = null;
}
$pluginDot = $this->plugin . '.';
}
if ($pluginController) {
$merge = array('components', 'helpers');
$this->_mergeVars($merge, $pluginController);
}
if ($mergeParent || !empty($pluginController)) {
$appVars = get_class_vars($this->_mergeParent);
$merge = array('components', 'helpers');
$this->_mergeVars($merge, $this->_mergeParent, true);
}
if ($this->uses === null) {
$this->uses = false;
}
if ($this->uses === false) {
$this->uses = [];
$this->modelClass = '';
}
if ($this->uses === true) {
$this->uses = array($pluginDot . $this->modelClass);
}
if (isset($appVars['uses']) && $appVars['uses'] === $this->uses) {
$oldUses = $this->uses;
$this->_mergeVars(
['components', 'helpers', 'uses'],
[
'associative' => ['components', 'helpers'],
'reverse' => ['uses']
]
);
if ($this->uses === $oldUses) {
array_unshift($this->uses, $pluginDot . $this->modelClass);
}
if ($pluginController) {
$pluginVars = get_class_vars($pluginController);
}
if ($this->uses !== false) {
$this->_mergeUses($pluginVars);
$this->_mergeUses($appVars);
} else {
$this->uses = array();
$this->modelClass = '';
}
}
/**
* Helper method for merging the $uses property together.
*
* Merges the elements not already in $this->uses into
* $this->uses.
*
* @param array $merge The data to merge in.
* @return void
*/
protected function _mergeUses($merge) {
if (!isset($merge['uses'])) {
return;
}
if ($merge['uses'] === true) {
return;
}
$this->uses = array_merge(
$this->uses,
array_diff($merge['uses'], $this->uses)
);
$this->uses = array_unique($this->uses);
}
/**
@@ -23,5 +23,4 @@
*/
class CommentsController extends AppController {
protected $_mergeParent = 'ControllerTestAppController';
}
@@ -26,7 +26,7 @@
*
* @package Cake.Test.Case
*/
class AllControllersTest extends \PHPUnit_Framework_TestSuite {
class AllControllerTest extends \PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
@@ -40,7 +40,6 @@ public static function suite() {
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller/ScaffoldTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller/PagesControllerTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller/ComponentTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller/ControllerMergeVarsTest.php');
return $suite;
}
}
}

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit f108089

Please sign in to comment.
You can’t perform that action at this time.