Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,20 +2,20 @@
/**
* FileTest 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('File', 'Utility');
App::uses('Folder', 'Utility');
@ -23,13 +23,14 @@ App::uses('Folder', 'Utility');
* FileTest class
*
* @package Cake.Test.Case.Utility
* @coversDefaultClass File
*/
class FileTest extends CakeTestCase {
/**
* File property
*
* @var mixed null
* @var mixed
*/
public $File = null;
@ -62,6 +63,15 @@ class FileTest extends CakeTestCase {
* testBasic method
*
* @return void
* @covers ::__construct
* @covers ::info
* @covers ::ext
* @covers ::name
* @covers ::md5
* @covers ::size
* @covers ::owner
* @covers ::group
* @covers ::Folder
*/
public function testBasic() {
$file = CAKE . DS . 'LICENSE.txt';
@ -81,8 +91,7 @@ class FileTest extends CakeTestCase {
'filesize' => filesize($file),
'mime' => 'text/plain'
);
if (
!function_exists('finfo_open') &&
if (!function_exists('finfo_open') &&
(!function_exists('mime_content_type') ||
function_exists('mime_content_type') &&
mime_content_type($this->File->pwd()) === false)
@ -125,13 +134,14 @@ class FileTest extends CakeTestCase {
/**
* testPermission method
*
* @return void
* @covers ::perms
*/
public function testPermission() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'File permissions tests not supported on Windows.');
$dir = TMP . 'tests' . DS . 'permissions' . DS;
$Folder = new Folder($dir);
$old = umask();
umask(0002);
@ -173,6 +183,7 @@ class FileTest extends CakeTestCase {
* testRead method
*
* @return void
* @covers ::read
*/
public function testRead() {
$file = __FILE__;
@ -204,6 +215,7 @@ class FileTest extends CakeTestCase {
* testOffset method
*
* @return void
* @covers ::offset
*/
public function testOffset() {
$this->File->close();
@ -217,25 +229,26 @@ class FileTest extends CakeTestCase {
$this->assertTrue(is_resource($this->File->handle));
$result = $this->File->offset();
$expecting = 0;
$this->assertSame($result, $expecting);
$expected = 0;
$this->assertSame($expected, $result);
$data = file_get_contents(__FILE__);
$success = $this->File->offset(5);
$expecting = substr($data, 5, 3);
$expected = substr($data, 5, 3);
$result = $this->File->read(3);
$this->assertTrue($success);
$this->assertEquals($expecting, $result);
$this->assertEquals($expected, $result);
$result = $this->File->offset();
$expecting = 5 + 3;
$this->assertSame($result, $expecting);
$expected = 5 + 3;
$this->assertSame($expected, $result);
}
/**
* testOpen method
*
* @return void
* @covers ::open
*/
public function testOpen() {
$this->File->handle = null;
@ -260,6 +273,7 @@ class FileTest extends CakeTestCase {
* testClose method
*
* @return void
* @covers ::close
*/
public function testClose() {
$this->File->handle = null;
@ -277,6 +291,9 @@ class FileTest extends CakeTestCase {
* testCreate method
*
* @return void
* @covers ::create
* @covers ::exists
* @covers ::clearStatCache
*/
public function testCreate() {
$tmpFile = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
@ -284,10 +301,29 @@ class FileTest extends CakeTestCase {
$this->assertTrue($File->exists());
}
/**
* Tests the exists() method.
*
* @return void
*/
public function testExists() {
$tmpFile = TMP . 'tests/cakephp.file.test.tmp';
$file = new File($tmpFile, true, 0777);
$this->assertTrue($file->exists(), 'absolute path should exist');
$file = new File('file://' . $tmpFile, false);
$this->assertTrue($file->exists(), 'file:// should exist.');
$file = new File('/something/bad', false);
$this->assertFalse($file->exists(), 'missing file should not exist.');
}
/**
* testOpeningNonExistentFileCreatesIt method
*
* @return void
* @covers ::open
* @covers ::create
*/
public function testOpeningNonExistentFileCreatesIt() {
$someFile = new File(TMP . 'some_file.txt', false);
@ -301,26 +337,28 @@ class FileTest extends CakeTestCase {
* testPrepare method
*
* @return void
* @covers ::prepare
*/
public function testPrepare() {
$string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere";
if (DS == '\\') {
if (DS === '\\') {
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
} else {
$expected = "some\nvery\ncool\nteststring here\n\n\nfor\n\n\n\n\nhere";
}
$this->assertSame(File::prepare($string), $expected);
$this->assertSame($expected, File::prepare($string));
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
$this->assertSame(File::prepare($string, true), $expected);
$this->assertSame($expected, File::prepare($string, true));
}
/**
* testReadable method
*
* @return void
* @covers ::readable
*/
public function testReadable() {
$someFile = new File(TMP . 'some_file.txt', false);
@ -334,6 +372,7 @@ class FileTest extends CakeTestCase {
* testWritable method
*
* @return void
* @covers ::writable
*/
public function testWritable() {
$someFile = new File(TMP . 'some_file.txt', false);
@ -347,6 +386,7 @@ class FileTest extends CakeTestCase {
* testExecutable method
*
* @return void
* @covers ::executable
*/
public function testExecutable() {
$someFile = new File(TMP . 'some_file.txt', false);
@ -360,6 +400,7 @@ class FileTest extends CakeTestCase {
* testLastAccess method
*
* @return void
* @covers ::lastAccess
*/
public function testLastAccess() {
$someFile = new File(TMP . 'some_file.txt', false);
@ -374,6 +415,7 @@ class FileTest extends CakeTestCase {
* testLastChange method
*
* @return void
* @covers ::lastChange
*/
public function testLastChange() {
$someFile = new File(TMP . 'some_file.txt', false);
@ -392,11 +434,12 @@ class FileTest extends CakeTestCase {
* testWrite method
*
* @return void
* @covers ::write
*/
public function testWrite() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
};
}
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
@ -422,11 +465,12 @@ class FileTest extends CakeTestCase {
* testAppend method
*
* @return void
* @covers ::append
*/
public function testAppend() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
};
}
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
@ -434,22 +478,31 @@ class FileTest extends CakeTestCase {
$TmpFile = new File($tmpFile);
$this->assertFalse(file_exists($tmpFile));
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
$fragments = array('CakePHP\'s', ' test suite', ' was here ...');
$data = null;
$size = 0;
foreach ($fragments as $fragment) {
$r = $TmpFile->append($fragment);
$this->assertTrue($r);
$this->assertTrue(file_exists($tmpFile));
$data = $data . $fragment;
$this->assertEquals($data, file_get_contents($tmpFile));
$newSize = $TmpFile->size();
$this->assertTrue($newSize > $size);
$size = $newSize;
$TmpFile->close();
}
$TmpFile->append('');
$this->assertEquals($data, file_get_contents($tmpFile));
$TmpFile->close();
}
/**
* testDelete method
*
* @return void
* @covers ::delete
*/
public function testDelete() {
if (!$tmpFile = $this->_getTmpFile()) {
@ -475,6 +528,7 @@ class FileTest extends CakeTestCase {
* active filehandles open.
*
* @return void
* @covers ::delete
*/
public function testDeleteAfterRead() {
if (!$tmpFile = $this->_getTmpFile()) {
@ -492,6 +546,7 @@ class FileTest extends CakeTestCase {
* testCopy method
*
* @return void
* @covers ::copy
*/
public function testCopy() {
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
@ -520,13 +575,14 @@ class FileTest extends CakeTestCase {
* Test mime()
*
* @return void
* @covers ::mime
*/
public function testMime() {
$this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$file = new File($path);
$expected = 'image/gif';
if (function_exists('mime_content_type') && false === mime_content_type($file->pwd())) {
if (function_exists('mime_content_type') && mime_content_type($file->pwd()) === false) {
$expected = false;
}
$this->assertEquals($expected, $file->mime());
@ -542,7 +598,7 @@ class FileTest extends CakeTestCase {
$tmpFile = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
if (is_writable(dirname($tmpFile)) && (!file_exists($tmpFile) || is_writable($tmpFile))) {
return $tmpFile;
};
}
if ($paintSkip) {
$trace = debug_backtrace();
@ -554,4 +610,54 @@ class FileTest extends CakeTestCase {
}
return false;
}
/**
* testReplaceText method
*
* @return void
* @covers ::replaceText
*/
public function testReplaceText() {
$TestFile = new File(dirname(__FILE__) . '/../../test_app/Vendor/welcome.php');
$TmpFile = new File(TMP . 'tests' . DS . 'cakephp.file.test.tmp');
// Copy the test file to the temporary location
$TestFile->copy($TmpFile->path, true);
// Replace the contents of the tempory file
$result = $TmpFile->replaceText('welcome.php', 'welcome.tmp');
$this->assertTrue($result);
// Double check
$expected = 'This is the welcome.tmp file in vendors directory';
$contents = $TmpFile->read();
$this->assertContains($expected, $contents);
$search = array('This is the', 'welcome.php file', 'in tmp directory');
$replace = array('This should be a', 'welcome.tmp file', 'in the Lib directory');
// Replace the contents of the tempory file
$result = $TmpFile->replaceText($search, $replace);
$this->assertTrue($result);
// Double check
$expected = 'This should be a welcome.tmp file in vendors directory';
$contents = $TmpFile->read();
$this->assertContains($expected, $contents);
$TmpFile->delete();
}
/**
* Tests that no path is being set for passed file paths that
* do not exist.
*
* @return void
* @covers ::pwd
*/
public function testNoPartialPathBeingSetForNonExistentPath() {
$tmpFile = new File('/non/existent/file');
$this->assertNull($tmpFile->pwd());
$this->assertNull($tmpFile->path);
}
}