2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FileTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
App::import('Core', 'File');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FileTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class FileTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* File property
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var mixed null
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $File = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-31 02:46:42 +00:00
|
|
|
/**
|
|
|
|
* setup the test case
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$file = __FILE__;
|
|
|
|
$this->File = new File($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tear down for test.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function teardown() {
|
|
|
|
parent::teardown();
|
|
|
|
$this->File->close();
|
|
|
|
unset($this->File);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBasic method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testBasic() {
|
|
|
|
$file = __FILE__;
|
|
|
|
|
|
|
|
$result = $this->File->pwd();
|
|
|
|
$expecting = $file;
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->name;
|
|
|
|
$expecting = basename(__FILE__);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->info();
|
2008-10-15 12:42:03 +00:00
|
|
|
$expecting = array(
|
|
|
|
'dirname' => dirname(__FILE__), 'basename' => basename(__FILE__),
|
|
|
|
'extension' => 'php', 'filename' =>'file.test'
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->ext();
|
|
|
|
$expecting = 'php';
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->name();
|
|
|
|
$expecting = 'file.test';
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->md5();
|
|
|
|
$expecting = md5_file($file);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->md5(true);
|
|
|
|
$expecting = md5_file($file);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->size();
|
|
|
|
$expecting = filesize($file);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->owner();
|
|
|
|
$expecting = fileowner($file);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->group();
|
|
|
|
$expecting = filegroup($file);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->Folder();
|
|
|
|
$this->assertIsA($result, 'Folder');
|
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s File permissions tests not supported on Windows');
|
2008-11-08 03:47:09 +00:00
|
|
|
$result = $this->File->perms();
|
|
|
|
$expecting = '0644';
|
|
|
|
$this->assertEqual($result, $expecting);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRead method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRead() {
|
2010-05-29 16:47:31 +00:00
|
|
|
$file = __FILE__;
|
|
|
|
$this->File =& new File($file);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->File->read();
|
|
|
|
$expecting = file_get_contents(__FILE__);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
$this->assertTrue(!is_resource($this->File->handle));
|
|
|
|
|
2008-10-15 12:42:03 +00:00
|
|
|
$this->File->lock = true;
|
|
|
|
$result = $this->File->read();
|
|
|
|
$expecting = file_get_contents(__FILE__);
|
2010-05-30 15:16:40 +00:00
|
|
|
$this->assertEqual($result, trim($expecting));
|
2008-10-15 12:42:03 +00:00
|
|
|
$this->File->lock = null;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = $expecting;
|
|
|
|
$expecting = substr($data, 0, 3);
|
|
|
|
$result = $this->File->read(3);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
$this->assertTrue(is_resource($this->File->handle));
|
|
|
|
|
|
|
|
$expecting = substr($data, 3, 3);
|
|
|
|
$result = $this->File->read(3);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOffset method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testOffset() {
|
|
|
|
$this->File->close();
|
|
|
|
|
|
|
|
$result = $this->File->offset();
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$this->assertFalse(is_resource($this->File->handle));
|
|
|
|
$success = $this->File->offset(0);
|
|
|
|
$this->assertTrue($success);
|
|
|
|
$this->assertTrue(is_resource($this->File->handle));
|
|
|
|
|
|
|
|
$result = $this->File->offset();
|
|
|
|
$expecting = 0;
|
|
|
|
$this->assertIdentical($result, $expecting);
|
|
|
|
|
|
|
|
$data = file_get_contents(__FILE__);
|
|
|
|
$success = $this->File->offset(5);
|
|
|
|
$expecting = substr($data, 5, 3);
|
|
|
|
$result = $this->File->read(3);
|
|
|
|
$this->assertTrue($success);
|
|
|
|
$this->assertEqual($result, $expecting);
|
|
|
|
|
|
|
|
$result = $this->File->offset();
|
|
|
|
$expecting = 5+3;
|
|
|
|
$this->assertIdentical($result, $expecting);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOpen method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testOpen() {
|
|
|
|
$this->File->handle = null;
|
|
|
|
|
|
|
|
$r = $this->File->open();
|
|
|
|
$this->assertTrue(is_resource($this->File->handle));
|
|
|
|
$this->assertTrue($r);
|
|
|
|
|
|
|
|
$handle = $this->File->handle;
|
|
|
|
$r = $this->File->open();
|
|
|
|
$this->assertTrue($r);
|
|
|
|
$this->assertTrue($handle === $this->File->handle);
|
|
|
|
$this->assertTrue(is_resource($this->File->handle));
|
|
|
|
|
|
|
|
$r = $this->File->open('r', true);
|
|
|
|
$this->assertTrue($r);
|
|
|
|
$this->assertFalse($handle === $this->File->handle);
|
|
|
|
$this->assertTrue(is_resource($this->File->handle));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testClose method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testClose() {
|
|
|
|
$this->File->handle = null;
|
|
|
|
$this->assertFalse(is_resource($this->File->handle));
|
|
|
|
$this->assertTrue($this->File->close());
|
|
|
|
$this->assertFalse(is_resource($this->File->handle));
|
|
|
|
|
|
|
|
$this->File->handle = fopen(__FILE__, 'r');
|
|
|
|
$this->assertTrue(is_resource($this->File->handle));
|
|
|
|
$this->assertTrue($this->File->close());
|
|
|
|
$this->assertFalse(is_resource($this->File->handle));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testCreate method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testCreate() {
|
|
|
|
$tmpFile = TMP.'tests'.DS.'cakephp.file.test.tmp';
|
2010-05-31 02:46:42 +00:00
|
|
|
$File = new File($tmpFile, true, 0777);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($File->exists());
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOpeningNonExistantFileCreatesIt method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testOpeningNonExistantFileCreatesIt() {
|
2010-05-31 02:46:42 +00:00
|
|
|
$someFile = new File(TMP . 'some_file.txt', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($someFile->open());
|
|
|
|
$this->assertEqual($someFile->read(), '');
|
|
|
|
$someFile->close();
|
|
|
|
$someFile->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPrepare method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPrepare() {
|
|
|
|
$string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere";
|
2008-11-08 03:47:09 +00:00
|
|
|
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";
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical(File::prepare($string), $expected);
|
|
|
|
|
2008-10-15 12:42:03 +00:00
|
|
|
$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";
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical(File::prepare($string, true), $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testReadable method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testReadable() {
|
2010-05-31 02:46:42 +00:00
|
|
|
$someFile = new File(TMP . 'some_file.txt', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($someFile->open());
|
|
|
|
$this->assertTrue($someFile->readable());
|
|
|
|
$someFile->close();
|
|
|
|
$someFile->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testWritable method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testWritable() {
|
2010-05-31 02:46:42 +00:00
|
|
|
$someFile = new File(TMP . 'some_file.txt', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($someFile->open());
|
|
|
|
$this->assertTrue($someFile->writable());
|
|
|
|
$someFile->close();
|
|
|
|
$someFile->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testExecutable method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testExecutable() {
|
2010-05-31 02:46:42 +00:00
|
|
|
$someFile = new File(TMP . 'some_file.txt', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($someFile->open());
|
|
|
|
$this->assertFalse($someFile->executable());
|
|
|
|
$someFile->close();
|
|
|
|
$someFile->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLastAccess method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLastAccess() {
|
2010-05-31 02:46:42 +00:00
|
|
|
$someFile = new File(TMP . 'some_file.txt', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($someFile->lastAccess());
|
|
|
|
$this->assertTrue($someFile->open());
|
|
|
|
$this->assertEqual($someFile->lastAccess(), time());
|
|
|
|
$someFile->close();
|
|
|
|
$someFile->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLastChange method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLastChange() {
|
2010-05-31 02:46:42 +00:00
|
|
|
$someFile = new File(TMP . 'some_file.txt', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($someFile->lastChange());
|
|
|
|
$this->assertTrue($someFile->open('r+'));
|
|
|
|
$this->assertEqual($someFile->lastChange(), time());
|
|
|
|
$someFile->write('something');
|
|
|
|
$this->assertEqual($someFile->lastChange(), time());
|
|
|
|
$someFile->close();
|
|
|
|
$someFile->delete();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testWrite method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testWrite() {
|
|
|
|
if (!$tmpFile = $this->_getTmpFile()) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
if (file_exists($tmpFile)) {
|
|
|
|
unlink($tmpFile);
|
|
|
|
}
|
|
|
|
|
2010-05-31 02:46:42 +00:00
|
|
|
$TmpFile = new File($tmpFile);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse(file_exists($tmpFile));
|
|
|
|
$this->assertFalse(is_resource($TmpFile->handle));
|
|
|
|
|
|
|
|
$testData = array('CakePHP\'s', ' test suite', ' was here ...', '');
|
|
|
|
foreach ($testData as $data) {
|
|
|
|
$r = $TmpFile->write($data);
|
|
|
|
$this->assertTrue($r);
|
|
|
|
$this->assertTrue(file_exists($tmpFile));
|
|
|
|
$this->assertEqual($data, file_get_contents($tmpFile));
|
|
|
|
$this->assertTrue(is_resource($TmpFile->handle));
|
|
|
|
$TmpFile->close();
|
|
|
|
|
|
|
|
}
|
|
|
|
unlink($tmpFile);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAppend method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAppend() {
|
|
|
|
if (!$tmpFile = $this->_getTmpFile()) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
if (file_exists($tmpFile)) {
|
|
|
|
unlink($tmpFile);
|
|
|
|
}
|
|
|
|
|
2010-05-31 02:46:42 +00:00
|
|
|
$TmpFile = new File($tmpFile);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse(file_exists($tmpFile));
|
|
|
|
|
|
|
|
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
|
|
|
|
$data = null;
|
|
|
|
foreach ($fragments as $fragment) {
|
|
|
|
$r = $TmpFile->append($fragment);
|
|
|
|
$this->assertTrue($r);
|
|
|
|
$this->assertTrue(file_exists($tmpFile));
|
|
|
|
$data = $data.$fragment;
|
|
|
|
$this->assertEqual($data, file_get_contents($tmpFile));
|
|
|
|
$TmpFile->close();
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDelete method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDelete() {
|
|
|
|
if (!$tmpFile = $this->_getTmpFile()) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!file_exists($tmpFile)) {
|
|
|
|
touch($tmpFile);
|
|
|
|
}
|
2010-05-31 02:46:42 +00:00
|
|
|
$TmpFile = new File($tmpFile);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(file_exists($tmpFile));
|
|
|
|
$result = $TmpFile->delete();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertFalse(file_exists($tmpFile));
|
|
|
|
|
2010-05-31 02:46:42 +00:00
|
|
|
$TmpFile = new File('/this/does/not/exist');
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $TmpFile->delete();
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-09 03:27:31 +00:00
|
|
|
/**
|
|
|
|
* testCopy method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCopy() {
|
|
|
|
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
|
|
|
|
$file = __FILE__;
|
2010-05-31 02:46:42 +00:00
|
|
|
$this->File = new File($file);
|
2009-10-09 03:27:31 +00:00
|
|
|
$result = $this->File->copy($dest);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->File->copy($dest, true);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->File->copy($dest, false);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$this->File->close();
|
|
|
|
unlink($dest);
|
|
|
|
|
2010-05-31 02:46:42 +00:00
|
|
|
$TmpFile = new File('/this/does/not/exist');
|
2009-10-09 03:27:31 +00:00
|
|
|
$result = $TmpFile->copy($dest);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$TmpFile->close();
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* getTmpFile method
|
2008-09-12 05:11:34 +00:00
|
|
|
*
|
|
|
|
* @param bool $paintSkip
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access protected
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function _getTmpFile($paintSkip = true) {
|
2010-05-29 16:47:31 +00:00
|
|
|
$tmpFile = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_writable(dirname($tmpFile)) && (!file_exists($tmpFile) || is_writable($tmpFile))) {
|
|
|
|
return $tmpFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($paintSkip) {
|
|
|
|
$caller = 'test';
|
|
|
|
if (function_exists('debug_backtrace')) {
|
|
|
|
$trace = debug_backtrace();
|
2010-05-29 16:47:31 +00:00
|
|
|
$caller = $trace[1]['function'] . '()';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$assertLine = new SimpleStackTrace(array(__FUNCTION__));
|
|
|
|
$assertLine = $assertLine->traceMethod();
|
|
|
|
$shortPath = substr($tmpFile, strlen(ROOT));
|
|
|
|
|
2008-10-15 12:42:03 +00:00
|
|
|
$message = '[FileTest] Skipping %s because "%s" not writeable!';
|
2010-04-15 16:38:12 +00:00
|
|
|
$message = sprintf(__($message), $caller, $shortPath).$assertLine;
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_reporter->paintSkip($message);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|