From bed7767258969698b04dcd31ad98f0f70b9938fb Mon Sep 17 00:00:00 2001 From: PhpNut Date: Wed, 17 Nov 2010 14:02:35 -0600 Subject: [PATCH 1/5] Removing __cache property that can be altered outside of the class definition. Adding __resetCache() as a replacement for checking if cache should be reset and written. --- cake/libs/configure.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 7166546b8..8e254266e 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -579,14 +579,6 @@ class App extends Object { */ var $return = false; -/** - * Determines if $__maps and $__paths cache should be written. - * - * @var boolean - * @access private - */ - var $__cache = false; - /** * Holds key/value pairs of $type => file path. * @@ -836,7 +828,7 @@ class App extends Object { } if ($cache === true) { - $_this->__cache = true; + $_this->__resetCache(true); } $_this->__objects[$name] = $objects; } @@ -932,7 +924,7 @@ class App extends Object { return true; } else { $_this->__remove($name . $ext['class'], $type, $plugin); - $_this->__cache = true; + $_this->__resetCache(true); } } if (!empty($search)) { @@ -963,7 +955,7 @@ class App extends Object { } if ($directory !== null) { - $_this->__cache = true; + $_this->__resetCache(true); $_this->__map($directory . $file, $name . $ext['class'], $type, $plugin); $_this->__overload($type, $name . $ext['class'], $parent); @@ -1292,6 +1284,21 @@ class App extends Object { } return $items; } + +/** + * Determines if $__maps and $__paths cache should be reset. + * + * @param boolean $reset + * @return boolean + * @access private + */ + function __resetCache($reset = null) { + static $cache = array(); + if (!$cache && $reset === true) { + $cache = true; + } + return $cache; + } /** * Object destructor. @@ -1302,7 +1309,7 @@ class App extends Object { * @access private */ function __destruct() { - if ($this->__cache) { + if ($this->__resetCache() === true) { $core = App::core('cake'); unset($this->__paths[rtrim($core[0], DS)]); Cache::write('dir_map', array_filter($this->__paths), '_cake_core_'); @@ -1310,4 +1317,4 @@ class App extends Object { Cache::write('object_map', $this->__objects, '_cake_core_'); } } -} +} \ No newline at end of file From 82d46067ab67c2027f6d469b392955fd019a1383 Mon Sep 17 00:00:00 2001 From: PhpNut Date: Wed, 17 Nov 2010 15:00:27 -0600 Subject: [PATCH 2/5] Corrected doc comment. --- cake/libs/configure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 8e254266e..e3e8e7835 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -1286,7 +1286,7 @@ class App extends Object { } /** - * Determines if $__maps and $__paths cache should be reset. + * Determines if $__maps, $__objects and $__paths cache should be reset. * * @param boolean $reset * @return boolean From e0a8ffe8a34937ab261b442505863d502987f0aa Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Nov 2010 13:26:30 -0500 Subject: [PATCH 3/5] Applying patch from 'jmccaffrey' to fix issues on windows where virtual machine paths would not be correctly handled. Fixes #1254 --- cake/libs/folder.php | 4 ++-- cake/tests/cases/libs/folder.test.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cake/libs/folder.php b/cake/libs/folder.php index 3886633ed..97de64e8c 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -258,7 +258,7 @@ class Folder extends Object { * @static */ function isWindowsPath($path) { - return (bool)preg_match('/^[A-Z]:\\\\/i', $path); + return (preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\'); } /** @@ -270,7 +270,7 @@ class Folder extends Object { * @static */ function isAbsolute($path) { - return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path)); + return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\'); } /** diff --git a/cake/tests/cases/libs/folder.test.php b/cake/tests/cases/libs/folder.test.php index 61d0478e6..3b214642a 100644 --- a/cake/tests/cases/libs/folder.test.php +++ b/cake/tests/cases/libs/folder.test.php @@ -366,6 +366,7 @@ class FolderTest extends CakeTestCase { $this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome')); $this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome')); $this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome')); + $this->assertTrue(Folder::isWindowsPath('\\\\vmware-host\\Shared Folders\\file')); } /** @@ -387,6 +388,7 @@ class FolderTest extends CakeTestCase { $this->assertTrue(Folder::isAbsolute('C:\\cake')); $this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file')); $this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file')); + $this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file')); } /** From 6d9b000aeeffd17811a0c774ce02638b6360fc7e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Nov 2010 22:34:24 -0500 Subject: [PATCH 4/5] Changing how mergeVars are handled, so the difference of app/current is used as a base. Also fixing issues where passing settings to helpers in AppController could result in them not being correctly merged. Thanks to hashmich for the partial patch. Fixes #1183 --- cake/libs/controller/controller.php | 8 +++---- .../cases/libs/controller/controller.test.php | 2 +- .../controller/controller_merge_vars.test.php | 23 +++++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 6b75ea324..4a9827975 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -430,7 +430,7 @@ class Controller extends Object { foreach ($merge as $var) { if (!empty($appVars[$var]) && is_array($this->{$var})) { - if ($var === 'components') { + if ($var !== 'uses') { $normal = Set::normalize($this->{$var}); $app = Set::normalize($appVars[$var]); if ($app !== $normal) { @@ -438,7 +438,7 @@ class Controller extends Object { } } else { $this->{$var} = Set::merge( - $this->{$var}, array_diff($appVars[$var], $this->{$var}) + array_diff($appVars[$var], $this->{$var}), $this->{$var} ); } } @@ -456,7 +456,7 @@ class Controller extends Object { foreach ($merge as $var) { if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) { - if ($var === 'components') { + if ($var !== 'uses') { $normal = Set::normalize($this->{$var}); $app = Set::normalize($appVars[$var]); if ($app !== $normal) { @@ -464,7 +464,7 @@ class Controller extends Object { } } else { $this->{$var} = Set::merge( - $this->{$var}, array_diff($appVars[$var], $this->{$var}) + array_diff($appVars[$var], $this->{$var}), $this->{$var} ); } } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 3fe277939..d73672814 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -1149,7 +1149,7 @@ class ControllerTest extends CakeTestCase { ? array_merge($appVars['uses'], $testVars['uses']) : $testVars['uses']; - $this->assertEqual(count(array_diff($TestController->helpers, $helpers)), 0); + $this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->helpers), Set::normalize($helpers))), 0); $this->assertEqual(count(array_diff($TestController->uses, $uses)), 0); $this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0); diff --git a/cake/tests/cases/libs/controller/controller_merge_vars.test.php b/cake/tests/cases/libs/controller/controller_merge_vars.test.php index c85e5312b..b98aff1ff 100644 --- a/cake/tests/cases/libs/controller/controller_merge_vars.test.php +++ b/cake/tests/cases/libs/controller/controller_merge_vars.test.php @@ -185,6 +185,25 @@ class ControllerMergeVarsTestCase extends CakeTestCase { $this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s'); } +/** + * Test that helpers declared in appcontroller come before those in the subclass + * orderwise + * + * @return void + */ + function testHelperOrderPrecedence() { + $Controller =& new MergeVariablesController(); + $Controller->helpers = array('Custom', 'Foo' => array('something')); + $Controller->constructClasses(); + + $expected = array( + 'MergeVar' => array('format' => 'html', 'terse'), + 'Custom' => null, + 'Foo' => array('something') + ); + $this->assertIdentical($Controller->helpers, $expected, 'Order is incorrect. %s'); + } + /** * test merging of vars with plugin * @@ -204,8 +223,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase { $this->assertEqual($Controller->components, $expected, 'Components are unexpected %s'); $expected = array( - 'Javascript', - 'MergeVar' => array('format' => 'html', 'terse') + 'MergeVar' => array('format' => 'html', 'terse'), + 'Javascript' => null ); $this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s'); From ef3cb0e50cc365f248dbf3d731afc28a514bbd55 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Nov 2010 22:46:55 -0500 Subject: [PATCH 5/5] Adding tests for Set::normalize() --- cake/tests/cases/libs/set.test.php | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 7d0f47e27..ee75ba1a9 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -2988,4 +2988,50 @@ class SetTest extends CakeTestCase { ); $this->assertEqual($result, $expected); } + +/** + * test normalization + * + * @return void + */ + function testNormalizeStrings() { + $result = Set::normalize('one,two,three'); + $expected = array('one' => null, 'two' => null, 'three' => null); + $this->assertEqual($expected, $result); + + $result = Set::normalize('one two three', true, ' '); + $expected = array('one' => null, 'two' => null, 'three' => null); + $this->assertEqual($expected, $result); + + $result = Set::normalize('one , two , three ', true, ',', true); + $expected = array('one' => null, 'two' => null, 'three' => null); + $this->assertEqual($expected, $result); + } + +/** + * test normalizing arrays + * + * @return void + */ + function testNormalizeArrays() { + $result = Set::normalize(array('one', 'two', 'three')); + $expected = array('one' => null, 'two' => null, 'three' => null); + $this->assertEqual($expected, $result); + + $result = Set::normalize(array('one', 'two', 'three'), false); + $expected = array('one', 'two', 'three'); + $this->assertEqual($expected, $result); + + $result = Set::normalize(array('one' => 1, 'two' => 2, 'three' => 3, 'four'), false); + $expected = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => null); + $this->assertEqual($expected, $result); + + $result = Set::normalize(array('one' => 1, 'two' => 2, 'three' => 3, 'four')); + $expected = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => null); + $this->assertEqual($expected, $result); + + $result = Set::normalize(array('one' => array('a', 'b', 'c' => 'cee'), 'two' => 2, 'three')); + $expected = array('one' => array('a', 'b', 'c' => 'cee'), 'two' => 2, 'three' => null); + $this->assertEqual($expected, $result); + } }