Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made default value and behavior of param `$exceptions` for Folder::tr…

…ee() identical to same param in Folder::read()
  • Loading branch information...
commit bcab3d0cb9288222ff19485b67ceadfc49f010fa 1 parent b84c9a1
@ADmad ADmad authored
View
51 lib/Cake/Test/Case/Utility/FolderTest.php
@@ -364,6 +364,41 @@ public function testFolderRead() {
}
/**
+ * testFolderReadWithHiddenFiles method
+ *
+ * @return void
+ */
+ public function testFolderReadWithHiddenFiles() {
+ $this->skipIf(!is_writeable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.');
+
+ $Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777);
+ mkdir($Folder->path . DS . '.svn');
+ mkdir($Folder->path . DS . 'some_folder');
+ touch($Folder->path . DS . 'not_hidden.txt');
+ touch($Folder->path . DS . '.hidden.txt');
+
+ $expected = array(
+ array('some_folder'),
+ array('not_hidden.txt'),
+ );
+ $result = $Folder->read(true, true);
+ $this->assertEquals($expected, $result);
+
+ $expected = array(
+ array(
+ '.svn',
+ 'some_folder'
+ ),
+ array(
+ '.hidden.txt',
+ 'not_hidden.txt'
+ ),
+ );
+ $result = $Folder->read(true);
+ $this->assertEquals($expected, $result);
+ }
+
+/**
* testFolderTree method
*
* @return void
@@ -417,41 +452,47 @@ public function testFolderTree() {
* @return void
*/
public function testFolderTreeWithHiddenFiles() {
- $this->skipIf(!is_writeable(TMP), 'Cant test Folder::tree with hidden files unless the tmp folder is writable.');
+ $this->skipIf(!is_writeable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777);
mkdir($Folder->path . DS . '.svn', 0777, true);
touch($Folder->path . DS . '.svn' . DS . 'InHiddenFolder.php');
+ mkdir($Folder->path . DS . '.svn' . DS . 'inhiddenfolder');
+ touch($Folder->path . DS . '.svn' . DS . 'inhiddenfolder' . DS . 'NestedInHiddenFolder.php');
touch($Folder->path . DS . 'not_hidden.txt');
touch($Folder->path . DS . '.hidden.txt');
+ mkdir($Folder->path . DS . 'visible_folder' . DS . '.git', 0777, true);
$expected = array(
array(
$Folder->path,
+ $Folder->path . DS . 'visible_folder',
),
array(
$Folder->path . DS . 'not_hidden.txt',
),
);
- $result = $Folder->tree(null, false);
- sort($result[1]);
- sort($expected[1]);
+ $result = $Folder->tree(null, true);
$this->assertEquals($expected, $result);
$expected = array(
array(
$Folder->path,
+ $Folder->path . DS . 'visible_folder',
+ $Folder->path . DS . 'visible_folder' . DS . '.git',
$Folder->path . DS . '.svn',
+ $Folder->path . DS . '.svn' . DS . 'inhiddenfolder',
),
array(
$Folder->path . DS . 'not_hidden.txt',
$Folder->path . DS . '.hidden.txt',
+ $Folder->path . DS . '.svn' . DS . 'inhiddenfolder' . DS . 'NestedInHiddenFolder.php',
$Folder->path . DS . '.svn' . DS . 'InHiddenFolder.php',
),
);
- $result = $Folder->tree(null, true);
+ $result = $Folder->tree(null, false);
sort($result[1]);
sort($expected[1]);
$this->assertEquals($expected, $result);
View
5 lib/Cake/TestSuite/CakeTestSuite.php
@@ -49,12 +49,9 @@ public function addTestDirectory($directory = '.') {
*/
public function addTestDirectoryRecursive($directory = '.') {
$Folder = new Folder($directory);
- $files = $Folder->tree(null, false, 'files');
+ $files = $Folder->tree(null, true, 'files');
foreach ($files as $file) {
- if (strpos($file, DS . '.') !== false) {
- continue;
- }
$this->addTestFile($file);
}
}
View
18 lib/Cake/Utility/Folder.php
@@ -398,22 +398,19 @@ public function chmod($path, $mode = false, $recursive = true, $exceptions = arr
* Returns an array of nested directories and files in each directory
*
* @param string $path the directory path to build the tree from
- * @param mixed $exceptions Array of files to exclude, false to exclude dot files.
- * @param string $type either file or dir. null returns both files and directories
+ * @param mixed $exceptions Either an array of files/folder to exclude
+ * or boolean true to not grab dot files/folders
+ * @param string $type either 'file' or 'dir'. null returns both files and directories
* @return mixed array of nested directories and files in each directory
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::tree
*/
- public function tree($path = null, $exceptions = true, $type = null) {
+ public function tree($path = null, $exceptions = false, $type = null) {
if ($path == null) {
$path = $this->path;
}
$files = array();
$directories = array($path);
- $skipHidden = false;
- if ($exceptions === false) {
- $skipHidden = true;
- }
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
if (isset($exceptions['.'])) {
@@ -421,6 +418,13 @@ public function tree($path = null, $exceptions = true, $type = null) {
unset($exceptions['.']);
}
}
+ $skipHidden = false;
+ if ($exceptions === true) {
+ $skipHidden = true;
+ } elseif (isset($exceptions['.'])) {
+ $skipHidden = true;
+ unset($exceptions['.']);
+ }
try {
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME | RecursiveDirectoryIterator::CURRENT_AS_SELF | RecursiveDirectoryIterator::SKIP_DOTS);

0 comments on commit bcab3d0

Please sign in to comment.
Something went wrong with that request. Please try again.