fixes #3183, Folder::read()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5628 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-09-11 19:41:57 +00:00
parent b2e263cd46
commit d64636796e
3 changed files with 43 additions and 33 deletions

View file

@ -166,12 +166,8 @@ class Dispatcher extends Object {
}
}
$protected = array('constructclasses', 'redirect', 'set', 'setAction', 'isauthorized', 'validate', 'validateerrors',
'render', 'referer', 'disablecache', 'flash', 'generatefieldnames', 'postconditions', 'cleanupfields',
'paginate', 'beforefilter', 'beforerender', 'afterfilter', 'object', 'tostring', 'requestaction', 'log',
'cakeerror');
$classMethods = array_map("low", get_class_methods($controller));
$protected = array_map('strtolower', get_class_methods('appcontroller'));
$classMethods = array_map('strtolower', get_class_methods($controller));
if (in_array(low($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
$privateAction = true;

View file

@ -133,7 +133,7 @@ class Folder extends Object{
function read($sort = true, $exceptions = false) {
$dirs = $files = array();
$dir = opendir($this->path);
if ($dir) {
if ($dir !== false) {
while (false !== ($n = readdir($dir))) {
$item = false;
if (is_array($exceptions)) {
@ -144,7 +144,7 @@ class Folder extends Object{
$item = $n;
}
if ($item) {
if ($item !== false) {
if (is_dir($this->addPathElement($this->path, $item))) {
$dirs[] = $item;
} else {

View file

@ -39,29 +39,29 @@ class FolderTest extends UnitTestCase {
function testBasic() {
$path = dirname(__FILE__);
$this->Folder =& new Folder($path);
$Folder =& new Folder($path);
$result = $this->Folder->pwd();
$result = $Folder->pwd();
$this->assertEqual($result, $path);
$result = $this->Folder->isWindowsPath($path);
$result = $Folder->isWindowsPath($path);
$expected = (DS == '\\' ? true : false);
$this->assertEqual($result, $expected);
$result = $this->Folder->isAbsolute($path);
$result = $Folder->isAbsolute($path);
$this->assertTrue($result);
$result = $this->Folder->isSlashTerm($path);
$result = $Folder->isSlashTerm($path);
$this->assertFalse($result);
$result = $this->Folder->isSlashTerm($path . DS);
$result = $Folder->isSlashTerm($path . DS);
$this->assertTrue($result);
$result = $this->Folder->addPathElement($path, 'test');
$result = $Folder->addPathElement($path, 'test');
$expected = $path . DS . 'test';
$this->assertEqual($result, $expected);
$result = $this->Folder->cd(ROOT);
$result = $Folder->cd(ROOT);
$expected = ROOT;
$this->assertEqual($result, $expected);
}
@ -70,64 +70,78 @@ class FolderTest extends UnitTestCase {
$path = dirname(dirname(__FILE__));
$inside = dirname($path) . DS;
$this->Folder =& new Folder($path);
$Folder =& new Folder($path);
$result = $this->Folder->pwd();
$result = $Folder->pwd();
$this->assertEqual($result, $path);
$result = $this->Folder->isSlashTerm($inside);
$result = $Folder->isSlashTerm($inside);
$this->assertTrue($result);
$result = $this->Folder->realpath('tests/');
$result = $Folder->realpath('tests/');
$this->assertEqual($result, $path . DS .'tests/');
$result = $this->Folder->inPath('tests/');
$result = $Folder->inPath('tests/');
$this->assertTrue($result);
$result = $this->Folder->inPath(DS . 'non-existing' . $inside);
$result = $Folder->inPath(DS . 'non-existing' . $inside);
$this->assertFalse($result);
}
function testOperations() {
$path = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
$this->Folder =& new Folder($path);
$Folder =& new Folder($path);
$result = is_dir($this->Folder->pwd());
$result = is_dir($Folder->pwd());
$this->assertTrue($result);
$new = TMP . 'test_folder_new';
$result = $this->Folder->create($new);
$result = $Folder->create($new);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $this->Folder->copy($copy);
$result = $Folder->copy($copy);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $this->Folder->chmod($copy, 0755);
$result = $Folder->chmod($copy, 0755);
$this->assertTrue($result);
$result = $this->Folder->cd($copy);
$result = $Folder->cd($copy);
$this->assertTrue($result);
$mv = TMP . 'test_folder_mv';
$result = $this->Folder->move($mv);
$result = $Folder->move($mv);
$this->assertTrue($result);
$result = $this->Folder->delete($new);
$result = $Folder->delete($new);
$this->assertTrue($result);
$result = $this->Folder->delete($mv);
$result = $Folder->delete($mv);
$this->assertTrue($result);
//pr($this->Folder->messages());
//pr($Folder->messages());
//pr($this->Folder->errors());
//pr($Folder->errors());
}
function testRealPathForWebroot() {
$Folder = new Folder('files/');
$this->assertEqual(realpath('files/'), $Folder->path);
}
function testZeroAsDirectory() {
$Folder =& new Folder(TMP);
$new = TMP . '0';
$result = $Folder->create($new);
$this->assertTrue($result);
$result = $Folder->read(true, '.');
$expected = array(array('0', 'cache', 'logs', 'sessions', 'tests'), array());
$this->assertEqual($expected, $result);
$result = $Folder->delete($new);
$this->assertTrue($result);
}
}
?>