mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
b2e263cd46
commit
d64636796e
3 changed files with 43 additions and 33 deletions
|
@ -166,12 +166,8 @@ class Dispatcher extends Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$protected = array('constructclasses', 'redirect', 'set', 'setAction', 'isauthorized', 'validate', 'validateerrors',
|
$protected = array_map('strtolower', get_class_methods('appcontroller'));
|
||||||
'render', 'referer', 'disablecache', 'flash', 'generatefieldnames', 'postconditions', 'cleanupfields',
|
$classMethods = array_map('strtolower', get_class_methods($controller));
|
||||||
'paginate', 'beforefilter', 'beforerender', 'afterfilter', 'object', 'tostring', 'requestaction', 'log',
|
|
||||||
'cakeerror');
|
|
||||||
|
|
||||||
$classMethods = array_map("low", get_class_methods($controller));
|
|
||||||
|
|
||||||
if (in_array(low($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
|
if (in_array(low($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
|
||||||
$privateAction = true;
|
$privateAction = true;
|
||||||
|
|
|
@ -133,7 +133,7 @@ class Folder extends Object{
|
||||||
function read($sort = true, $exceptions = false) {
|
function read($sort = true, $exceptions = false) {
|
||||||
$dirs = $files = array();
|
$dirs = $files = array();
|
||||||
$dir = opendir($this->path);
|
$dir = opendir($this->path);
|
||||||
if ($dir) {
|
if ($dir !== false) {
|
||||||
while (false !== ($n = readdir($dir))) {
|
while (false !== ($n = readdir($dir))) {
|
||||||
$item = false;
|
$item = false;
|
||||||
if (is_array($exceptions)) {
|
if (is_array($exceptions)) {
|
||||||
|
@ -144,7 +144,7 @@ class Folder extends Object{
|
||||||
$item = $n;
|
$item = $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item) {
|
if ($item !== false) {
|
||||||
if (is_dir($this->addPathElement($this->path, $item))) {
|
if (is_dir($this->addPathElement($this->path, $item))) {
|
||||||
$dirs[] = $item;
|
$dirs[] = $item;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,29 +39,29 @@ class FolderTest extends UnitTestCase {
|
||||||
|
|
||||||
function testBasic() {
|
function testBasic() {
|
||||||
$path = dirname(__FILE__);
|
$path = dirname(__FILE__);
|
||||||
$this->Folder =& new Folder($path);
|
$Folder =& new Folder($path);
|
||||||
|
|
||||||
$result = $this->Folder->pwd();
|
$result = $Folder->pwd();
|
||||||
$this->assertEqual($result, $path);
|
$this->assertEqual($result, $path);
|
||||||
|
|
||||||
$result = $this->Folder->isWindowsPath($path);
|
$result = $Folder->isWindowsPath($path);
|
||||||
$expected = (DS == '\\' ? true : false);
|
$expected = (DS == '\\' ? true : false);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Folder->isAbsolute($path);
|
$result = $Folder->isAbsolute($path);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->isSlashTerm($path);
|
$result = $Folder->isSlashTerm($path);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$result = $this->Folder->isSlashTerm($path . DS);
|
$result = $Folder->isSlashTerm($path . DS);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->addPathElement($path, 'test');
|
$result = $Folder->addPathElement($path, 'test');
|
||||||
$expected = $path . DS . 'test';
|
$expected = $path . DS . 'test';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Folder->cd(ROOT);
|
$result = $Folder->cd(ROOT);
|
||||||
$expected = ROOT;
|
$expected = ROOT;
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
@ -70,64 +70,78 @@ class FolderTest extends UnitTestCase {
|
||||||
$path = dirname(dirname(__FILE__));
|
$path = dirname(dirname(__FILE__));
|
||||||
$inside = dirname($path) . DS;
|
$inside = dirname($path) . DS;
|
||||||
|
|
||||||
$this->Folder =& new Folder($path);
|
$Folder =& new Folder($path);
|
||||||
|
|
||||||
$result = $this->Folder->pwd();
|
$result = $Folder->pwd();
|
||||||
$this->assertEqual($result, $path);
|
$this->assertEqual($result, $path);
|
||||||
|
|
||||||
$result = $this->Folder->isSlashTerm($inside);
|
$result = $Folder->isSlashTerm($inside);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->realpath('tests/');
|
$result = $Folder->realpath('tests/');
|
||||||
$this->assertEqual($result, $path . DS .'tests/');
|
$this->assertEqual($result, $path . DS .'tests/');
|
||||||
|
|
||||||
$result = $this->Folder->inPath('tests/');
|
$result = $Folder->inPath('tests/');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->inPath(DS . 'non-existing' . $inside);
|
$result = $Folder->inPath(DS . 'non-existing' . $inside);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testOperations() {
|
function testOperations() {
|
||||||
$path = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
|
$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);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$new = TMP . 'test_folder_new';
|
$new = TMP . 'test_folder_new';
|
||||||
$result = $this->Folder->create($new);
|
$result = $Folder->create($new);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$copy = TMP . 'test_folder_copy';
|
$copy = TMP . 'test_folder_copy';
|
||||||
$result = $this->Folder->copy($copy);
|
$result = $Folder->copy($copy);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$copy = TMP . 'test_folder_copy';
|
$copy = TMP . 'test_folder_copy';
|
||||||
$result = $this->Folder->chmod($copy, 0755);
|
$result = $Folder->chmod($copy, 0755);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->cd($copy);
|
$result = $Folder->cd($copy);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$mv = TMP . 'test_folder_mv';
|
$mv = TMP . 'test_folder_mv';
|
||||||
$result = $this->Folder->move($mv);
|
$result = $Folder->move($mv);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->delete($new);
|
$result = $Folder->delete($new);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Folder->delete($mv);
|
$result = $Folder->delete($mv);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
//pr($this->Folder->messages());
|
//pr($Folder->messages());
|
||||||
|
|
||||||
//pr($this->Folder->errors());
|
//pr($Folder->errors());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testRealPathForWebroot() {
|
function testRealPathForWebroot() {
|
||||||
$Folder = new Folder('files/');
|
$Folder = new Folder('files/');
|
||||||
$this->assertEqual(realpath('files/'), $Folder->path);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue