Skip to content
Permalink
Browse files

Fix issue with $uses merging.

* Fix missing model names when a controller did not define $uses.
* Remove un-necessary test classes.
  • Loading branch information...
markstory committed Oct 13, 2012
1 parent ec17c0c commit 7fe7ce78a76051cb320fb421ac5ac511fccb9a02
@@ -544,15 +544,15 @@ protected function _mergeControllerVars() {
if ($this->uses === true) {
$this->uses = [$pluginDot . $this->modelClass];
}
$oldUses = $this->uses;
$this->_mergeVars(
['components', 'helpers', 'uses'],
[
'associative' => ['components', 'helpers'],
'reverse' => ['uses']
]
);
if ($this->uses === $oldUses && $this->modelClass) {
$usesProperty = new \ReflectionProperty($this, 'uses');
if ($this->uses && $usesProperty->getDeclaringClass()->getName() !== get_class($this)) {
array_unshift($this->uses, $pluginDot . $this->modelClass);
}
$this->uses = array_unique($this->uses);
@@ -12,7 +12,6 @@
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.TestApp.Controller
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
@@ -21,6 +20,7 @@
/**
* RequestActionController class
*
* @package Cake.Test.TestApp.Controller
*/
class RequestActionController extends AppController {
@@ -30,7 +30,7 @@ class RequestActionController extends AppController {
* @var array
* @access public
*/
public $uses = array('RequestActionPost');
public $uses = ['Post'];
/**
* test_request_action method
@@ -26,4 +26,19 @@ class Post extends AppModel {
public $name = 'Post';
/**
* find method
*
* @param string $type
* @param array $options
* @return void
*/
public function find($type = 'first', $options = array()) {
if ($type == 'popular') {
$conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
$options = Hash::merge($options, compact('conditions'));
return parent::find('all', $options);
}
return parent::find($type, $options);
}
}
@@ -47,7 +47,7 @@ class ControllerTestAppController extends Controller {
*
* @var array
*/
public $uses = array('ControllerPost');
public $uses = ['Post'];
/**
* components property
@@ -58,69 +58,6 @@ class ControllerTestAppController extends Controller {
}
/**
* ControllerPost class
*
* @package Cake.Test.Case.Controller
*/
class ControllerPost extends TestModel {
/**
* name property
*
* @var string 'ControllerPost'
*/
public $name = 'ControllerPost';
/**
* useTable property
*
* @var string 'posts'
*/
public $useTable = 'posts';
/**
* invalidFields property
*
* @var array
*/
public $invalidFields = array('name' => 'error_msg');
/**
* lastQuery property
*
* @var mixed null
*/
public $lastQuery = null;
/**
* beforeFind method
*
* @param mixed $query
* @return void
*/
public function beforeFind($query) {
$this->lastQuery = $query;
}
/**
* find method
*
* @param string $type
* @param array $options
* @return void
*/
public function find($type = 'first', $options = array()) {
if ($type == 'popular') {
$conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
$options = Hash::merge($options, compact('conditions'));
return parent::find('all', $options);
}
return parent::find($type, $options);
}
}
/**
* TestController class
*
@@ -216,13 +153,6 @@ class AnotherTestController extends ControllerTestAppController {
*/
public $name = 'AnotherTest';
/**
* uses property
*
* @var array
*/
public $uses = false;
}
/**
@@ -757,7 +687,7 @@ public function testMergeVars() {
];
$this->assertEquals($expected, $TestController->components);
$expected = array('Comment', 'ControllerPost');
$expected = array('Comment', 'Post');
$this->assertEquals(
$expected,
$TestController->uses,
@@ -767,13 +697,12 @@ public function testMergeVars() {
$TestController = new AnotherTestController($request);
$TestController->constructClasses();
$appVars = get_class_vars(__NAMESPACE__ . '\ControllerTestAppController');
$testVars = get_class_vars(__NAMESPACE__ . '\AnotherTestController');
$this->assertTrue(in_array('ControllerPost', $appVars['uses']));
$this->assertFalse($testVars['uses']);
$this->assertFalse(property_exists($TestController, 'ControllerPost'));
$this->assertEquals('AnotherTest', $TestController->modelClass);
$this->assertEquals(
['AnotherTest', 'Post'],
$TestController->uses,
'Incorrect uses when controller does not define $uses.'
);
}
/**
@@ -894,7 +823,7 @@ public function testValidateErrors() {
public function testValidateErrorsOnArbitraryModels() {
$TestController = new TestController();
$Post = new ControllerPost();
$Post = new \TestApp\Model\Post();
$Post->validate = array('title' => 'notEmpty');
$Post->set('title', '');
$result = $TestController->validateErrors($Post);

0 comments on commit 7fe7ce7

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