Skip to content

Commit

Permalink
Update controller tests.
Browse files Browse the repository at this point in the history
* Remove a number of test classes. Replace them with dynamic mocks.
* Skip more tests in DbAcl.
* Fix all failing tests except mergeVars related ones.
* Remove a number of deprecated features.
  • Loading branch information
markstory committed Oct 3, 2012
1 parent 6d0e033 commit 72bf1ca
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 447 deletions.
82 changes: 2 additions & 80 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -404,15 +404,6 @@ public function __isset($name) {
*/
public function __get($name) {
switch ($name) {
case 'base':
case 'here':
case 'webroot':
case 'data':
return $this->request->{$name};
case 'action':
return isset($this->request->params['action']) ? $this->request->params['action'] : '';
case 'params':
return $this->request;
case 'paginate':
return $this->Components->load('Paginator')->settings;
}
Expand All @@ -433,15 +424,6 @@ public function __get($name) {
*/
public function __set($name, $value) {
switch ($name) {
case 'base':
case 'here':
case 'webroot':
case 'data':
return $this->request->{$name} = $value;
case 'action':
return $this->request->params['action'] = $value;
case 'params':
return $this->request->params = $value;
case 'paginate':
return $this->Components->load('Paginator')->settings = $value;
}
Expand Down Expand Up @@ -955,10 +937,9 @@ public function render($view = null, $layout = null) {
$models = ClassRegistry::keys();
foreach ($models as $currentModel) {
$currentObject = ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model')) {
if ($currentObject instanceof \Cake\Model\Model) {
$className = get_class($currentObject);
list($plugin) = pluginSplit(App::location($className));
$this->request->params['models'][$currentObject->alias] = compact('plugin', 'className');
$this->request->params['models'][$currentObject->alias] = compact('className');
$View->validationErrors[$currentObject->alias] =& $currentObject->validationErrors;
}
}
Expand Down Expand Up @@ -1020,65 +1001,6 @@ public function flash($message, $url, $pause = 1, $layout = 'flash') {
$this->render(false, $layout);
}

/**
* Converts POST'ed form data to a model conditions array, suitable for use in a Model::find() call.
*
* @param array $data POST'ed data organized by model and field
* @param string|array $op A string containing an SQL comparison operator, or an array matching operators
* to fields
* @param string $bool SQL boolean operator: AND, OR, XOR, etc.
* @param boolean $exclusive If true, and $op is an array, fields not included in $op will not be
* included in the returned conditions
* @return array An array of model conditions
* @deprecated
*/
public function postConditions($data = array(), $op = null, $bool = 'AND', $exclusive = false) {
if (!is_array($data) || empty($data)) {
if (!empty($this->request->data)) {
$data = $this->request->data;
} else {
return null;
}
}
$cond = array();

if ($op === null) {
$op = '';
}

$arrayOp = is_array($op);
foreach ($data as $model => $fields) {
foreach ($fields as $field => $value) {
$key = $model . '.' . $field;
$fieldOp = $op;
if ($arrayOp) {
if (array_key_exists($key, $op)) {
$fieldOp = $op[$key];
} elseif (array_key_exists($field, $op)) {
$fieldOp = $op[$field];
} else {
$fieldOp = false;
}
}
if ($exclusive && $fieldOp === false) {
continue;
}
$fieldOp = strtoupper(trim($fieldOp));
if ($fieldOp === 'LIKE') {
$key = $key . ' LIKE';
$value = '%' . $value . '%';
} elseif ($fieldOp && $fieldOp != '=') {
$key = $key . ' ' . $fieldOp;
}
$cond[$key] = $value;
}
}
if ($bool != null && strtoupper($bool) != 'AND') {
$cond = array($bool => $cond);
}
return $cond;
}

/**
* Handles automatic pagination of model records.
*
Expand Down
9 changes: 0 additions & 9 deletions lib/Cake/Test/TestApp/Controller/AppController.php
@@ -1,12 +1,5 @@
<?php
/**
* Application level Controller
*
* This file is application-wide controller file. You can put all
* application-wide controller-related methods here.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -15,7 +8,6 @@
*
* @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)
*/
Expand All @@ -30,7 +22,6 @@
* will inherit them.
*
* @package Cake.Controller
* @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
*/
class AppController extends Controller {
}
27 changes: 27 additions & 0 deletions lib/Cake/Test/TestApp/Controller/CommentsController.php
@@ -0,0 +1,27 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.TestApp.Controller
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace TestApp\Controller;

use TestApp\Controller\AppController;

/**
* ControllerPostsController class
*
* @package Cake.Test.Case.Controller
*/
class CommentsController extends AppController {

protected $_mergeParent = 'ControllerTestAppController';
}
8 changes: 2 additions & 6 deletions lib/Cake/Test/TestCase/Controller/Component/Acl/DbAclTest.php
@@ -1,9 +1,5 @@
<?php
/**
* DbAclTest file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -12,12 +8,11 @@
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Acl
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

namespace Cake\Test\TestCase\Controller\Component\Acl;

use Cake\Controller\ComponentCollection;
use Cake\Controller\Component\AclComponent;
use Cake\Controller\Component\Acl\DbAcl;
Expand Down Expand Up @@ -213,6 +208,7 @@ class DbAclTest extends TestCase {
*/
public function setUp() {
parent::setUp();
$this->markTestIncomplete('DbAcl will not work until models do.');
Configure::write('Acl.classname', __NAMESPACE__ . '\DbAclTwoTest');
Configure::write('Acl.database', 'test');
$Collection = new ComponentCollection();
Expand Down

0 comments on commit 72bf1ca

Please sign in to comment.