mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 08:13:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -2,20 +2,20 @@ | |||
| /** | ||||
|  * FolderTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Utility | ||||
|  * @since         CakePHP(tm) v 1.2.0.4206 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Folder', 'Utility'); | ||||
| App::uses('File', 'Utility'); | ||||
| 
 | ||||
|  | @ -29,14 +29,19 @@ class FolderTest extends CakeTestCase { | |||
| 	protected static $_tmp = array(); | ||||
| 
 | ||||
| /** | ||||
|  * Save the directory names in TMP | ||||
|  * Save the directory names in TMP and make sure default directories exist | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public static function setUpBeforeClass() { | ||||
| 		$dirs = array('cache', 'logs', 'sessions', 'tests'); | ||||
| 		foreach ($dirs as $dir) { | ||||
| 			new Folder(TMP . $dir, true); | ||||
| 		} | ||||
| 
 | ||||
| 		foreach (scandir(TMP) as $file) { | ||||
| 			if (is_dir(TMP . $file) && !in_array($file, array('.', '..'))) { | ||||
| 				self::$_tmp[] = $file; | ||||
| 				static::$_tmp[] = $file; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | @ -57,7 +62,7 @@ class FolderTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		$exclude = array_merge(self::$_tmp, array('.', '..')); | ||||
| 		$exclude = array_merge(static::$_tmp, array('.', '..')); | ||||
| 		foreach (scandir(TMP) as $dir) { | ||||
| 			if (is_dir(TMP . $dir) && !in_array($dir, $exclude)) { | ||||
| 				$iterator = new RecursiveDirectoryIterator(TMP . $dir); | ||||
|  | @ -71,6 +76,7 @@ class FolderTest extends CakeTestCase { | |||
| 				rmdir(TMP . $dir); | ||||
| 			} | ||||
| 		} | ||||
| 		parent::tearDown(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -103,28 +109,86 @@ class FolderTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testInPath() { | ||||
| 		$path = dirname(dirname(__FILE__)); | ||||
| 		$inside = dirname($path) . DS; | ||||
| 		// "/Test/test_app/"
 | ||||
| 		$basePath = CAKE . 'Test' . DS . 'test_app' . DS; | ||||
| 		$Base = new Folder($basePath); | ||||
| 
 | ||||
| 		$Folder = new Folder($path); | ||||
| 		$result = $Base->pwd(); | ||||
| 		$this->assertEquals($basePath, $result); | ||||
| 
 | ||||
| 		$result = $Folder->pwd(); | ||||
| 		$this->assertEquals($path, $result); | ||||
| 		// is "/" in "/Test/test_app/"
 | ||||
| 		$result = $Base->inPath(realpath(DS), true); | ||||
| 		$this->assertFalse($result, true); | ||||
| 
 | ||||
| 		$result = Folder::isSlashTerm($inside); | ||||
| 		// is "/Test/test_app/" in "/Test/test_app/"
 | ||||
| 		$result = $Base->inPath($basePath, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $Folder->realpath('Test/'); | ||||
| 		$this->assertEquals($path . DS . 'Test' . DS, $result); | ||||
| 
 | ||||
| 		$result = $Folder->inPath('Test' . DS); | ||||
| 		// is "/Test/test_app" in "/Test/test_app/"
 | ||||
| 		$result = $Base->inPath(mb_substr($basePath, 0, -1), true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $Folder->inPath(DS . 'non-existing' . $inside); | ||||
| 		// is "/Test/test_app/sub" in "/Test/test_app/"
 | ||||
| 		$result = $Base->inPath($basePath . 'sub', true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		// is "/Test" in "/Test/test_app/"
 | ||||
| 		$result = $Base->inPath(dirname($basePath), true); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$result = $Folder->inPath($path . DS . 'Model', true); | ||||
| 		// 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)); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		// 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); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -164,13 +228,29 @@ class FolderTest extends CakeTestCase { | |||
| 		$this->assertTrue($Folder->delete()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test recursive directory create failure. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRecursiveCreateFailure() { | ||||
| 		$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Cant perform operations using permissions on windows.'); | ||||
| 		$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Cant perform operations using permissions on Windows.'); | ||||
| 
 | ||||
| 		$path = TMP . 'tests' . DS . 'one'; | ||||
| 		mkdir($path); | ||||
|  | @ -338,11 +418,24 @@ class FolderTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testAddPathElement() { | ||||
| 		$expected = DS . 'some' . DS . 'dir' . DS . 'another_path'; | ||||
| 
 | ||||
| 		$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path'); | ||||
| 		$this->assertEquals(DS . 'some' . DS . 'dir' . DS . 'another_path', $result); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path'); | ||||
| 		$this->assertEquals(DS . 'some' . DS . 'dir' . DS . 'another_path', $result); | ||||
| 		$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); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -369,7 +462,7 @@ class FolderTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testFolderReadWithHiddenFiles() { | ||||
| 		$this->skipIf(!is_writeable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.'); | ||||
| 		$this->skipIf(!is_writable(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'); | ||||
|  | @ -452,7 +545,7 @@ class FolderTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testFolderTreeWithHiddenFiles() { | ||||
| 		$this->skipIf(!is_writeable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.'); | ||||
| 		$this->skipIf(!is_writable(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); | ||||
|  | @ -529,6 +622,8 @@ class FolderTest extends CakeTestCase { | |||
| 		$this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file')); | ||||
| 		$this->assertFalse(Folder::isAbsolute('\\path/to/file')); | ||||
| 		$this->assertFalse(Folder::isAbsolute('\\path\\to\\file')); | ||||
| 		$this->assertFalse(Folder::isAbsolute('notRegisteredStreamWrapper://example')); | ||||
| 		$this->assertFalse(Folder::isAbsolute('://example')); | ||||
| 
 | ||||
| 		$this->assertTrue(Folder::isAbsolute('/usr/local')); | ||||
| 		$this->assertTrue(Folder::isAbsolute('//path/to/file')); | ||||
|  | @ -536,6 +631,7 @@ class FolderTest extends CakeTestCase { | |||
| 		$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')); | ||||
| 		$this->assertTrue(Folder::isAbsolute('http://www.example.com')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -635,7 +731,7 @@ class FolderTest extends CakeTestCase { | |||
| 		$this->assertSame(array_diff($expected, $result), array()); | ||||
| 
 | ||||
| 		$result = $Folder->find('.*', true); | ||||
| 		$expected = array('config.php', 'routes.php'); | ||||
| 		$expected = array('cacert.pem', 'config.php', 'routes.php'); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 
 | ||||
| 		$result = $Folder->find('.*\.php'); | ||||
|  | @ -761,6 +857,55 @@ class FolderTest extends CakeTestCase { | |||
| 		$Folder->delete($Folder->pwd() . 'config_non_existent'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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); | ||||
| 
 | ||||
| 		chmod($folder, 0555); | ||||
| 		chmod($file, 0444); | ||||
| 
 | ||||
| 		$Folder = new Folder($folder); | ||||
| 		$return = $Folder->delete(); | ||||
| 		$this->assertFalse($return); | ||||
| 
 | ||||
| 		$messages = $Folder->messages(); | ||||
| 		$errors = $Folder->errors(); | ||||
| 		$expected = array( | ||||
| 			$file . ' NOT removed', | ||||
| 			$folder . ' NOT removed', | ||||
| 		); | ||||
| 		sort($expected); | ||||
| 		sort($errors); | ||||
| 		$this->assertEmpty($messages); | ||||
| 		$this->assertEquals($expected, $errors); | ||||
| 
 | ||||
| 		chmod($file, 0644); | ||||
| 		chmod($folder, 0755); | ||||
| 
 | ||||
| 		$return = $Folder->delete(); | ||||
| 		$this->assertTrue($return); | ||||
| 
 | ||||
| 		$messages = $Folder->messages(); | ||||
| 		$errors = $Folder->errors(); | ||||
| 		$expected = array( | ||||
| 			$file . ' removed', | ||||
| 			$folder . ' removed', | ||||
| 		); | ||||
| 		sort($expected); | ||||
| 		sort($messages); | ||||
| 		$this->assertEmpty($errors); | ||||
| 		$this->assertEquals($expected, $messages); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDelete method | ||||
|  * | ||||
|  | @ -803,6 +948,64 @@ class FolderTest extends CakeTestCase { | |||
| /** | ||||
|  * testCopy method | ||||
|  * | ||||
|  * Verify that subdirectories existing in both destination and source directory | ||||
|  * are merged recursively. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	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 | ||||
|  * are merged recursively. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	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 | ||||
|  * | ||||
|  * Verify that directories and files are copied recursively | ||||
|  * even if the destination directory already exists. | ||||
|  * Subdirectories existing in both destination and source directory | ||||
|  | @ -810,128 +1013,357 @@ class FolderTest extends CakeTestCase { | |||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCopy() { | ||||
| 	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(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that SKIP mode skips files too. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCopyWithSkipFileSkipped() { | ||||
| 		$path = TMP . 'folder_test'; | ||||
| 		$folderOne = $path . DS . 'folder1'; | ||||
| 		$folderTwo = $folderOne . DS . 'folder2'; | ||||
| 		$folderThree = $path . DS . 'folder3'; | ||||
| 		$fileOne = $folderOne . DS . 'file1.php'; | ||||
| 		$fileTwo = $folderTwo . DS . 'file2.php'; | ||||
| 		$folderTwo = $path . DS . 'folder2'; | ||||
| 
 | ||||
| 		new Folder($path, true); | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		new Folder($folderThree, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileTwo); | ||||
| 		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($folderThree); | ||||
| 		$result = $Folder->copy(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'file1.php')); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'folder2' . DS . 'file2.php')); | ||||
| 		$this->assertEquals('Folder Two File', file_get_contents($folderTwo . DS . 'fileA.txt')); | ||||
| 	} | ||||
| 
 | ||||
| 		$Folder = new Folder($folderThree); | ||||
| 		$Folder->delete(); | ||||
| /** | ||||
|  * testCopyWithOverwrite | ||||
|  * | ||||
|  * Verify that subdirectories existing in both destination and source directory | ||||
|  * are overwritten/replaced recursively. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCopyWithOverwrite() { | ||||
| 		extract($this->_setupFilesystem()); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->copy($folderThree); | ||||
| 		$this->assertTrue($result); | ||||
| 		$Folder->copy(array('to' => $folderThree, 'scheme' => Folder::OVERWRITE)); | ||||
| 
 | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'file1.php')); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'folder2' . DS . 'file2.php')); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php')); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderThree); | ||||
| 		$Folder->delete(); | ||||
| 		$Folder = new Folder($folderTwo); | ||||
| 		$result = $Folder->copy(array('to' => $folderThree, 'scheme' => Folder::OVERWRITE)); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		new Folder($folderThree, true); | ||||
| 		new Folder($folderThree . DS . 'folder2', true); | ||||
| 		file_put_contents($folderThree . DS . 'folder2' . DS . 'file2.php', 'untouched'); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php')); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->copy($folderThree); | ||||
| 		unlink($fileOneA); | ||||
| 		$result = $Folder->copy(array('to' => $folderThree, 'scheme' => Folder::OVERWRITE)); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'file1.php')); | ||||
| 		$this->assertEquals('untouched', file_get_contents($folderThree . DS . 'folder2' . DS . 'file2.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 | ||||
|  * $path: folder_test/ | ||||
|  * - folder1/file1.php | ||||
|  * - folder1/folderA/fileA.php | ||||
|  * - folder2/file2.php | ||||
|  * - folder2/folderB/fileB.php | ||||
|  * - folder3/ | ||||
|  * | ||||
|  * @return array Filenames to extract in the test methods | ||||
|  */ | ||||
| 	protected function _setupFilesystem() { | ||||
| 		$path = TMP . 'folder_test'; | ||||
| 
 | ||||
| 		$folderOne = $path . DS . 'folder1'; | ||||
| 		$folderOneA = $folderOne . DS . 'folderA'; | ||||
| 		$folderTwo = $path . DS . 'folder2'; | ||||
| 		$folderTwoB = $folderTwo . DS . 'folderB'; | ||||
| 		$folderThree = $path . DS . 'folder3'; | ||||
| 
 | ||||
| 		$fileOne = $folderOne . DS . 'file1.php'; | ||||
| 		$fileTwo = $folderTwo . DS . 'file2.php'; | ||||
| 		$fileOneA = $folderOneA . DS . 'fileA.php'; | ||||
| 		$fileTwoB = $folderTwoB . DS . 'fileB.php'; | ||||
| 
 | ||||
| 		new Folder($path, true); | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderOneA, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		new Folder($folderTwoB, true); | ||||
| 		new Folder($folderThree, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileTwo); | ||||
| 		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 | ||||
|  * are skipped and not merged or overwritten. | ||||
|  * are merged recursively. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMove() { | ||||
| 		$path = TMP . 'folder_test'; | ||||
| 		$folderOne = $path . DS . 'folder1'; | ||||
| 		$folderTwo = $folderOne . DS . 'folder2'; | ||||
| 		$folderThree = $path . DS . 'folder3'; | ||||
| 		$fileOne = $folderOne . DS . 'file1.php'; | ||||
| 		$fileTwo = $folderTwo . DS . 'file2.php'; | ||||
| 
 | ||||
| 		new Folder($path, true); | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		new Folder($folderThree, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileTwo); | ||||
| 		extract($this->_setupFilesystem()); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->move($folderThree); | ||||
| 		$result = $Folder->move($folderTwo); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'file1.php')); | ||||
| 		$this->assertTrue(is_dir($folderThree . DS . 'folder2')); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'folder2' . DS . 'file2.php')); | ||||
| 		$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->assertFalse(file_exists($folderTwo)); | ||||
| 		$this->assertFalse(file_exists($fileTwo)); | ||||
| 		$this->assertTrue(file_exists($folderTwo . DS . 'folderA')); | ||||
| 		$this->assertFalse(file_exists($folderOneA)); | ||||
| 		$this->assertFalse(file_exists($fileOneA)); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderThree); | ||||
| 		$Folder = new Folder($folderTwo); | ||||
| 		$Folder->delete(); | ||||
| 
 | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		new Folder($folderOneA, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileTwo); | ||||
| 		touch($fileOneA); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->move($folderThree); | ||||
| 		$result = $Folder->move($folderTwo); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'file1.php')); | ||||
| 		$this->assertTrue(is_dir($folderThree . DS . 'folder2')); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'folder2' . DS . 'file2.php')); | ||||
| 		$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($folderTwo)); | ||||
| 		$this->assertFalse(file_exists($fileTwo)); | ||||
| 		$this->assertFalse(file_exists($folderOneA)); | ||||
| 		$this->assertFalse(file_exists($fileOneA)); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderThree); | ||||
| 		$Folder = new Folder($folderTwo); | ||||
| 		$Folder->delete(); | ||||
| 
 | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderOneA, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		new Folder($folderThree, true); | ||||
| 		new Folder($folderThree . DS . 'folder2', true); | ||||
| 		new Folder($folderTwoB, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileTwo); | ||||
| 		file_put_contents($folderThree . DS . 'folder2' . DS . 'file2.php', 'untouched'); | ||||
| 		touch($fileOneA); | ||||
| 		new Folder($folderOne . DS . 'folderB', true); | ||||
| 		touch($folderOne . DS . 'folderB' . DS . 'fileB.php'); | ||||
| 		file_put_contents($folderTwoB . DS . 'fileB.php', 'untouched'); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->move($folderThree); | ||||
| 		$result = $Folder->move($folderTwo); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists($folderThree . DS . 'file1.php')); | ||||
| 		$this->assertEquals('untouched', file_get_contents($folderThree . DS . 'folder2' . DS . 'file2.php')); | ||||
| 		$this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); | ||||
| 		$this->assertEquals('', file_get_contents($folderTwoB . DS . 'fileB.php')); | ||||
| 		$this->assertFalse(file_exists($fileOne)); | ||||
| 		$this->assertFalse(file_exists($folderTwo)); | ||||
| 		$this->assertFalse(file_exists($fileTwo)); | ||||
| 		$this->assertFalse(file_exists($folderOneA)); | ||||
| 		$this->assertFalse(file_exists($fileOneA)); | ||||
| 
 | ||||
| 		$Folder = new Folder($path); | ||||
| 		$Folder->delete(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testMoveWithSkip method | ||||
|  * | ||||
|  * 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 | ||||
|  */ | ||||
| 	public function testMoveWithSkip() { | ||||
| 		extract($this->_setupFilesystem()); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); | ||||
| 		$this->assertTrue(is_dir($folderTwo . DS . 'folderB')); | ||||
| 		$this->assertTrue(file_exists($folderTwoB . DS . 'fileB.php')); | ||||
| 		$this->assertFalse(file_exists($fileOne)); | ||||
| 		$this->assertFalse(file_exists($folderOneA)); | ||||
| 		$this->assertFalse(file_exists($fileOneA)); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderTwo); | ||||
| 		$Folder->delete(); | ||||
| 
 | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderOneA, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileOneA); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); | ||||
| 		$this->assertTrue($result); | ||||
| 		$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)); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderTwo); | ||||
| 		$Folder->delete(); | ||||
| 
 | ||||
| 		new Folder($folderOne, true); | ||||
| 		new Folder($folderOneA, true); | ||||
| 		new Folder($folderTwo, true); | ||||
| 		new Folder($folderTwoB, true); | ||||
| 		touch($fileOne); | ||||
| 		touch($fileOneA); | ||||
| 		file_put_contents($folderTwoB . DS . 'fileB.php', 'untouched'); | ||||
| 
 | ||||
| 		$Folder = new Folder($folderOne); | ||||
| 		$result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); | ||||
| 		$this->assertEquals('untouched', file_get_contents($folderTwoB . DS . 'fileB.php')); | ||||
| 		$this->assertFalse(file_exists($fileOne)); | ||||
| 		$this->assertFalse(file_exists($folderOneA)); | ||||
| 		$this->assertFalse(file_exists($fileOneA)); | ||||
| 
 | ||||
| 		$Folder = new Folder($path); | ||||
| 		$Folder->delete(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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(); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko