From 9e36d1bedc168e4b16233826b540520f8fc7766f Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 00:23:59 -0400 Subject: [PATCH 01/20] Fixing whitespacing on aco_fixture. Adding tests to AclShell::grant() Refactoring __getParams() --- cake/console/libs/acl.php | 22 +++++----------- cake/tests/cases/console/libs/acl.test.php | 15 +++++++++++ cake/tests/fixtures/aco_fixture.php | 30 +++++++++++----------- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index 18d73fe7c..1b31ac5d3 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -530,23 +530,15 @@ class AclShell extends Shell { * @access private */ function __getParams() { - $aro = ife(is_numeric($this->args[0]), intval($this->args[0]), $this->args[0]); - $aco = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]); - - if (is_string($aro) && preg_match('/^([\w]+)\.(.*)$/', $aro, $matches)) { - $aro = array( - 'model' => $matches[1], - 'foreign_key' => $matches[2], - ); + $aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0]; + $aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1]; + + if (is_string($aro)) { + $aro = $this->parseIdentifier($aro); } - - if (is_string($aco) && preg_match('/^([\w]+)\.(.*)$/', $aco, $matches)) { - $aco = array( - 'model' => $matches[1], - 'foreign_key' => $matches[2], - ); + if (is_string($aco)) { + $aco = $this->parseIdentifier($aco); } - $action = null; if (isset($this->args[2])) { $action = $this->args[2]; diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index c65f02b16..010c0eea0 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -217,5 +217,20 @@ class AclShellTest extends CakeTestCase { $result = $Aro->read(null, 4); $this->assertEqual($result['Aro']['parent_id'], null); } + +/** + * test grant + * + * @return void + **/ + function testGrant() { + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true)); + $this->Task->grant(); + + $node = $this->Task->Acl->Aro->read(null, 4); + $this->assertFalse(empty($node['Aco'][0])); + $this->assertEqual($node['Aco'][0]['Permission']['_create'], 1); + } } ?> \ No newline at end of file diff --git a/cake/tests/fixtures/aco_fixture.php b/cake/tests/fixtures/aco_fixture.php index 57e0172dd..e13f8745c 100644 --- a/cake/tests/fixtures/aco_fixture.php +++ b/cake/tests/fixtures/aco_fixture.php @@ -49,13 +49,13 @@ class AcoFixture extends CakeTestFixture { * @access public */ var $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), - 'model' => array('type' => 'string', 'default' => ''), + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), + 'model' => array('type' => 'string', 'default' => ''), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), - 'alias' => array('type' => 'string', 'default' => ''), - 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), - 'rght' => array('type' => 'integer', 'length' => 10, 'null' => true) + 'alias' => array('type' => 'string', 'default' => ''), + 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), + 'rght' => array('type' => 'integer', 'length' => 10, 'null' => true) ); /** @@ -65,15 +65,15 @@ class AcoFixture extends CakeTestFixture { * @access public */ var $records = array( - array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18), - array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9), - array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6), - array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5), - array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8), - array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17), - array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14), - array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13), - array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16), + array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18), + array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9), + array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6), + array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5), + array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8), + array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2','lft' => 10, 'rght' => 17), + array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14), + array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13), + array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16), ); } From cd9dd97eff90e6abe862c729d9ea2d642e46c3d6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 00:37:53 -0400 Subject: [PATCH 02/20] Adding test cases for AclShell --- cake/tests/cases/console/libs/acl.test.php | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 010c0eea0..14d480787 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -232,5 +232,43 @@ class AclShellTest extends CakeTestCase { $this->assertFalse(empty($node['Aco'][0])); $this->assertEqual($node['Aco'][0]['Permission']['_create'], 1); } + +/** + * test dent + * + * @return void + **/ + function testDeny() { + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission denied/'), true)); + $this->Task->deny(); + + $node = $this->Task->Acl->Aro->read(null, 4); + $this->assertFalse(empty($node['Aco'][0])); + $this->assertEqual($node['Aco'][0]['Permission']['_create'], -1); + } + +/** + * test checking allowed and denied perms + * + * @return void + **/ + function testCheck() { + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*'); + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/not allowed/'), true)); + $this->Task->check(); + + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); + $this->Task->expectAt(1, 'out', array(new PatternExpectation('/Permission granted/'), true)); + $this->Task->grant(); + + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); + $this->Task->expectAt(2, 'out', array(new PatternExpectation('/is allowed/'), true)); + $this->Task->check(); + + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*'); + $this->Task->expectAt(3, 'out', array(new PatternExpectation('/not allowed/'), true)); + $this->Task->check(); + } } ?> \ No newline at end of file From 3aa56e82c9a0a4eaad25a8e948ab12dcb9f850e8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 12:20:12 -0400 Subject: [PATCH 03/20] Fixing typo. --- cake/tests/cases/console/libs/acl.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 14d480787..095895562 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -234,7 +234,7 @@ class AclShellTest extends CakeTestCase { } /** - * test dent + * test deny * * @return void **/ From e6b32e21adeaaa96103911992dd09c7bbd2d853c Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 23:13:48 -0400 Subject: [PATCH 04/20] Adding tests for getPath and inherit. Refactoring the output of getPath --- cake/console/libs/acl.php | 37 +++++++++++++++++----- cake/tests/cases/console/libs/acl.test.php | 34 ++++++++++++++++++-- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index 1b31ac5d3..f6ab50e1d 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -1,10 +1,6 @@ _checkArgs(2, 'getPath'); $this->checkNodeType(); extract($this->__dataVars()); - $id = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]); + $identifier = $this->parseIdentifier($this->args[1]); + + $id = $this->_getNodeId($class, $identifier); $nodes = $this->Acl->{$class}->getPath($id); + if (empty($nodes)) { - $this->error(sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), __("No tree returned.", true)); + $this->error( + sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), + __("No tree returned.", true) + ); } for ($i = 0; $i < count($nodes); $i++) { - $this->out(str_repeat(' ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n"); + $this->_outputNode($class, $nodes[$i], $i); + } + } + +/** + * Outputs a single node, Either using the alias or Model.key + * + * @param string $class Class name that is being used. + * @param array $node Array of node information. + * @param integer $indent indent level. + * @return void + * @access protected + **/ + function _outputNode($class, $node, $indent) { + $indent = str_repeat(' ', $indent); + $data = $node[$class]; + if ($data['alias']) { + $this->out($indent . "[" . $data['id'] . "] " . $data['alias']); + } else { + $this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']); } } diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 095895562..5d7ccfc15 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -1,6 +1,4 @@ Task->expectAt(3, 'out', array(new PatternExpectation('/not allowed/'), true)); $this->Task->check(); } + +/** + * test inherit and that it 0's the permission fields. + * + * @return void + **/ + function testInherit() { + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true)); + $this->Task->grant(); + + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all'); + $this->Task->expectAt(1, 'out', array(new PatternExpectation('/permission inherited/i'), true)); + $this->Task->inherit(); + + $node = $this->Task->Acl->Aro->read(null, 4); + $this->assertFalse(empty($node['Aco'][0])); + $this->assertEqual($node['Aco'][0]['Permission']['_create'], 0); + } + +/** + * test getting the path for an aro/aco + * + * @return void + **/ + function testGetPath() { + $this->Task->args = array('aro', 'AuthUser.2'); + $this->Task->expectAt(0, 'out', array('[1] ROOT')); + $this->Task->expectAt(1, 'out', array(' [2] admins')); + $this->Task->expectAt(2, 'out', array(' [4] Elrond')); + $this->Task->getPath(); + } } ?> \ No newline at end of file From eda74d08b4b3f842ebffe1a272679d836d1b2312 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 23:41:25 -0400 Subject: [PATCH 05/20] Updating view() to use node references. updating test cases to use new formating. --- cake/console/libs/acl.php | 43 +++++++++++----------- cake/tests/cases/console/libs/acl.test.php | 12 +++--- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index f6ab50e1d..a6e872220 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -54,7 +54,7 @@ class AclShell extends Shell { * @var string * @access public */ - var $dataSource = 'default'; + var $connection = 'default'; /** * Contains tasks to load and instantiate @@ -70,10 +70,8 @@ class AclShell extends Shell { * @access public */ function startup() { - $this->dataSource = 'default'; - - if (isset($this->params['datasource'])) { - $this->dataSource = $this->params['datasource']; + if (isset($this->params['connection'])) { + $this->connection = $this->params['connection']; } if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) { @@ -227,6 +225,8 @@ class AclShell extends Shell { __("No tree returned.", true) ); } + $this->out(__('Path:', true)); + $this->hr(); for ($i = 0; $i < count($nodes); $i++) { $this->_outputNode($class, $nodes[$i], $i); } @@ -324,12 +324,14 @@ class AclShell extends Shell { $this->_checkArgs(1, 'view'); $this->checkNodeType(); extract($this->__dataVars()); + if (isset($this->args[1]) && !is_null($this->args[1])) { - $key = ife(is_numeric($this->args[1]), $secondary_id, 'alias'); + $key = is_numeric($this->args[1]) ? $secondary_id : 'alias'; $conditions = array($class . '.' . $key => $this->args[1]); } else { $conditions = null; } + $nodes = $this->Acl->{$class}->find('all', array('conditions' => $conditions, 'order' => 'lft ASC')); if (empty($nodes)) { if (isset($this->args[1])) { @@ -340,8 +342,10 @@ class AclShell extends Shell { } $this->out($class . " tree:"); $this->hr(); + $stack = array(); $last = null; + foreach ($nodes as $n) { $stack[] = $n; if (!empty($last)) { @@ -355,14 +359,10 @@ class AclShell extends Shell { } } } - $last = $n[$class]['rght']; - $count = count($stack); - $indent = str_repeat(' ', $count); - if ($n[$class]['alias']) { - $this->out($indent . "[" . $n[$class]['id'] . "]" . $n[$class]['alias']."\n"); - } else { - $this->out($indent . "[" . $n[$class]['id'] . "]" . $n[$class]['model'] . '.' . $n[$class]['foreign_key'] . "\n"); - } + $last = $n[$class]['rght']; + $count = count($stack); + + $this->_outputNode($class, $n, $count); } $this->hr(); } @@ -409,7 +409,7 @@ class AclShell extends Shell { "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), - 'setparent' => "setParent aro|aco \n" . + 'setparent' => "setParent aro|aco \n" . "\t" . __("Moves the ACL object specified by beneath", true) . "\n" . "\t" . __("the parent ACL object specified by .", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . @@ -422,26 +422,26 @@ class AclShell extends Shell { "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), - 'check' => "check [] " . __("or", true) . " all\n" . + 'check' => "check [] " . __("or", true) . " all\n" . "\t" . __("Use this command to check ACL permissions.", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), - 'grant' => "grant [] " . __("or", true) . " all\n" . + 'grant' => "grant [] " . __("or", true) . " all\n" . "\t" . __("Use this command to grant ACL permissions. Once executed, the ARO", true) . "\n" . "\t" . __("specified (and its children, if any) will have ALLOW access to the", true) . "\n" . "\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), - 'deny' => "deny []" . __("or", true) . " all\n" . + 'deny' => "deny []" . __("or", true) . " all\n" . "\t" . __("Use this command to deny ACL permissions. Once executed, the ARO", true) . "\n" . "\t" . __("specified (and its children, if any) will have DENY access to the", true) . "\n" . "\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), - 'inherit' => "inherit []" . __("or", true) . " all\n" . + 'inherit' => "inherit []" . __("or", true) . " all\n" . "\t" . __("Use this command to force a child ARO object to inherit its", true) . "\n" . "\t" . __("permissions settings from its parent.", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . @@ -449,7 +449,8 @@ class AclShell extends Shell { 'view' => "view aro|aco []\n" . "\t" . __("The view command will return the ARO or ACO tree.", true) . "\n" . - "\t" . __("The optional id/alias parameter allows you to return\n\tonly a portion of the requested tree.", true) . "\n" . + "\t" . __("The optional node parameter allows you to return", true) . "\n" . + "\t" . __("only a portion of the requested tree.", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), @@ -482,7 +483,7 @@ class AclShell extends Shell { return false; } if ($this->args[0] != 'aco' && $this->args[0] != 'aro') { - $this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[1]), __('Please specify which ACL object type you wish to create.', true)); + $this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[1]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"', true)); } } diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 5d7ccfc15..a956b3ccb 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -125,9 +125,9 @@ class AclShellTest extends CakeTestCase { $this->Task->args[0] = 'aro'; $this->Task->expectAt(0, 'out', array('Aro tree:')); - $this->Task->expectAt(1, 'out', array(new PatternExpectation('/\[1\]ROOT/'))); - $this->Task->expectAt(3, 'out', array(new PatternExpectation('/\[3\]Gandalf/'))); - $this->Task->expectAt(5, 'out', array(new PatternExpectation('/\[5\]MyModel.2/'))); + $this->Task->expectAt(1, 'out', array(new PatternExpectation('/\[1\] ROOT/'))); + $this->Task->expectAt(3, 'out', array(new PatternExpectation('/\[3\] Gandalf/'))); + $this->Task->expectAt(5, 'out', array(new PatternExpectation('/\[5\] MyModel.2/'))); $this->Task->view(); } @@ -295,9 +295,9 @@ class AclShellTest extends CakeTestCase { **/ function testGetPath() { $this->Task->args = array('aro', 'AuthUser.2'); - $this->Task->expectAt(0, 'out', array('[1] ROOT')); - $this->Task->expectAt(1, 'out', array(' [2] admins')); - $this->Task->expectAt(2, 'out', array(' [4] Elrond')); + $this->Task->expectAt(1, 'out', array('[1] ROOT')); + $this->Task->expectAt(2, 'out', array(' [2] admins')); + $this->Task->expectAt(3, 'out', array(' [4] Elrond')); $this->Task->getPath(); } } From 8d351d90b329af0a80d50f3ad9a7c5958a5d32e5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 23:43:01 -0400 Subject: [PATCH 06/20] Updating file headers. --- cake/console/libs/acl.php | 7 ++----- cake/tests/cases/console/libs/acl.test.php | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index a6e872220..bc6bb220b 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -5,20 +5,17 @@ * PHP versions 4 and 5 * * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @package cake * @subpackage cake.cake.console.libs * @since CakePHP(tm) v 1.2.0.5012 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ App::import('Component', 'Acl'); diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index a956b3ccb..64d5cad79 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -5,20 +5,17 @@ * PHP versions 4 and 5 * * CakePHP : Rapid Development Framework (http://www.cakephp.org) - * Copyright 2006-2008, Cake Software Foundation, Inc. + * Copyright 2006-2009, Cake Software Foundation, Inc. * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource - * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @copyright Copyright 2006-2009, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package cake * @subpackage cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.0.7726 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ App::import('Shell', 'Shell', false); From ff04c7668a44a03191cb69b54fbfbb3619c97e4d Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 6 Aug 2009 15:59:47 -0300 Subject: [PATCH 07/20] Fixing DS for Windows --- cake/tests/cases/console/libs/tasks/db_config.test.php | 2 +- cake/tests/cases/console/libs/tasks/fixture.test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/db_config.test.php b/cake/tests/cases/console/libs/tasks/db_config.test.php index 2c93225f7..a637c8403 100644 --- a/cake/tests/cases/console/libs/tasks/db_config.test.php +++ b/cake/tests/cases/console/libs/tasks/db_config.test.php @@ -85,7 +85,7 @@ class DbConfigTaskTest extends CakeTestCase { $this->Task->Dispatch =& $this->Dispatcher; $this->Task->Dispatch->shellPaths = App::path('shells'); - $this->Task->params['working'] = rtrim(APP, '/'); + $this->Task->params['working'] = rtrim(APP, DS); $this->Task->databaseClassName = 'TEST_DATABASE_CONFIG'; } diff --git a/cake/tests/cases/console/libs/tasks/fixture.test.php b/cake/tests/cases/console/libs/tasks/fixture.test.php index 4301f71c4..71873155f 100644 --- a/cake/tests/cases/console/libs/tasks/fixture.test.php +++ b/cake/tests/cases/console/libs/tasks/fixture.test.php @@ -96,10 +96,10 @@ class FixtureTaskTest extends CakeTestCase { * @return void **/ function testConstruct() { - $this->Dispatch->params['working'] = '/my/path'; + $this->Dispatch->params['working'] = DS . 'my' . DS . 'path'; $Task =& new FixtureTask($this->Dispatch); - $expected = '/my/path/tests/fixtures/'; + $expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS; $this->assertEqual($Task->path, $expected); } From ae89e709d2b48df183e49ff3a53077a5c55d7d2d Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 6 Aug 2009 18:14:25 -0300 Subject: [PATCH 08/20] Refactoring extract shell. Supporting use of $foo['bar'] as $count. --- cake/console/libs/tasks/extract.php | 105 ++++-------------- .../cases/console/libs/tasks/extract.test.php | 12 ++ cake/tests/test_app/views/pages/extract.ctp | 11 ++ 3 files changed, 46 insertions(+), 82 deletions(-) create mode 100644 cake/tests/test_app/views/pages/extract.ctp diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index eda49614b..73bf03125 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -280,13 +280,13 @@ class ExtractTask extends Shell{ } } unset($allTokens); - $this->basic(); - $this->basic('__c'); - $this->extended(); - $this->extended('__dc', 2); - $this->extended('__n', 0, true); - $this->extended('__dn', 2, true); - $this->extended('__dcn', 4, true); + $this->__parse('__', array('singular')); + $this->__parse('__n', array('singular', 'plural')); + $this->__parse('__d', array('domain', 'singular')); + $this->__parse('__c', array('singular')); + $this->__parse('__dc', array('domain', 'singular')); + $this->__parse('__dn', array('domain', 'singular', 'plural')); + $this->__parse('__dcn', array('domain', 'singular', 'plural')); } $this->__buildFiles(); $this->__writeFiles(); @@ -294,50 +294,13 @@ class ExtractTask extends Shell{ } /** - * Will parse __(), __c() functions + * Parse tokens * * @param string $functionName Function name that indicates translatable string (e.g: '__') + * @param array $map Array containing what variables it will find (e.g: domain, singular, plural) * @access public */ - function basic($functionName = '__') { - $count = 0; - $tokenCount = count($this->__tokens); - - while (($tokenCount - $count) > 3) { - list($countToken, $parenthesis, $middle, $right) = array($this->__tokens[$count], $this->__tokens[$count + 1], $this->__tokens[$count + 2], $this->__tokens[$count + 3]); - if (!is_array($countToken)) { - $count++; - continue; - } - - list($type, $string, $line) = $countToken; - if (($type == T_STRING) && ($string == $functionName) && ($parenthesis == '(')) { - - if (in_array($right, array(')', ',')) - && (is_array($middle) && ($middle[0] == T_CONSTANT_ENCAPSED_STRING))) { - - if ($this->__oneFile === true) { - $this->__strings[$this->__formatString($middle[1])][$this->__file][] = $line; - } else { - $this->__strings[$this->__file][$this->__formatString($middle[1])][] = $line; - } - } else { - $this->__markerError($this->__file, $line, $functionName, $count); - } - } - $count++; - } - } - -/** - * Will parse __d(), __dc(), __n(), __dn(), __dcn() - * - * @param string $functionName Function name that indicates translatable string (e.g: '__') - * @param integer $shift Number of parameters to shift to find translateable string - * @param boolean $plural Set to true if function supports plural format, false otherwise - * @access public - */ - function extended($functionName = '__d', $shift = 0, $plural = false) { + function __parse($functionName, $map) { $count = 0; $tokenCount = count($this->__tokens); @@ -362,50 +325,28 @@ class ExtractTask extends Shell{ $position++; } - if ($plural) { - $end = $position + $shift + 7; - - if ($this->__tokens[$position + $shift + 5] === ')') { - $end = $position + $shift + 5; + $mapCount = count($map); + $strings = array(); + while (count($strings) < $mapCount && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { + if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $strings[] = $this->__tokens[$position][1]; } - - if (empty($shift)) { - list($singular, $firstComma, $plural, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$end]); - $condition = ($seoncdComma == ','); - } else { - list($domain, $firstComma, $singular, $seoncdComma, $plural, $comma3, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$position + 4], $this->__tokens[$position + 5], $this->__tokens[$end]); - $condition = ($comma3 == ','); - } - $condition = $condition && - (is_array($singular) && ($singular[0] == T_CONSTANT_ENCAPSED_STRING)) && - (is_array($plural) && ($plural[0] == T_CONSTANT_ENCAPSED_STRING)); - } else { - if ($this->__tokens[$position + $shift + 5] === ')') { - $comma = $this->__tokens[$position + $shift + 3]; - $end = $position + $shift + 5; - } else { - $comma = null; - $end = $position + $shift + 3; - } - - list($domain, $firstComma, $text, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $comma, $this->__tokens[$end]); - $condition = ($seoncdComma == ',' || $seoncdComma === null) && - (is_array($domain) && ($domain[0] == T_CONSTANT_ENCAPSED_STRING)) && - (is_array($text) && ($text[0] == T_CONSTANT_ENCAPSED_STRING)); + $position++; } - if (($endParenthesis == ')') && $condition) { + if ($mapCount == count($strings)) { + extract(array_combine($map, $strings)); if ($this->__oneFile === true) { - if ($plural) { - $this->__strings[$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][$this->__file][] = $line; + if (isset($plural)) { + $this->__strings[$this->__formatString($singular) . "\0" . $this->__formatString($plural)][$this->__file][] = $line; } else { - $this->__strings[$this->__formatString($text[1])][$this->__file][] = $line; + $this->__strings[$this->__formatString($singular)][$this->__file][] = $line; } } else { if ($plural) { - $this->__strings[$this->__file][$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][] = $line; + $this->__strings[$this->__file][$this->__formatString($singular) . "\0" . $this->__formatString($plural)][] = $line; } else { - $this->__strings[$this->__file][$this->__formatString($text[1])][] = $line; + $this->__strings[$this->__file][$this->__formatString($singular)][] = $line; } } } else { diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index dbeb7f80c..89394485e 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -107,6 +107,7 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/'; $this->assertPattern($pattern, $result); + // home.ctp $pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/'; $this->assertPattern($pattern, $result); $pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/'; @@ -134,6 +135,17 @@ class ExtractTaskTest extends CakeTestCase { $pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s'; $this->assertPattern($pattern, $result); + // extract.ctp + $pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/'; + $this->assertPattern($pattern, $result); + $pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/'; + $this->assertPattern($pattern, $result); + + $pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/'; + $this->assertPattern($pattern, $result); + $pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/'; + $this->assertPattern($pattern, $result); + $Folder = new Folder($path); $Folder->delete(); } diff --git a/cake/tests/test_app/views/pages/extract.ctp b/cake/tests/test_app/views/pages/extract.ctp new file mode 100644 index 000000000..1244223f3 --- /dev/null +++ b/cake/tests/test_app/views/pages/extract.ctp @@ -0,0 +1,11 @@ + 10); + +// Plural +__n('You have %d new message.', 'You have %d new messages.', $count); +__n('You deleted %d message.', 'You deleted %d messages.', $messages['count']); + +// Domain Plural +__dn('domain', 'You have %d new message (domain).', 'You have %d new messages (domain).', '10'); +__dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages (domain).', $messages['count']); \ No newline at end of file From 2cc8ae631e8a4e78c299e75a37fb757886b4e8ad Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 7 Aug 2009 08:32:27 -0400 Subject: [PATCH 09/20] Fixing notice error when non-existant node type is used. Fixing view() so you can view a slice of the tree. --- cake/console/libs/acl.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index bc6bb220b..769b282ee 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -1,6 +1,6 @@ error( - sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), + sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), __("No tree returned.", true) ); } @@ -322,14 +322,24 @@ class AclShell extends Shell { $this->checkNodeType(); extract($this->__dataVars()); - if (isset($this->args[1]) && !is_null($this->args[1])) { - $key = is_numeric($this->args[1]) ? $secondary_id : 'alias'; - $conditions = array($class . '.' . $key => $this->args[1]); + if (isset($this->args[1])) { + $identity = $this->parseIdentifier($this->args[1]); + + $topNode = $this->Acl->{$class}->find('first', array( + 'conditions' => array($class . '.id' => $this->_getNodeId($class, $identity)) + )); + + $nodes = $this->Acl->{$class}->find('all', array( + 'conditions' => array( + $class . '.lft >=' => $topNode[$class]['lft'], + $class . '.lft <=' => $topNode[$class]['rght'] + ), + 'order' => $class . '.lft ASC' + )); } else { - $conditions = null; + $nodes = $this->Acl->{$class}->find('all', array('order' => $class . '.lft ASC')); } - $nodes = $this->Acl->{$class}->find('all', array('conditions' => $conditions, 'order' => 'lft ASC')); if (empty($nodes)) { if (isset($this->args[1])) { $this->error(sprintf(__("%s not found", true), $this->args[1]), __("No tree returned.", true)); @@ -447,7 +457,7 @@ class AclShell extends Shell { 'view' => "view aro|aco []\n" . "\t" . __("The view command will return the ARO or ACO tree.", true) . "\n" . "\t" . __("The optional node parameter allows you to return", true) . "\n" . - "\t" . __("only a portion of the requested tree.", true) . "\n" . + "\t" . __("only a portion of the requested tree.", true) . "\n" . "\t" . __("For more detailed parameter usage info,", true) . "\n" . "\t" . __("see help for the 'create' command.", true), @@ -480,7 +490,7 @@ class AclShell extends Shell { return false; } if ($this->args[0] != 'aco' && $this->args[0] != 'aro') { - $this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[1]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"', true)); + $this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[0]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"', true)); } } @@ -551,7 +561,7 @@ class AclShell extends Shell { function __getParams() { $aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0]; $aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1]; - + if (is_string($aro)) { $aro = $this->parseIdentifier($aro); } From c305b7a410978850f265d62591565f5352630608 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 7 Aug 2009 08:37:31 -0400 Subject: [PATCH 10/20] Adding tests to AclShell::view() --- cake/tests/cases/console/libs/acl.test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 64d5cad79..a7e83c2e2 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -128,6 +128,21 @@ class AclShellTest extends CakeTestCase { $this->Task->view(); } + +/** + * test view with an argument + * + * @return void + **/ + function testViewWithArgument() { + $this->Task->args = array('aro', 'admins'); + $this->Task->expectAt(0, 'out', array('Aro tree:')); + $this->Task->expectAt(1, 'out', array(' [2] admins')); + $this->Task->expectAt(2, 'out', array(' [3] Gandalf')); + $this->Task->expectAt(3, 'out', array(' [4] Elrond')); + $this->Task->view(); + } + /** * test the method that splits model.foreign key. and that it returns an array. * @@ -297,5 +312,6 @@ class AclShellTest extends CakeTestCase { $this->Task->expectAt(3, 'out', array(' [4] Elrond')); $this->Task->getPath(); } + } ?> \ No newline at end of file From 32754c426198fb8f264e706fea740a3161a08fb8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 7 Aug 2009 22:10:39 -0400 Subject: [PATCH 11/20] Adding test case for SchemaShell --- cake/tests/cases/console/libs/schema.test.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 cake/tests/cases/console/libs/schema.test.php diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php new file mode 100644 index 000000000..36e761c71 --- /dev/null +++ b/cake/tests/cases/console/libs/schema.test.php @@ -0,0 +1,80 @@ +Dispatcher =& new TestSchemaShellMockShellDispatcher(); + $this->Task =& new MockSchemaShell($this->Dispatcher); + $this->Task->Dispatch =& $this->Dispatcher; + } + +/** + * endTest method + * + * @return void + * @access public + */ + function endTest() { + ClassRegistry::flush(); + } + + +} +?> \ No newline at end of file From 3c46b51b7ff1f2a85e7553bf1fa2c1e931b5a1eb Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 7 Aug 2009 22:19:40 -0400 Subject: [PATCH 12/20] Adding test cases for startup() --- cake/console/libs/schema.php | 4 +-- cake/tests/cases/console/libs/schema.test.php | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 60d959721..adc480e39 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -1,6 +1,4 @@ Task->startup(); + $this->assertTrue(isset($this->Task->Schema)); + $this->assertTrue(is_a($this->Task->Schema, 'CakeSchema')); + $this->assertEqual($this->Task->Schema->name, 'App'); + $this->assertEqual($this->Task->Schema->file, 'schema.php'); + unset($this->Task->Schema); + $this->Task->params = array( + 'name' => 'TestSchema' + ); + $this->Task->startup(); + $this->assertEqual($this->Task->Schema->name, 'TestSchema'); + $this->assertEqual($this->Task->Schema->file, 'test_schema.php'); + $this->assertEqual($this->Task->Schema->connection, 'default'); + $this->assertEqual($this->Task->Schema->path, APP . 'config' . DS . 'schema'); + + unset($this->Task->Schema); + $this->Task->params = array( + 'file' => 'other_file.php', + 'connection' => 'test_suite', + 'path' => '/test/path' + ); + $this->Task->startup(); + $this->assertEqual($this->Task->Schema->name, 'App'); + $this->assertEqual($this->Task->Schema->file, 'other_file.php'); + $this->assertEqual($this->Task->Schema->connection, 'test_suite'); + $this->assertEqual($this->Task->Schema->path, '/test/path'); + } } ?> \ No newline at end of file From 12b94756d02a474e3d5417572dafa14a4497fd74 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 7 Aug 2009 22:28:28 -0400 Subject: [PATCH 13/20] Adding tests for view() --- cake/tests/cases/console/libs/schema.test.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index d868aeb5d..6cb63688c 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -41,7 +41,7 @@ Mock::generatePartial( ); Mock::generatePartial( 'SchemaShell', 'MockSchemaShell', - array('in', 'out', 'hr', 'createFile', 'error', 'err') + array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop') ); /** @@ -52,6 +52,7 @@ Mock::generatePartial( */ class SchemaShellTest extends CakeTestCase { + var $fixtures = array('core.article', 'core.user'); /** * startTest method * @@ -108,5 +109,29 @@ class SchemaShellTest extends CakeTestCase { $this->assertEqual($this->Task->Schema->connection, 'test_suite'); $this->assertEqual($this->Task->Schema->path, '/test/path'); } + +/** + * Test View - and that it dumps the schema file to stdout + * + * @return void + **/ + function testView() { + $this->Task->startup(); + $this->Task->Schema->path = APP . 'config' . DS . 'schema'; + $this->Task->params['file'] = 'i18n.php'; + $this->Task->expectOnce('_stop'); + $this->Task->expectOnce('out'); + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/class i18nSchema extends CakeSchema/'))); + $this->Task->view(); + } + +/** + * undocumented function + * + * @return void + **/ + function () { + + } } ?> \ No newline at end of file From 496555108485ff2ad542f72be61abb17e3f3e125 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 8 Aug 2009 23:00:40 -0400 Subject: [PATCH 14/20] Adding test cases for dump() --- cake/tests/cases/console/libs/schema.test.php | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 6cb63688c..91bec2162 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -126,12 +126,49 @@ class SchemaShellTest extends CakeTestCase { } /** - * undocumented function + * test dumping a schema file. * * @return void **/ - function () { - + function testDump() { + $this->Task->params = array('name' => 'i18n'); + $this->Task->startup(); + $this->Task->Schema->path = APP . 'config' . DS . 'schema'; + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i'))); + $this->Task->dump(); + } + +/** + * test dump() with sql file generation + * + * @return void + **/ + function testDumpWithFileWriting() { + //copy file. + $file =& new File(APP . 'config' . DS . 'schema' . DS . 'i18n.php'); + $contents = $file->read(); + $file =& new File(TMP . 'tests' . DS . 'i18n.php'); + $file->write($contents); + + $this->Task->params = array('name' => 'i18n'); + $this->Task->args = array('write'); + $this->Task->startup(); + $this->Task->Schema->path = TMP . 'tests'; + $this->Task->dump(); + + $sql =& new File(TMP . 'tests' . DS . 'i18n.sql'); + $contents = $sql->read(); + $this->assertPattern('/DROP TABLE/', $contents); + $this->assertPattern('/CREATE TABLE `i18n`/', $contents); + $this->assertPattern('/id/', $contents); + $this->assertPattern('/model/', $contents); + $this->assertPattern('/field/', $contents); + $this->assertPattern('/locale/', $contents); + $this->assertPattern('/foreign_key/', $contents); + $this->assertPattern('/content/', $contents); + + $sql->delete(); + $file->delete(); } } ?> \ No newline at end of file From a27575382b58797d757d87d6a68841a03afd0079 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 8 Aug 2009 23:21:24 -0400 Subject: [PATCH 15/20] Adding tests for generate() from jperras --- cake/tests/cases/console/libs/schema.test.php | 103 +++++++++++------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 91bec2162..45125d684 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -14,11 +14,12 @@ * @copyright Copyright 2006-2009, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @subpackage cake.tests.cases.console.libs.Shells * @since CakePHP v 1.3 * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ App::import('Shell', 'Shell', false); +App::import('Model', 'CakeSchema', false); if (!defined('DISABLE_AUTO_DISPATCH')) { define('DISABLE_AUTO_DISPATCH', true); @@ -44,11 +45,13 @@ Mock::generatePartial( array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop') ); +Mock::generate('CakeSchema', 'MockSchemaCakeSchema'); + /** * SchemaShellTest class * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @subpackage cake.tests.cases.console.libs.Shells */ class SchemaShellTest extends CakeTestCase { @@ -61,8 +64,8 @@ class SchemaShellTest extends CakeTestCase { */ function startTest() { $this->Dispatcher =& new TestSchemaShellMockShellDispatcher(); - $this->Task =& new MockSchemaShell($this->Dispatcher); - $this->Task->Dispatch =& $this->Dispatcher; + $this->Shell =& new MockSchemaShell($this->Dispatcher); + $this->Shell->Dispatch =& $this->Dispatcher; } /** @@ -81,33 +84,33 @@ class SchemaShellTest extends CakeTestCase { * @return void **/ function testStartup() { - $this->Task->startup(); - $this->assertTrue(isset($this->Task->Schema)); - $this->assertTrue(is_a($this->Task->Schema, 'CakeSchema')); - $this->assertEqual($this->Task->Schema->name, 'App'); - $this->assertEqual($this->Task->Schema->file, 'schema.php'); + $this->Shell->startup(); + $this->assertTrue(isset($this->Shell->Schema)); + $this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema')); + $this->assertEqual($this->Shell->Schema->name, 'App'); + $this->assertEqual($this->Shell->Schema->file, 'schema.php'); - unset($this->Task->Schema); - $this->Task->params = array( + unset($this->Shell->Schema); + $this->Shell->params = array( 'name' => 'TestSchema' ); - $this->Task->startup(); - $this->assertEqual($this->Task->Schema->name, 'TestSchema'); - $this->assertEqual($this->Task->Schema->file, 'test_schema.php'); - $this->assertEqual($this->Task->Schema->connection, 'default'); - $this->assertEqual($this->Task->Schema->path, APP . 'config' . DS . 'schema'); + $this->Shell->startup(); + $this->assertEqual($this->Shell->Schema->name, 'TestSchema'); + $this->assertEqual($this->Shell->Schema->file, 'test_schema.php'); + $this->assertEqual($this->Shell->Schema->connection, 'default'); + $this->assertEqual($this->Shell->Schema->path, APP . 'config' . DS . 'schema'); - unset($this->Task->Schema); - $this->Task->params = array( + unset($this->Shell->Schema); + $this->Shell->params = array( 'file' => 'other_file.php', 'connection' => 'test_suite', 'path' => '/test/path' ); - $this->Task->startup(); - $this->assertEqual($this->Task->Schema->name, 'App'); - $this->assertEqual($this->Task->Schema->file, 'other_file.php'); - $this->assertEqual($this->Task->Schema->connection, 'test_suite'); - $this->assertEqual($this->Task->Schema->path, '/test/path'); + $this->Shell->startup(); + $this->assertEqual($this->Shell->Schema->name, 'App'); + $this->assertEqual($this->Shell->Schema->file, 'other_file.php'); + $this->assertEqual($this->Shell->Schema->connection, 'test_suite'); + $this->assertEqual($this->Shell->Schema->path, '/test/path'); } /** @@ -116,13 +119,13 @@ class SchemaShellTest extends CakeTestCase { * @return void **/ function testView() { - $this->Task->startup(); - $this->Task->Schema->path = APP . 'config' . DS . 'schema'; - $this->Task->params['file'] = 'i18n.php'; - $this->Task->expectOnce('_stop'); - $this->Task->expectOnce('out'); - $this->Task->expectAt(0, 'out', array(new PatternExpectation('/class i18nSchema extends CakeSchema/'))); - $this->Task->view(); + $this->Shell->startup(); + $this->Shell->Schema->path = APP . 'config' . DS . 'schema'; + $this->Shell->params['file'] = 'i18n.php'; + $this->Shell->expectOnce('_stop'); + $this->Shell->expectOnce('out'); + $this->Shell->expectAt(0, 'out', array(new PatternExpectation('/class i18nSchema extends CakeSchema/'))); + $this->Shell->view(); } /** @@ -131,11 +134,11 @@ class SchemaShellTest extends CakeTestCase { * @return void **/ function testDump() { - $this->Task->params = array('name' => 'i18n'); - $this->Task->startup(); - $this->Task->Schema->path = APP . 'config' . DS . 'schema'; - $this->Task->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i'))); - $this->Task->dump(); + $this->Shell->params = array('name' => 'i18n'); + $this->Shell->startup(); + $this->Shell->Schema->path = APP . 'config' . DS . 'schema'; + $this->Shell->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i'))); + $this->Shell->dump(); } /** @@ -144,17 +147,16 @@ class SchemaShellTest extends CakeTestCase { * @return void **/ function testDumpWithFileWriting() { - //copy file. $file =& new File(APP . 'config' . DS . 'schema' . DS . 'i18n.php'); $contents = $file->read(); $file =& new File(TMP . 'tests' . DS . 'i18n.php'); $file->write($contents); - $this->Task->params = array('name' => 'i18n'); - $this->Task->args = array('write'); - $this->Task->startup(); - $this->Task->Schema->path = TMP . 'tests'; - $this->Task->dump(); + $this->Shell->params = array('name' => 'i18n'); + $this->Shell->args = array('write'); + $this->Shell->startup(); + $this->Shell->Schema->path = TMP . 'tests'; + $this->Shell->dump(); $sql =& new File(TMP . 'tests' . DS . 'i18n.sql'); $contents = $sql->read(); @@ -170,5 +172,24 @@ class SchemaShellTest extends CakeTestCase { $sql->delete(); $file->delete(); } + +/** + * test generate with snapshot generation + * + * @return void + */ + function testGenerateSnaphot() { + $this->Shell->path = TMP; + $this->Shell->params['file'] = 'schema.php'; + $this->Shell->args = array('snapshot'); + $this->Shell->Schema =& new MockSchemaCakeSchema(); + $this->Shell->Schema->setReturnValue('read', array('schema data')); + $this->Shell->Schema->setReturnValue('write', true); + + $this->Shell->Schema->expectOnce('read'); + $this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema_1.php'))); + + $this->Shell->generate(); + } } ?> \ No newline at end of file From f70b97f4cbf8c3be7fc74781eaba449eddc2ab2c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 8 Aug 2009 23:46:00 -0400 Subject: [PATCH 16/20] Adding more tests for generate(). --- cake/console/libs/schema.php | 2 +- cake/tests/cases/console/libs/schema.test.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index adc480e39..af2ed4b8a 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -137,7 +137,7 @@ class SchemaShell extends Shell { $snapshot = true; $result = $this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's'); if ($result === 'q') { - $this->_stop(); + return $this->_stop(); } if ($result === 'o') { $snapshot = false; diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 45125d684..14c6c4ee1 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -191,5 +191,48 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->generate(); } + +/** + * test generate without a snapshot. + * + * @return void + **/ + function testGenerateNoOverwrite() { + touch(TMP . 'schema.php'); + $this->Shell->params['file'] = 'schema.php'; + $this->Shell->args = array(); + + $this->Shell->setReturnValue('in', 'q'); + $this->Shell->Schema =& new MockSchemaCakeSchema(); + $this->Shell->Schema->path = TMP; + $this->Shell->Schema->expectNever('read'); + + $result = $this->Shell->generate(); + unlink(TMP . 'schema.php'); + } + +/** + * test generate with overwriting of the schema files. + * + * @return void + **/ + function testGenerateOverwrite() { + touch(TMP . 'schema.php'); + $this->Shell->params['file'] = 'schema.php'; + $this->Shell->args = array(); + + $this->Shell->setReturnValue('in', 'o'); + $this->Shell->expectAt(1, 'out', array(new PatternExpectation('/Schema file:\s[a-z\.]+\sgenerated/'))); + $this->Shell->Schema =& new MockSchemaCakeSchema(); + $this->Shell->Schema->path = TMP; + $this->Shell->Schema->setReturnValue('read', array('schema data')); + $this->Shell->Schema->setReturnValue('write', true); + + $this->Shell->Schema->expectOnce('read'); + $this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema.php'))); + + $this->Shell->generate(); + unlink(TMP . 'schema.php'); + } } ?> \ No newline at end of file From de87fbd484d69500d12ac536dc38d8fafea6bade Mon Sep 17 00:00:00 2001 From: AD7six Date: Sun, 9 Aug 2009 12:54:41 +0200 Subject: [PATCH 17/20] updating console output to use a more concise format typing "cake" on the command line will now output ... Available Shells: acl [CORE] bake [CORE] i18n [CORE] testsuite [CORE] api [CORE] console [CORE] schema [CORE] To run a command, type 'cake shell_name [args]' ... Auto adjusting the width on *nix systems --- cake/console/cake.php | 68 +++++++++++++++++++------- cake/tests/cases/console/cake.test.php | 53 ++++++++++---------- 2 files changed, 78 insertions(+), 43 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index ab4d6c891..e3e1c85ba 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -27,6 +27,7 @@ if (!defined('E_DEPRECATED')) { define('E_DEPRECATED', 8192); } + /** * Shell dispatcher * @@ -402,6 +403,7 @@ class ShellDispatcher { $this->stderr($title . "\n" . $message . "\n"); return false; } + /** * Get shell to use, either plugin shell or application shell * @@ -606,28 +608,58 @@ class ShellDispatcher { $this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"); $this->stdout("\nAvailable Shells:"); - $_shells = array(); + $shellList = array(); foreach ($this->shellPaths as $path) { - if (is_dir($path)) { - $shells = App::objects('file', $path); - $path = str_replace(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, 'CORE' . DS, $path); - $path = str_replace(APP, 'APP' . DS, $path); - $path = str_replace(ROOT, 'ROOT', $path); - $path = rtrim($path, DS); - $this->stdout("\n " . $path . ":"); - if (empty($shells)) { - $this->stdout("\t - none"); - } else { - sort($shells); - foreach ($shells as $shell) { - - if ($shell !== 'shell.php') { - $this->stdout("\t " . str_replace('.php', '', $shell)); - } - } + if (!is_dir($path)) { + continue; + } + $shells = App::objects('file', $path); + if (empty($shells)) { + continue; + } + if (preg_match('@plugins[\\\/]([^\\\/]*)@', $path, $matches)) { + $type = Inflector::camelize($matches[1]); + } elseif (preg_match('@([^\\\/]*)[\\\/]vendors[\\\/]@', $path, $matches)) { + $type = $matches[1]; + } elseif (strpos($path, CAKE_CORE_INCLUDE_PATH . DS . 'cake') === 0) { + $type = 'CORE'; + } else { + $type = 'app'; + } + foreach ($shells as $shell) { + if ($shell !== 'shell.php') { + $shell = str_replace('.php', '', $shell); + $shellList[$shell][$type] = $type; } } } + if ($shellList) { + ksort($shellList); + if (DS === '/') { + $width = exec('tput cols') - 2; + } + if (empty($width)) { + $width = 80; + } + $columns = max(1, floor($width / 30)); + $rows = ceil(count($shellList) / $columns); + + foreach($shellList as $shell => $types) { + sort($types); + $shellList[$shell] = str_pad($shell . ' [' . implode ($types, ', ') . ']', $width / $columns); + } + $out = array_chunk($shellList, $rows); + for($i = 0; $i < $rows; $i++) { + $row = ''; + for($j = 0; $j < $columns; $j++) { + if (!isset($out[$j][$i])) { + continue; + } + $row .= $out[$j][$i]; + } + $this->stdout(" " . $row); + } + } $this->stdout("\nTo run a command, type 'cake shell_name [args]'"); $this->stdout("To get help on a specific command, type 'cake shell_name help'"); } diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index de7d8793e..ef725f168 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.php @@ -36,8 +36,8 @@ if (!class_exists('ShellDispatcher')) { ob_end_clean(); } - require_once CONSOLE_LIBS . 'shell.php'; + /** * TestShellDispatcher class * @@ -85,6 +85,7 @@ class TestShellDispatcher extends ShellDispatcher { * @access public */ var $TestShell; + /** * _initEnvironment method * @@ -138,6 +139,7 @@ class TestShellDispatcher extends ShellDispatcher { $this->stopped = 'Stopped with status: ' . $status; return $status; } + /** * getShell * @@ -148,6 +150,7 @@ class TestShellDispatcher extends ShellDispatcher { function getShell($plugin = null) { return $this->_getShell($plugin); } + /** * _getShell * @@ -439,7 +442,6 @@ class ShellDispatcherTest extends CakeTestCase { $Dispatcher->parseParams($params); $this->assertEqual($expected, $Dispatcher->params); - $params = array( 'cake.php', '-working', @@ -510,6 +512,7 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->getShell('test_plugin'); $this->assertIsA($result, 'ExampleShell'); } + /** * Verify correct dispatch of Shell subclasses with a main method * @@ -600,6 +603,7 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertFalse($result); } + /** * Verify correct dispatch of Shell subclasses without a main method * @@ -671,6 +675,7 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertFalse($result); } + /** * Verify correct dispatch of custom classes with a main method * @@ -750,6 +755,7 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertFalse($result); } + /** * Verify correct dispatch of custom classes without a main method * @@ -819,6 +825,7 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertFalse($result); } + /** * Verify that a task is called instead of the shell if the first arg equals * the name of the task @@ -867,6 +874,7 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertTrue($result); } + /** * Verify shifting of arguments * @@ -906,39 +914,34 @@ class ShellDispatcherTest extends CakeTestCase { function testHelpCommand() { $Dispatcher =& new TestShellDispatcher(); - $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin(\\\|\/)vendors(\\\|\/)shells:"; - $expected .= "\n\t example"; - $expected .= "\n/"; + $expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/"; $this->assertPattern($expected, $Dispatcher->stdout); - $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin_two(\\\|\/)vendors(\\\|\/)shells:"; - $expected .= "\n\t example"; - $expected .= "\n\t welcome"; - $expected .= "\n/"; + $expected = "/welcome \[.*TestPluginTwo.*\]/"; $this->assertPattern($expected, $Dispatcher->stdout); - $expected = "/ APP(\\\|\/)vendors(\\\|\/)shells:"; - $expected .= "\n/"; + $expected = "/acl \[.*CORE.*\]/"; $this->assertPattern($expected, $Dispatcher->stdout); - $expected = "/ ROOT(\\\|\/)vendors(\\\|\/)shells:"; - $expected .= "\n/"; + $expected = "/api \[.*CORE.*\]/"; $this->assertPattern($expected, $Dispatcher->stdout); - $expected = "/ CORE(\\\|\/)console(\\\|\/)libs:"; - $expected .= "\n\t acl"; - $expected .= "\n\t api"; - $expected .= "\n\t bake"; - $expected .= "\n\t console"; - $expected .= "\n\t i18n"; - $expected .= "\n\t schema"; - $expected .= "\n\t testsuite"; - $expected .= "\n/"; + $expected = "/bake \[.*CORE.*\]/"; $this->assertPattern($expected, $Dispatcher->stdout); - $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:"; - $expected .= "\n\t sample"; - $expected .= "\n/"; + $expected = "/console \[.*CORE.*\]/"; + $this->assertPattern($expected, $Dispatcher->stdout); + + $expected = "/i18n \[.*CORE.*\]/"; + $this->assertPattern($expected, $Dispatcher->stdout); + + $expected = "/schema \[.*CORE.*\]/"; + $this->assertPattern($expected, $Dispatcher->stdout); + + $expected = "/testsuite \[.*CORE.*\]/"; + $this->assertPattern($expected, $Dispatcher->stdout); + + $expected = "/sample \[.*test_app.*\]/"; $this->assertPattern($expected, $Dispatcher->stdout); } } From dd1075a330509d9cd6c3004a110186fc87785698 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 10 Aug 2009 21:38:09 -0400 Subject: [PATCH 18/20] Adding i18n to schema shell. --- cake/console/libs/schema.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index af2ed4b8a..c7de8cb52 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -232,7 +232,7 @@ class SchemaShell extends Shell { */ function run() { if (!isset($this->args[0])) { - $this->err('command not found'); + $this->err(__('Command not found', true)); $this->_stop(); } @@ -279,7 +279,7 @@ class SchemaShell extends Shell { $this->__update($Schema, $table); break; default: - $this->err(__('command not found', true)); + $this->err(__('Command not found', true)); $this->_stop(); } } @@ -313,7 +313,7 @@ class SchemaShell extends Shell { $this->out(array_keys($drop)); if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) { - $this->out('Dropping table(s).'); + $this->out(__('Dropping table(s).', true)); $this->__run($drop, 'drop', $Schema); } @@ -321,7 +321,7 @@ class SchemaShell extends Shell { $this->out(array_keys($create)); if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) { - $this->out('Creating table(s).'); + $this->out(__('Creating table(s).', true)); $this->__run($create, 'create', $Schema); } @@ -337,7 +337,7 @@ class SchemaShell extends Shell { function __update($Schema, $table = null) { $db =& ConnectionManager::getDataSource($this->Schema->connection); - $this->out('Comparing Database to Schema...'); + $this->out(__('Comparing Database to Schema...', true)); $Old = $this->Schema->read(); $compare = $this->Schema->compare($Old, $Schema); @@ -415,7 +415,8 @@ class SchemaShell extends Shell { * @access public */ function help() { - $this->out("The Schema Shell generates a schema object from \n\t\tthe database and updates the database from the schema."); + $this->out("The Schema Shell generates a schema object from"); + $this->out("the database and updates the database from the schema."); $this->hr(); $this->out("Usage: cake schema ..."); $this->hr(); From 74448e4deeee28d2cf9d0eee9f3ba8fbcab40be4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 10 Aug 2009 21:54:29 -0400 Subject: [PATCH 19/20] Adding test cases for run create in Schema shell. --- cake/console/libs/schema.php | 4 +- cake/tests/cases/console/libs/schema.test.php | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index c7de8cb52..ef94fd8e1 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -122,7 +122,7 @@ class SchemaShell extends Shell { * @access public */ function generate() { - $this->out('Generating Schema...'); + $this->out(__('Generating Schema...', true)); $options = array(); if (isset($this->params['f'])) { $options = array('models' => false); @@ -280,7 +280,7 @@ class SchemaShell extends Shell { break; default: $this->err(__('Command not found', true)); - $this->_stop(); + $this->_stop(); } } diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 14c6c4ee1..5b7ae176d 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -234,5 +234,50 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->generate(); unlink(TMP . 'schema.php'); } + +/** + * Test schema run create with no table args. + * + * @return void + **/ + function testRunCreateNoArgs() { + $this->Shell->params = array( + 'connection' => 'test_suite', + 'name' => 'i18n', + 'path' => APP . 'config' . DS . 'schema' + ); + $this->Shell->args = array('create'); + $this->Shell->startup(); + $this->Shell->setReturnValue('in', 'y'); + $this->Shell->run(); + + $db =& ConnectionManager::getDataSource('test_suite'); + $sources = $db->listSources(); + $this->assertTrue(in_array('i18n', $sources)); + } + +/** + * Test schema run create with no table args. + * + * @return void + **/ + function testRunCreateWithTableArgs() { + $this->Shell->params = array( + 'connection' => 'test_suite', + 'name' => 'DbAcl', + 'path' => APP . 'config' . DS . 'schema' + ); + $this->Shell->args = array('create', 'acos'); + $this->Shell->startup(); + $this->Shell->setReturnValue('in', 'y'); + $this->Shell->run(); + + $db =& ConnectionManager::getDataSource('test_suite'); + $sources = $db->listSources(); + $this->assertTrue(in_array('acos', $sources)); + $this->assertFalse(in_array('aros', $sources)); + $this->assertFalse(in_array('aros_acos', $sources)); + } + } ?> \ No newline at end of file From e306b65908f7d119bdc0c629da46fae709f7b79e Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Aug 2009 12:08:33 -0400 Subject: [PATCH 20/20] Updating View test case to work with updated API's --- cake/tests/cases/libs/view/view.test.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 98f1caa2f..562aff8d3 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -254,8 +254,11 @@ class ViewTest extends CakeTestCase { function startTest() { App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), - 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) - )); + 'views' => array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS + ) + ), true); } /** @@ -303,8 +306,10 @@ class ViewTest extends CakeTestCase { $this->Controller->action = 'index'; $View = new TestView($this->Controller); - Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)); - Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + )); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'tests' . DS .'index.ctp'; $result = $View->getViewFileName('index');