2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FolderTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2010-12-19 02:32:25 +00:00
|
|
|
App::uses('Folder', 'Utility');
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('File', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FolderTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class FolderTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-09-23 02:05:36 +00:00
|
|
|
protected static $_tmp = array();
|
|
|
|
|
|
|
|
/**
|
2012-09-10 08:23:52 +00:00
|
|
|
* Save the directory names in TMP and make sure default directories exist
|
2011-09-23 02:05:36 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function setUpBeforeClass() {
|
2012-09-10 08:23:52 +00:00
|
|
|
$dirs = array('cache', 'logs', 'sessions', 'tests');
|
|
|
|
foreach ($dirs as $dir) {
|
|
|
|
new Folder(TMP . $dir, true);
|
|
|
|
}
|
|
|
|
|
2011-09-23 02:05:36 +00:00
|
|
|
foreach (scandir(TMP) as $file) {
|
|
|
|
if (is_dir(TMP . $file) && !in_array($file, array('.', '..'))) {
|
2015-07-21 08:22:53 +00:00
|
|
|
static::$_tmp[] = $file;
|
2011-09-23 02:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setUp clearstatcache() to flush file descriptors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
clearstatcache();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the TMP directory to its original state.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
2015-07-21 08:22:53 +00:00
|
|
|
$exclude = array_merge(static::$_tmp, array('.', '..'));
|
2011-11-16 08:33:18 +00:00
|
|
|
foreach (scandir(TMP) as $dir) {
|
|
|
|
if (is_dir(TMP . $dir) && !in_array($dir, $exclude)) {
|
|
|
|
$iterator = new RecursiveDirectoryIterator(TMP . $dir);
|
|
|
|
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
|
|
|
|
if ($file->isFile() || $file->isLink()) {
|
|
|
|
unlink($file->getPathname());
|
|
|
|
} elseif ($file->isDir() && !in_array($file->getFilename(), array('.', '..'))) {
|
|
|
|
rmdir($file->getPathname());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir(TMP . $dir);
|
2011-09-23 02:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-07 18:24:28 +00:00
|
|
|
parent::tearDown();
|
2011-09-23 02:05:36 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBasic method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBasic() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$path = dirname(__FILE__);
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder($path);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $Folder->pwd();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($path, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$result = Folder::addPathElement($path, 'test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = $path . DS . 'test';
|
2011-11-15 16:18:05 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $Folder->cd(ROOT);
|
|
|
|
$expected = ROOT;
|
2011-11-15 16:18:05 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-11-07 01:08:18 +00:00
|
|
|
|
|
|
|
$result = $Folder->cd(ROOT . DS . 'non-existent');
|
|
|
|
$this->assertFalse($result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInPath method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInPath() {
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// "/Test/test_app/"
|
|
|
|
$basePath = CAKE . 'Test' . DS . 'test_app' . DS;
|
|
|
|
$Base = new Folder($basePath);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
$result = $Base->pwd();
|
|
|
|
$this->assertEquals($basePath, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// is "/" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath(realpath(DS), true);
|
|
|
|
$this->assertFalse($result, true);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// is "/Test/test_app/" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath($basePath, true);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// is "/Test/test_app" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath(mb_substr($basePath, 0, -1), true);
|
|
|
|
$this->assertTrue($result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// is "/Test/test_app/sub" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath($basePath . 'sub', true);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// is "/Test" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath(dirname($basePath), true);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
2012-03-27 18:55:13 +00:00
|
|
|
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
// is "/Test/other/(...)Test/test_app" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath(TMP . 'tests' . DS . 'other' . DS . $basePath, true);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
// is "/Test/test_app/" in "/"
|
|
|
|
$result = $Base->inPath(realpath(DS));
|
2012-03-27 18:55:13 +00:00
|
|
|
$this->assertTrue($result);
|
Fix/tighten `Folder::inPath()` checks.
The current checks are way too relaxed, and are more like testing
for a substring, which makes it easy for invalid paths to slip
trough, for example `/foo/var/www` is falsely tested to reside in
`/var/www`.
Passing an empty path never worked properly, it was triggering a
warning, didn't worked on Windows, and the behavior that the current
top level directory would be assumed for empty paths wasn't
documented.
Similar is true for relative paths. While they did match at one point,
this was incorrect behavior, and matching actual path fragments seems
out of scope for this method.
This change makes the `$path` argument required, requires it to be an
absolute path, and throws an exception in case a non-absolute path is
being passed.
2016-08-26 11:28:02 +00:00
|
|
|
|
|
|
|
// is "/Test/test_app/" in "/Test/test_app/"
|
|
|
|
$result = $Base->inPath($basePath);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
// is "/Test/test_app/" in "/Test/test_app"
|
|
|
|
$result = $Base->inPath(mb_substr($basePath, 0, -1));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
// is "/Test/test_app/" in "/Test"
|
|
|
|
$result = $Base->inPath(dirname($basePath));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
// is "/Test/test_app/" in "/Test/test_app/sub"
|
|
|
|
$result = $Base->inPath($basePath . 'sub');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
// is "/other/Test/test_app/" in "/Test/test_app/"
|
|
|
|
$VirtualBase = new Folder();
|
|
|
|
$VirtualBase->path = '/other/Test/test_app';
|
|
|
|
$result = $VirtualBase->inPath('/Test/test_app/');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data provider for the testInPathInvalidPathArgument test
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function inPathInvalidPathArgumentDataProvider() {
|
|
|
|
return array(
|
|
|
|
array(''),
|
|
|
|
array('relative/path/'),
|
|
|
|
array('unknown://stream-wrapper')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider inPathInvalidPathArgumentDataProvider
|
|
|
|
* @param string $path
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
* @expectedExceptionMessage The $path argument is expected to be an absolute path.
|
|
|
|
*/
|
|
|
|
public function testInPathInvalidPathArgument($path) {
|
|
|
|
$Folder = new Folder();
|
|
|
|
$Folder->inPath($path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-02-20 16:25:46 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* test creation of single and multiple paths.
|
2010-02-20 16:25:46 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreation() {
|
2011-10-20 23:10:09 +00:00
|
|
|
$Folder = new Folder(TMP . 'tests');
|
|
|
|
$result = $Folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
|
2010-02-20 16:25:46 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
|
|
|
|
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
|
|
|
|
rmdir(TMP . 'tests' . DS . 'first');
|
|
|
|
|
2011-10-20 23:10:09 +00:00
|
|
|
$Folder = new Folder(TMP . 'tests');
|
|
|
|
$result = $Folder->create(TMP . 'tests' . DS . 'first');
|
2010-02-20 16:25:46 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
rmdir(TMP . 'tests' . DS . 'first');
|
|
|
|
}
|
2010-03-31 02:35:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that creation of folders with trailing ds works
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateWithTrailingDs() {
|
2011-10-20 23:10:09 +00:00
|
|
|
$Folder = new Folder(TMP);
|
2010-03-31 02:35:49 +00:00
|
|
|
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
|
2011-10-20 23:10:09 +00:00
|
|
|
$result = $Folder->create($path);
|
2010-08-10 02:56:41 +00:00
|
|
|
$this->assertTrue($result);
|
2010-03-31 02:35:49 +00:00
|
|
|
|
|
|
|
$this->assertTrue(is_dir($path), 'Folder was not made');
|
|
|
|
|
2011-10-20 23:10:09 +00:00
|
|
|
$Folder = new Folder(TMP . 'tests' . DS . 'trailing');
|
|
|
|
$this->assertTrue($Folder->delete());
|
2010-03-31 02:35:49 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 01:32:28 +00:00
|
|
|
/**
|
|
|
|
* Test that relative paths to create() are added to cwd.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCreateRelative() {
|
|
|
|
$folder = new Folder(TMP);
|
|
|
|
$path = TMP . 'tests' . DS . 'relative-test';
|
|
|
|
$result = $folder->create('tests' . DS . 'relative-test');
|
|
|
|
$this->assertTrue($result, 'should create');
|
|
|
|
|
|
|
|
$this->assertTrue(is_dir($path), 'Folder was not made');
|
|
|
|
$folder = new Folder($path);
|
|
|
|
$folder->delete();
|
|
|
|
}
|
|
|
|
|
2010-02-20 16:25:46 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* test recursive directory create failure.
|
2010-02-20 16:25:46 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRecursiveCreateFailure() {
|
2015-07-09 13:54:03 +00:00
|
|
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Cant perform operations using permissions on Windows.');
|
2011-05-31 00:49:46 +00:00
|
|
|
|
2010-02-20 16:25:46 +00:00
|
|
|
$path = TMP . 'tests' . DS . 'one';
|
|
|
|
mkdir($path);
|
|
|
|
chmod($path, '0444');
|
|
|
|
|
2010-05-31 02:57:28 +00:00
|
|
|
try {
|
2011-10-20 23:10:09 +00:00
|
|
|
$Folder = new Folder($path);
|
|
|
|
$result = $Folder->create($path . DS . 'two' . DS . 'three');
|
2010-05-31 02:57:28 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
} catch (PHPUnit_Framework_Error $e) {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
2010-02-20 16:25:46 +00:00
|
|
|
|
|
|
|
chmod($path, '0777');
|
|
|
|
rmdir($path);
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOperations method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testOperations() {
|
2011-05-31 03:03:49 +00:00
|
|
|
$path = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder($path);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = is_dir($Folder->pwd());
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$new = TMP . 'test_folder_new';
|
|
|
|
$result = $Folder->create($new);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$copy = TMP . 'test_folder_copy';
|
|
|
|
$result = $Folder->copy($copy);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$copy = TMP . 'test_folder_copy';
|
2009-09-01 02:47:37 +00:00
|
|
|
$result = $Folder->copy($copy);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$copy = TMP . 'test_folder_copy';
|
|
|
|
$result = $Folder->chmod($copy, 0755, false);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $Folder->cd($copy);
|
2010-05-31 02:57:28 +00:00
|
|
|
$this->assertTrue((bool)$result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$mv = TMP . 'test_folder_mv';
|
|
|
|
$result = $Folder->move($mv);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$mv = TMP . 'test_folder_mv_2';
|
2009-09-01 02:47:37 +00:00
|
|
|
$result = $Folder->move($mv);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $Folder->delete($new);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $Folder->delete($mv);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2009-09-01 02:47:37 +00:00
|
|
|
$result = $Folder->delete($mv);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2008-11-07 01:08:18 +00:00
|
|
|
$new = APP . 'index.php';
|
|
|
|
$result = $Folder->create($new);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$expected = $new . ' is a file';
|
2010-12-13 02:02:42 +00:00
|
|
|
$result = $Folder->errors();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $result[0]);
|
2008-11-07 01:08:18 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$new = TMP . 'test_folder_new';
|
|
|
|
$result = $Folder->create($new);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $Folder->cd($new);
|
2010-05-31 02:57:28 +00:00
|
|
|
$this->assertTrue((bool)$result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $Folder->delete();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder('non-existent');
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Folder->pwd();
|
|
|
|
$this->assertNull($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-09 04:34:11 +00:00
|
|
|
/**
|
|
|
|
* testChmod method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testChmod() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Folder permissions tests not supported on Windows.');
|
2008-11-06 18:00:56 +00:00
|
|
|
|
2012-03-11 02:33:40 +00:00
|
|
|
$path = TMP;
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder($path);
|
2008-09-09 04:34:11 +00:00
|
|
|
|
|
|
|
$subdir = 'test_folder_new';
|
|
|
|
$new = TMP . $subdir;
|
|
|
|
|
|
|
|
$this->assertTrue($Folder->create($new));
|
|
|
|
$this->assertTrue($Folder->create($new . DS . 'test1'));
|
|
|
|
$this->assertTrue($Folder->create($new . DS . 'test2'));
|
|
|
|
|
|
|
|
$filePath = $new . DS . 'test1.php';
|
2010-05-31 02:57:28 +00:00
|
|
|
$File = new File($filePath);
|
2008-09-09 04:34:11 +00:00
|
|
|
$this->assertTrue($File->create());
|
2011-11-16 08:33:18 +00:00
|
|
|
|
2011-11-15 07:47:52 +00:00
|
|
|
$filePath = $new . DS . 'skip_me.php';
|
|
|
|
$File = new File($filePath);
|
|
|
|
$this->assertTrue($File->create());
|
2008-09-09 04:34:11 +00:00
|
|
|
|
2011-11-15 07:47:52 +00:00
|
|
|
$this->assertTrue($Folder->chmod($new, 0755, true));
|
2012-03-11 03:00:16 +00:00
|
|
|
$perms = substr(sprintf('%o', fileperms($new . DS . 'test2')), -4);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('0755', $perms);
|
2012-03-14 02:59:20 +00:00
|
|
|
|
2012-03-11 02:40:38 +00:00
|
|
|
$this->assertTrue($Folder->chmod($new, 0744, true, array('skip_me.php', 'test2')));
|
2011-11-16 08:33:18 +00:00
|
|
|
|
2011-11-15 07:47:52 +00:00
|
|
|
$perms = substr(sprintf('%o', fileperms($new . DS . 'test2')), -4);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('0755', $perms);
|
2011-11-16 08:33:18 +00:00
|
|
|
|
2012-03-11 03:00:16 +00:00
|
|
|
$perms = substr(sprintf('%o', fileperms($new . DS . 'test1')), -4);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('0744', $perms);
|
2011-11-16 08:33:18 +00:00
|
|
|
|
2008-09-09 04:34:11 +00:00
|
|
|
$Folder->delete($new);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRealPathForWebroot method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRealPathForWebroot() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Folder = new Folder('files/');
|
2011-11-15 16:18:05 +00:00
|
|
|
$this->assertEquals(realpath('files/'), $Folder->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testZeroAsDirectory method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testZeroAsDirectory() {
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder(TMP);
|
2008-05-30 11:40:08 +00:00
|
|
|
$new = TMP . '0';
|
2008-09-09 04:34:11 +00:00
|
|
|
$this->assertTrue($Folder->create($new));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $Folder->read(true, true);
|
2008-11-07 01:08:18 +00:00
|
|
|
$expected = array('0', 'cache', 'logs', 'sessions', 'tests');
|
2011-11-15 16:18:05 +00:00
|
|
|
$this->assertEquals($expected, $result[0]);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-09-23 02:05:36 +00:00
|
|
|
$result = $Folder->read(true, array('logs'));
|
2008-11-07 01:08:18 +00:00
|
|
|
$expected = array('0', 'cache', 'sessions', 'tests');
|
2011-11-15 16:18:05 +00:00
|
|
|
$this->assertEquals($expected, $result[0]);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $Folder->delete($new);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-28 01:04:14 +00:00
|
|
|
/**
|
|
|
|
* test Adding path elements to a path
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddPathElement() {
|
2013-10-03 02:45:22 +00:00
|
|
|
$expected = DS . 'some' . DS . 'dir' . DS . 'another_path';
|
|
|
|
|
2009-10-28 01:04:14 +00:00
|
|
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
|
2013-10-03 02:45:22 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-28 01:04:14 +00:00
|
|
|
|
|
|
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
|
2013-10-03 02:45:22 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', array('another_path'));
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, array('another_path'));
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$expected = DS . 'some' . DS . 'dir' . DS . 'another_path' . DS . 'and' . DS . 'another';
|
|
|
|
|
|
|
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', array('another_path', 'and', 'another'));
|
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-28 01:04:14 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFolderRead method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFolderRead() {
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder(TMP);
|
2008-11-07 01:08:18 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('cache', 'logs', 'sessions', 'tests');
|
2008-11-07 01:08:18 +00:00
|
|
|
$result = $Folder->read(true, true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $result[0]);
|
2008-11-07 01:08:18 +00:00
|
|
|
|
2011-05-28 21:08:22 +00:00
|
|
|
$Folder->path = TMP . 'non-existent';
|
2008-11-07 01:08:18 +00:00
|
|
|
$expected = array(array(), array());
|
|
|
|
$result = $Folder->read(true, true);
|
2011-11-15 16:18:05 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-12-21 20:33:22 +00:00
|
|
|
/**
|
|
|
|
* testFolderReadWithHiddenFiles method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFolderReadWithHiddenFiles() {
|
2012-09-15 10:17:35 +00:00
|
|
|
$this->skipIf(!is_writable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.');
|
2011-12-21 20:33:22 +00:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFolderTree method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFolderTree() {
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder();
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Config',
|
|
|
|
CAKE . 'Config' . DS . 'unicode',
|
2012-03-14 02:59:20 +00:00
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding'
|
2008-05-30 11:40:08 +00:00
|
|
|
),
|
|
|
|
array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Config' . DS . 'config.php',
|
2012-03-14 02:59:20 +00:00
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0250_02af.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php',
|
|
|
|
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php'
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$result = $Folder->tree(CAKE . 'Config', false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame(array(), array_diff($expected[0], $result[0]));
|
|
|
|
$this->assertSame(array(), array_diff($result[0], $expected[0]));
|
2008-11-07 01:08:18 +00:00
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$result = $Folder->tree(CAKE . 'Config', false, 'dir');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame(array(), array_diff($expected[0], $result));
|
|
|
|
$this->assertSame(array(), array_diff($expected[0], $result));
|
2008-11-07 01:08:18 +00:00
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$result = $Folder->tree(CAKE . 'Config', false, 'files');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame(array(), array_diff($expected[1], $result));
|
|
|
|
$this->assertSame(array(), array_diff($expected[1], $result));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-12-10 05:44:15 +00:00
|
|
|
/**
|
|
|
|
* testFolderTreeWithHiddenFiles method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFolderTreeWithHiddenFiles() {
|
2012-09-15 10:17:35 +00:00
|
|
|
$this->skipIf(!is_writable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.');
|
2011-12-10 05:44:15 +00:00
|
|
|
|
|
|
|
$Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777);
|
|
|
|
mkdir($Folder->path . DS . '.svn', 0777, true);
|
|
|
|
touch($Folder->path . DS . '.svn' . DS . 'InHiddenFolder.php');
|
2011-12-21 20:33:22 +00:00
|
|
|
mkdir($Folder->path . DS . '.svn' . DS . 'inhiddenfolder');
|
|
|
|
touch($Folder->path . DS . '.svn' . DS . 'inhiddenfolder' . DS . 'NestedInHiddenFolder.php');
|
2011-12-10 05:44:15 +00:00
|
|
|
touch($Folder->path . DS . 'not_hidden.txt');
|
|
|
|
touch($Folder->path . DS . '.hidden.txt');
|
2011-12-21 20:33:22 +00:00
|
|
|
mkdir($Folder->path . DS . 'visible_folder' . DS . '.git', 0777, true);
|
2011-12-10 05:44:15 +00:00
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
$Folder->path,
|
2011-12-21 20:33:22 +00:00
|
|
|
$Folder->path . DS . 'visible_folder',
|
2011-12-10 05:44:15 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
$Folder->path . DS . 'not_hidden.txt',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2011-12-21 20:33:22 +00:00
|
|
|
$result = $Folder->tree(null, true);
|
2011-12-10 15:08:24 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-12-10 05:44:15 +00:00
|
|
|
|
2012-02-17 19:46:52 +00:00
|
|
|
$result = $Folder->tree(null, array('.'));
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2011-12-10 05:44:15 +00:00
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
$Folder->path,
|
2011-12-21 20:33:22 +00:00
|
|
|
$Folder->path . DS . 'visible_folder',
|
|
|
|
$Folder->path . DS . 'visible_folder' . DS . '.git',
|
2011-12-10 05:44:15 +00:00
|
|
|
$Folder->path . DS . '.svn',
|
2011-12-21 20:33:22 +00:00
|
|
|
$Folder->path . DS . '.svn' . DS . 'inhiddenfolder',
|
2011-12-10 05:44:15 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
$Folder->path . DS . 'not_hidden.txt',
|
|
|
|
$Folder->path . DS . '.hidden.txt',
|
2011-12-21 20:33:22 +00:00
|
|
|
$Folder->path . DS . '.svn' . DS . 'inhiddenfolder' . DS . 'NestedInHiddenFolder.php',
|
2011-12-10 05:44:15 +00:00
|
|
|
$Folder->path . DS . '.svn' . DS . 'InHiddenFolder.php',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2011-12-21 20:33:22 +00:00
|
|
|
$result = $Folder->tree(null, false);
|
2011-12-21 22:07:04 +00:00
|
|
|
sort($result[0]);
|
|
|
|
sort($expected[0]);
|
2011-12-10 15:08:24 +00:00
|
|
|
sort($result[1]);
|
|
|
|
sort($expected[1]);
|
|
|
|
$this->assertEquals($expected, $result);
|
2011-12-10 05:44:15 +00:00
|
|
|
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testWindowsPath method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWindowsPath() {
|
2008-12-18 00:17:19 +00:00
|
|
|
$this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
|
|
|
|
$this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
|
|
|
|
$this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
|
2010-11-20 18:26:30 +00:00
|
|
|
$this->assertTrue(Folder::isWindowsPath('\\\\vmware-host\\Shared Folders\\file'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testIsAbsolute method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsAbsolute() {
|
2008-12-18 00:17:19 +00:00
|
|
|
$this->assertFalse(Folder::isAbsolute('path/to/file'));
|
|
|
|
$this->assertFalse(Folder::isAbsolute('cake/'));
|
|
|
|
$this->assertFalse(Folder::isAbsolute('path\\to\\file'));
|
|
|
|
$this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
|
|
|
|
$this->assertFalse(Folder::isAbsolute('\\path/to/file'));
|
|
|
|
$this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
|
2014-06-22 08:13:14 +00:00
|
|
|
$this->assertFalse(Folder::isAbsolute('notRegisteredStreamWrapper://example'));
|
|
|
|
$this->assertFalse(Folder::isAbsolute('://example'));
|
2008-12-18 00:17:19 +00:00
|
|
|
|
|
|
|
$this->assertTrue(Folder::isAbsolute('/usr/local'));
|
|
|
|
$this->assertTrue(Folder::isAbsolute('//path/to/file'));
|
|
|
|
$this->assertTrue(Folder::isAbsolute('C:\\cake'));
|
|
|
|
$this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
|
|
|
|
$this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
|
2010-11-20 18:26:30 +00:00
|
|
|
$this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
|
2014-06-22 08:13:14 +00:00
|
|
|
$this->assertTrue(Folder::isAbsolute('http://www.example.com'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testIsSlashTerm method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsSlashTerm() {
|
2008-12-18 00:17:19 +00:00
|
|
|
$this->assertFalse(Folder::isSlashTerm('cake'));
|
|
|
|
|
|
|
|
$this->assertTrue(Folder::isSlashTerm('C:\\cake\\'));
|
|
|
|
$this->assertTrue(Folder::isSlashTerm('/usr/local/'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testStatic method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSlashTerm() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Folder::slashTerm('/path/to/file');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/path/to/file/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testNormalizePath method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNormalizePath() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$path = '/path/to/file';
|
|
|
|
$result = Folder::normalizePath($path);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$path = '\\path\\\to\\\file';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Folder::normalizePath($path);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$path = 'C:\\path\\to\\file';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Folder::normalizePath($path);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('\\', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* correctSlashFor method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCorrectSlashFor() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$path = '/path/to/file';
|
|
|
|
$result = Folder::correctSlashFor($path);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$path = '\\path\\to\\file';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Folder::correctSlashFor($path);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$path = 'C:\\path\to\\file';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Folder::correctSlashFor($path);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('\\', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInCakePath method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInCakePath() {
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder();
|
2008-05-30 11:40:08 +00:00
|
|
|
$Folder->cd(ROOT);
|
2008-12-18 00:17:19 +00:00
|
|
|
$path = 'C:\\path\\to\\file';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Folder->inCakePath($path);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$path = ROOT;
|
|
|
|
$Folder->cd(ROOT);
|
|
|
|
$result = $Folder->inCakePath($path);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2011-05-13 08:06:45 +00:00
|
|
|
$path = DS . 'lib' . DS . 'Cake' . DS . 'Config';
|
|
|
|
$Folder->cd(ROOT . DS . 'lib' . DS . 'Cake' . DS . 'Config');
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Folder->inCakePath($path);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFind method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFind() {
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder();
|
2011-04-17 10:35:21 +00:00
|
|
|
$Folder->cd(CAKE . 'Config');
|
2008-12-18 00:17:19 +00:00
|
|
|
$result = $Folder->find();
|
2011-03-12 05:22:23 +00:00
|
|
|
$expected = array('config.php');
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
2009-03-15 00:10:53 +00:00
|
|
|
|
|
|
|
$result = $Folder->find('.*', true);
|
2012-11-12 02:57:52 +00:00
|
|
|
$expected = array('cacert.pem', 'config.php', 'routes.php');
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$result = $Folder->find('.*\.php');
|
2011-03-12 05:22:23 +00:00
|
|
|
$expected = array('config.php');
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
2009-03-15 00:10:53 +00:00
|
|
|
|
|
|
|
$result = $Folder->find('.*\.php', true);
|
2011-07-17 03:47:12 +00:00
|
|
|
$expected = array('config.php', 'routes.php');
|
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$result = $Folder->find('.*ig\.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('config.php');
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-03-12 05:22:23 +00:00
|
|
|
$result = $Folder->find('config\.php');
|
|
|
|
$expected = array('config.php');
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP);
|
2011-10-20 23:10:09 +00:00
|
|
|
$File = new File($Folder->pwd() . DS . 'paths.php', true);
|
2009-09-01 02:47:37 +00:00
|
|
|
$Folder->create($Folder->pwd() . DS . 'testme');
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd('testme');
|
|
|
|
$result = $Folder->find('paths\.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array();
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd($Folder->pwd() . '/..');
|
|
|
|
$result = $Folder->find('paths\.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('paths.php');
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-06-27 08:04:54 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP);
|
|
|
|
$Folder->delete($Folder->pwd() . DS . 'testme');
|
2011-10-20 23:10:09 +00:00
|
|
|
$File->delete();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testFindRecursive method
|
2008-06-27 08:04:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindRecursive() {
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder();
|
2011-04-17 10:35:21 +00:00
|
|
|
$Folder->cd(CAKE);
|
2008-12-18 00:17:19 +00:00
|
|
|
$result = $Folder->findRecursive('(config|paths)\.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Config' . DS . 'config.php'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
2009-03-15 00:10:53 +00:00
|
|
|
|
|
|
|
$result = $Folder->findRecursive('(config|paths)\.php', true);
|
|
|
|
$expected = array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Config' . DS . 'config.php'
|
2009-03-15 00:10:53 +00:00
|
|
|
);
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP);
|
2009-09-01 02:47:37 +00:00
|
|
|
$Folder->create($Folder->pwd() . DS . 'testme');
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd('testme');
|
2010-05-31 02:57:28 +00:00
|
|
|
$File = new File($Folder->pwd() . DS . 'paths.php');
|
2008-12-18 00:17:19 +00:00
|
|
|
$File->create();
|
|
|
|
$Folder->cd(TMP . 'sessions');
|
|
|
|
$result = $Folder->findRecursive('paths\.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array();
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP . 'testme');
|
2010-05-31 02:57:28 +00:00
|
|
|
$File = new File($Folder->pwd() . DS . 'my.php');
|
2008-12-18 00:17:19 +00:00
|
|
|
$File->create();
|
|
|
|
$Folder->cd($Folder->pwd() . '/../..');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$result = $Folder->findRecursive('(paths|my)\.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-07 01:08:18 +00:00
|
|
|
TMP . 'testme' . DS . 'my.php',
|
|
|
|
TMP . 'testme' . DS . 'paths.php'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
|
|
|
$this->assertSame(array_diff($expected, $result), array());
|
2009-03-15 00:10:53 +00:00
|
|
|
|
|
|
|
$result = $Folder->findRecursive('(paths|my)\.php', true);
|
|
|
|
$expected = array(
|
|
|
|
TMP . 'testme' . DS . 'my.php',
|
|
|
|
TMP . 'testme' . DS . 'paths.php'
|
|
|
|
);
|
2011-07-17 03:47:12 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$Folder->cd(CAKE . 'Config');
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP);
|
|
|
|
$Folder->delete($Folder->pwd() . DS . 'testme');
|
|
|
|
$File->delete();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* testConstructWithNonExistentPath method
|
2008-06-27 08:04:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 23:29:53 +00:00
|
|
|
public function testConstructWithNonExistentPath() {
|
|
|
|
$Folder = new Folder(TMP . 'config_non_existent', true);
|
|
|
|
$this->assertTrue(is_dir(TMP . 'config_non_existent'));
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP);
|
2012-02-23 23:29:53 +00:00
|
|
|
$Folder->delete($Folder->pwd() . 'config_non_existent');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testDirSize method
|
2008-06-27 08:04:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDirSize() {
|
2012-02-23 23:29:53 +00:00
|
|
|
$Folder = new Folder(TMP . 'config_non_existent', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(0, $Folder->dirSize());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-31 02:57:28 +00:00
|
|
|
$File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
|
2008-12-18 00:17:19 +00:00
|
|
|
$File->create();
|
|
|
|
$File->write('something here');
|
|
|
|
$File->close();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(14, $Folder->dirSize());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-18 00:17:19 +00:00
|
|
|
$Folder->cd(TMP);
|
2012-02-23 23:29:53 +00:00
|
|
|
$Folder->delete($Folder->pwd() . 'config_non_existent');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-10-01 11:42:14 +00:00
|
|
|
/**
|
|
|
|
* test that errors and messages can be resetted
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testReset() {
|
|
|
|
$path = TMP . 'folder_delete_test';
|
|
|
|
mkdir($path);
|
|
|
|
$folder = $path . DS . 'sub';
|
|
|
|
mkdir($folder);
|
|
|
|
$file = $folder . DS . 'file';
|
|
|
|
touch($file);
|
2012-10-01 14:52:41 +00:00
|
|
|
|
|
|
|
chmod($folder, 0555);
|
|
|
|
chmod($file, 0444);
|
2012-10-01 11:42:14 +00:00
|
|
|
|
|
|
|
$Folder = new Folder($folder);
|
|
|
|
$return = $Folder->delete();
|
|
|
|
$this->assertFalse($return);
|
|
|
|
|
|
|
|
$messages = $Folder->messages();
|
|
|
|
$errors = $Folder->errors();
|
|
|
|
$expected = array(
|
2012-10-01 14:52:41 +00:00
|
|
|
$file . ' NOT removed',
|
2012-10-01 11:42:14 +00:00
|
|
|
$folder . ' NOT removed',
|
|
|
|
);
|
|
|
|
sort($expected);
|
|
|
|
sort($errors);
|
|
|
|
$this->assertEmpty($messages);
|
|
|
|
$this->assertEquals($expected, $errors);
|
|
|
|
|
2012-10-01 14:52:41 +00:00
|
|
|
chmod($file, 0644);
|
|
|
|
chmod($folder, 0755);
|
2012-10-01 11:42:14 +00:00
|
|
|
|
|
|
|
$return = $Folder->delete();
|
|
|
|
$this->assertTrue($return);
|
|
|
|
|
|
|
|
$messages = $Folder->messages();
|
|
|
|
$errors = $Folder->errors();
|
|
|
|
$expected = array(
|
2012-10-01 14:52:41 +00:00
|
|
|
$file . ' removed',
|
2012-10-01 11:42:14 +00:00
|
|
|
$folder . ' removed',
|
|
|
|
);
|
|
|
|
sort($expected);
|
|
|
|
sort($messages);
|
|
|
|
$this->assertEmpty($errors);
|
|
|
|
$this->assertEquals($expected, $messages);
|
|
|
|
}
|
|
|
|
|
2008-09-08 16:44:06 +00:00
|
|
|
/**
|
|
|
|
* testDelete method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDelete() {
|
2008-09-08 16:44:06 +00:00
|
|
|
$path = TMP . 'folder_delete_test';
|
2011-12-14 20:29:30 +00:00
|
|
|
mkdir($path);
|
|
|
|
touch($path . DS . 'file_1');
|
|
|
|
mkdir($path . DS . 'level_1_1');
|
|
|
|
touch($path . DS . 'level_1_1' . DS . 'file_1_1');
|
|
|
|
mkdir($path . DS . 'level_1_1' . DS . 'level_2_1');
|
|
|
|
touch($path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_1');
|
|
|
|
touch($path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_2');
|
|
|
|
mkdir($path . DS . 'level_1_1' . DS . 'level_2_2');
|
2008-09-12 05:11:34 +00:00
|
|
|
|
2011-12-14 20:29:30 +00:00
|
|
|
$Folder = new Folder($path, true);
|
2008-09-08 16:44:06 +00:00
|
|
|
$return = $Folder->delete();
|
|
|
|
$this->assertTrue($return);
|
2008-09-12 05:11:34 +00:00
|
|
|
|
2008-09-08 16:44:06 +00:00
|
|
|
$messages = $Folder->messages();
|
|
|
|
$errors = $Folder->errors();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $errors);
|
2008-09-12 05:11:34 +00:00
|
|
|
|
2008-09-08 16:44:06 +00:00
|
|
|
$expected = array(
|
2011-12-14 20:29:30 +00:00
|
|
|
$path . DS . 'file_1 removed',
|
|
|
|
$path . DS . 'level_1_1' . DS . 'file_1_1 removed',
|
|
|
|
$path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_1 removed',
|
|
|
|
$path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_2 removed',
|
|
|
|
$path . DS . 'level_1_1' . DS . 'level_2_1 removed',
|
|
|
|
$path . DS . 'level_1_1' . DS . 'level_2_2 removed',
|
|
|
|
$path . DS . 'level_1_1 removed',
|
2008-09-08 16:44:06 +00:00
|
|
|
$path . ' removed'
|
|
|
|
);
|
2011-12-15 00:18:11 +00:00
|
|
|
sort($expected);
|
|
|
|
sort($messages);
|
|
|
|
$this->assertEquals($expected, $messages);
|
2008-09-08 16:44:06 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-01 17:54:25 +00:00
|
|
|
/**
|
|
|
|
* testCopy method
|
|
|
|
*
|
2012-09-10 08:23:52 +00:00
|
|
|
* Verify that subdirectories existing in both destination and source directory
|
2012-09-10 21:08:14 +00:00
|
|
|
* are merged recursively.
|
2012-09-10 08:23:52 +00:00
|
|
|
*
|
2012-09-10 17:20:15 +00:00
|
|
|
* @return void
|
2012-09-10 08:23:52 +00:00
|
|
|
*/
|
|
|
|
public function testCopy() {
|
|
|
|
extract($this->_setupFilesystem());
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
|
|
|
$result = $Folder->copy($folderThree);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($folderTwo);
|
|
|
|
$result = $Folder->copy($folderThree);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file2.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderB' . DS . 'fileB.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($path);
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCopyWithMerge method
|
|
|
|
*
|
|
|
|
* Verify that subdirectories existing in both destination and source directory
|
2012-09-10 21:08:14 +00:00
|
|
|
* are merged recursively.
|
2012-09-10 08:23:52 +00:00
|
|
|
*
|
2012-09-10 17:20:15 +00:00
|
|
|
* @return void
|
2012-09-10 08:23:52 +00:00
|
|
|
*/
|
|
|
|
public function testCopyWithMerge() {
|
|
|
|
extract($this->_setupFilesystem());
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
|
|
|
$result = $Folder->copy($folderThree);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($folderTwo);
|
|
|
|
$result = $Folder->copy(array('to' => $folderThree, 'scheme' => Folder::MERGE));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file2.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderB' . DS . 'fileB.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($path);
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCopyWithSkip method
|
|
|
|
*
|
2009-04-01 17:54:25 +00:00
|
|
|
* Verify that directories and files are copied recursively
|
|
|
|
* even if the destination directory already exists.
|
|
|
|
* Subdirectories existing in both destination and source directory
|
|
|
|
* are skipped and not merged or overwritten.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-09-10 08:23:52 +00:00
|
|
|
public function testCopyWithSkip() {
|
|
|
|
extract($this->_setupFilesystem());
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
|
|
|
$result = $Folder->copy(array('to' => $folderTwo, 'scheme' => Folder::SKIP));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($folderTwo);
|
|
|
|
$Folder->delete();
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
|
|
|
$result = $Folder->copy(array('to' => $folderTwo, 'scheme' => Folder::SKIP));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($folderTwo);
|
|
|
|
$Folder->delete();
|
|
|
|
|
|
|
|
new Folder($folderTwo, true);
|
|
|
|
new Folder($folderTwo . DS . 'folderB', true);
|
|
|
|
file_put_contents($folderTwo . DS . 'file2.php', 'touched');
|
|
|
|
file_put_contents($folderTwo . DS . 'folderB' . DS . 'fileB.php', 'untouched');
|
|
|
|
|
|
|
|
$Folder = new Folder($folderTwo);
|
|
|
|
$result = $Folder->copy(array('to' => $folderThree, 'scheme' => Folder::SKIP));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file2.php'));
|
|
|
|
$this->assertEquals('touched', file_get_contents($folderThree . DS . 'file2.php'));
|
|
|
|
$this->assertEquals('untouched', file_get_contents($folderThree . DS . 'folderB' . DS . 'fileB.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($path);
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
2014-09-10 01:33:14 +00:00
|
|
|
/**
|
|
|
|
* Test that SKIP mode skips files too.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCopyWithSkipFileSkipped() {
|
|
|
|
$path = TMP . 'folder_test';
|
|
|
|
$folderOne = $path . DS . 'folder1';
|
|
|
|
$folderTwo = $path . DS . 'folder2';
|
|
|
|
|
|
|
|
new Folder($path, true);
|
|
|
|
new Folder($folderOne, true);
|
|
|
|
new Folder($folderTwo, true);
|
|
|
|
file_put_contents($folderOne . DS . 'fileA.txt', 'Folder One File');
|
|
|
|
file_put_contents($folderTwo . DS . 'fileA.txt', 'Folder Two File');
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
|
|
|
$result = $Folder->copy(array('to' => $folderTwo, 'scheme' => Folder::SKIP));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEquals('Folder Two File', file_get_contents($folderTwo . DS . 'fileA.txt'));
|
|
|
|
}
|
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
/**
|
|
|
|
* testCopyWithOverwrite
|
|
|
|
*
|
|
|
|
* Verify that subdirectories existing in both destination and source directory
|
2012-09-10 21:08:14 +00:00
|
|
|
* are overwritten/replaced recursively.
|
2012-09-10 08:23:52 +00:00
|
|
|
*
|
2012-09-10 17:20:15 +00:00
|
|
|
* @return void
|
2012-09-10 08:23:52 +00:00
|
|
|
*/
|
2012-09-15 02:37:39 +00:00
|
|
|
public function testCopyWithOverwrite() {
|
2012-09-10 08:23:52 +00:00
|
|
|
extract($this->_setupFilesystem());
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
2015-09-25 15:22:00 +00:00
|
|
|
$Folder->copy(array('to' => $folderThree, 'scheme' => Folder::OVERWRITE));
|
2012-09-10 08:23:52 +00:00
|
|
|
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($folderTwo);
|
|
|
|
$result = $Folder->copy(array('to' => $folderThree, 'scheme' => Folder::OVERWRITE));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
|
|
|
unlink($fileOneA);
|
|
|
|
$result = $Folder->copy(array('to' => $folderThree, 'scheme' => Folder::OVERWRITE));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'file2.php'));
|
|
|
|
$this->assertTrue(!file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
$this->assertTrue(file_exists($folderThree . DS . 'folderB' . DS . 'fileB.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($path);
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup filesystem for copy tests
|
2012-09-10 17:20:15 +00:00
|
|
|
* $path: folder_test/
|
|
|
|
* - folder1/file1.php
|
|
|
|
* - folder1/folderA/fileA.php
|
|
|
|
* - folder2/file2.php
|
|
|
|
* - folder2/folderB/fileB.php
|
|
|
|
* - folder3/
|
2012-09-10 08:23:52 +00:00
|
|
|
*
|
2012-09-10 17:20:15 +00:00
|
|
|
* @return array Filenames to extract in the test methods
|
2012-09-10 08:23:52 +00:00
|
|
|
*/
|
|
|
|
protected function _setupFilesystem() {
|
2009-04-01 17:54:25 +00:00
|
|
|
$path = TMP . 'folder_test';
|
2012-09-10 08:23:52 +00:00
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
$folderOne = $path . DS . 'folder1';
|
2012-09-10 08:23:52 +00:00
|
|
|
$folderOneA = $folderOne . DS . 'folderA';
|
|
|
|
$folderTwo = $path . DS . 'folder2';
|
|
|
|
$folderTwoB = $folderTwo . DS . 'folderB';
|
2012-03-14 02:59:20 +00:00
|
|
|
$folderThree = $path . DS . 'folder3';
|
2012-09-10 08:23:52 +00:00
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
$fileOne = $folderOne . DS . 'file1.php';
|
|
|
|
$fileTwo = $folderTwo . DS . 'file2.php';
|
2012-09-10 08:23:52 +00:00
|
|
|
$fileOneA = $folderOneA . DS . 'fileA.php';
|
|
|
|
$fileTwoB = $folderTwoB . DS . 'fileB.php';
|
2009-04-01 17:54:25 +00:00
|
|
|
|
|
|
|
new Folder($path, true);
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderOne, true);
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderOneA, true);
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderTwo, true);
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderTwoB, true);
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderThree, true);
|
|
|
|
touch($fileOne);
|
|
|
|
touch($fileTwo);
|
2012-09-10 08:23:52 +00:00
|
|
|
touch($fileOneA);
|
|
|
|
touch($fileTwoB);
|
|
|
|
|
|
|
|
return compact(
|
|
|
|
'path',
|
|
|
|
'folderOne', 'folderOneA', 'folderTwo', 'folderTwoB', 'folderThree',
|
|
|
|
'fileOne', 'fileOneA', 'fileTwo', 'fileTwoB');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMove method
|
|
|
|
*
|
|
|
|
* Verify that directories and files are moved recursively
|
|
|
|
* even if the destination directory already exists.
|
|
|
|
* Subdirectories existing in both destination and source directory
|
2012-09-10 21:08:14 +00:00
|
|
|
* are merged recursively.
|
2012-09-10 08:23:52 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMove() {
|
|
|
|
extract($this->_setupFilesystem());
|
2012-03-14 02:59:20 +00:00
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
$result = $Folder->move($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$this->assertTrue($result);
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(is_dir($folderTwo . DS . 'folderB'));
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'folderB' . DS . 'fileB.php'));
|
|
|
|
$this->assertFalse(file_exists($fileOne));
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'folderA'));
|
|
|
|
$this->assertFalse(file_exists($folderOneA));
|
|
|
|
$this->assertFalse(file_exists($fileOneA));
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
$Folder = new Folder($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$Folder->delete();
|
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderOne, true);
|
|
|
|
new Folder($folderOneA, true);
|
|
|
|
touch($fileOne);
|
|
|
|
touch($fileOneA);
|
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
$Folder = new Folder($folderOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
$result = $Folder->move($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$this->assertTrue($result);
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(is_dir($folderTwo . DS . 'folderA'));
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'folderA' . DS . 'fileA.php'));
|
|
|
|
$this->assertFalse(file_exists($fileOne));
|
|
|
|
$this->assertFalse(file_exists($folderOneA));
|
|
|
|
$this->assertFalse(file_exists($fileOneA));
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
$Folder = new Folder($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$Folder->delete();
|
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderOne, true);
|
|
|
|
new Folder($folderOneA, true);
|
|
|
|
new Folder($folderTwo, true);
|
|
|
|
new Folder($folderTwoB, true);
|
|
|
|
touch($fileOne);
|
|
|
|
touch($fileOneA);
|
|
|
|
new Folder($folderOne . DS . 'folderB', true);
|
|
|
|
touch($folderOne . DS . 'folderB' . DS . 'fileB.php');
|
|
|
|
file_put_contents($folderTwoB . DS . 'fileB.php', 'untouched');
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
$Folder = new Folder($folderOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
$result = $Folder->move($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$this->assertTrue($result);
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertEquals('', file_get_contents($folderTwoB . DS . 'fileB.php'));
|
|
|
|
$this->assertFalse(file_exists($fileOne));
|
2012-09-15 02:37:39 +00:00
|
|
|
$this->assertFalse(file_exists($folderOneA));
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertFalse(file_exists($fileOneA));
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder($path);
|
2009-04-01 17:54:25 +00:00
|
|
|
$Folder->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-01 17:54:25 +00:00
|
|
|
/**
|
2012-09-10 08:23:52 +00:00
|
|
|
* testMoveWithSkip method
|
2009-04-01 17:54:25 +00:00
|
|
|
*
|
|
|
|
* Verify that directories and files are moved recursively
|
|
|
|
* even if the destination directory already exists.
|
|
|
|
* Subdirectories existing in both destination and source directory
|
|
|
|
* are skipped and not merged or overwritten.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-09-10 08:23:52 +00:00
|
|
|
public function testMoveWithSkip() {
|
|
|
|
extract($this->_setupFilesystem());
|
2012-03-14 02:59:20 +00:00
|
|
|
|
|
|
|
$Folder = new Folder($folderOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
$result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP));
|
2009-04-01 17:54:25 +00:00
|
|
|
$this->assertTrue($result);
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(is_dir($folderTwo . DS . 'folderB'));
|
|
|
|
$this->assertTrue(file_exists($folderTwoB . DS . 'fileB.php'));
|
2012-03-14 02:59:20 +00:00
|
|
|
$this->assertFalse(file_exists($fileOne));
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertFalse(file_exists($folderOneA));
|
|
|
|
$this->assertFalse(file_exists($fileOneA));
|
2012-03-14 02:59:20 +00:00
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
$Folder = new Folder($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$Folder->delete();
|
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderOne, true);
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderOneA, true);
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderTwo, true);
|
|
|
|
touch($fileOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
touch($fileOneA);
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
$Folder = new Folder($folderOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
$result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP));
|
2009-04-01 17:54:25 +00:00
|
|
|
$this->assertTrue($result);
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertTrue(is_dir($folderTwo . DS . 'folderA'));
|
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'folderA' . DS . 'fileA.php'));
|
2012-03-14 02:59:20 +00:00
|
|
|
$this->assertFalse(file_exists($fileOne));
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertFalse(file_exists($folderOneA));
|
|
|
|
$this->assertFalse(file_exists($fileOneA));
|
2012-03-14 02:59:20 +00:00
|
|
|
|
2012-09-10 08:23:52 +00:00
|
|
|
$Folder = new Folder($folderTwo);
|
2009-04-01 17:54:25 +00:00
|
|
|
$Folder->delete();
|
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderOne, true);
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderOneA, true);
|
2012-03-14 02:59:20 +00:00
|
|
|
new Folder($folderTwo, true);
|
2012-09-10 08:23:52 +00:00
|
|
|
new Folder($folderTwoB, true);
|
2012-03-14 02:59:20 +00:00
|
|
|
touch($fileOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
touch($fileOneA);
|
|
|
|
file_put_contents($folderTwoB . DS . 'fileB.php', 'untouched');
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2012-03-14 02:59:20 +00:00
|
|
|
$Folder = new Folder($folderOne);
|
2012-09-10 08:23:52 +00:00
|
|
|
$result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP));
|
2009-04-01 17:54:25 +00:00
|
|
|
$this->assertTrue($result);
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
|
|
|
|
$this->assertEquals('untouched', file_get_contents($folderTwoB . DS . 'fileB.php'));
|
2012-03-14 02:59:20 +00:00
|
|
|
$this->assertFalse(file_exists($fileOne));
|
2012-09-10 08:23:52 +00:00
|
|
|
$this->assertFalse(file_exists($folderOneA));
|
|
|
|
$this->assertFalse(file_exists($fileOneA));
|
2009-04-01 17:54:25 +00:00
|
|
|
|
2010-05-31 02:57:28 +00:00
|
|
|
$Folder = new Folder($path);
|
2009-04-01 17:54:25 +00:00
|
|
|
$Folder->delete();
|
|
|
|
}
|
2012-03-14 02:59:20 +00:00
|
|
|
|
2016-05-12 14:28:04 +00:00
|
|
|
/**
|
|
|
|
* testSortByTime method
|
|
|
|
*
|
|
|
|
* Verify that the order using modified time is correct.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSortByTime() {
|
|
|
|
$Folder = new Folder(TMP . 'test_sort_by_time', true);
|
|
|
|
|
|
|
|
$file2 = new File($Folder->pwd() . DS . 'file_2.tmp');
|
|
|
|
$file2->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
$file1 = new File($Folder->pwd() . DS . 'file_1.tmp');
|
|
|
|
$file1->create();
|
|
|
|
|
|
|
|
$expected = array('file_2.tmp', 'file_1.tmp');
|
|
|
|
$result = $Folder->find('.*', Folder::SORT_TIME);
|
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSortByTime2 method
|
|
|
|
*
|
|
|
|
* Verify that the sort order using modified time is correct.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSortByTime2() {
|
|
|
|
$Folder = new Folder(TMP . 'test_sort_by_time2', true);
|
|
|
|
|
|
|
|
$fileC = new File($Folder->pwd() . DS . 'c.txt');
|
|
|
|
$fileC->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
$fileA = new File($Folder->pwd() . DS . 'a.txt');
|
|
|
|
$fileA->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
$fileB = new File($Folder->pwd() . DS . 'b.txt');
|
|
|
|
$fileB->create();
|
|
|
|
|
|
|
|
$expected = array('c.txt', 'a.txt', 'b.txt');
|
|
|
|
$result = $Folder->find('.*', Folder::SORT_TIME);
|
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that the sort order using name is correct.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSortByName() {
|
|
|
|
$Folder = new Folder(TMP . 'test_sort_by_name', true);
|
|
|
|
|
|
|
|
$fileA = new File($Folder->pwd() . DS . 'a.txt');
|
|
|
|
$fileA->create();
|
|
|
|
|
|
|
|
$fileC = new File($Folder->pwd() . DS . 'c.txt');
|
|
|
|
$fileC->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
$fileB = new File($Folder->pwd() . DS . 'b.txt');
|
|
|
|
$fileB->create();
|
|
|
|
|
|
|
|
$expected = array('a.txt', 'b.txt', 'c.txt');
|
|
|
|
$result = $Folder->find('.*', Folder::SORT_NAME);
|
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|