summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/helpers/file_helper_test.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-10-05 21:45:41 +0200
committerAndrey Andreev <narf@bofh.bg>2012-10-05 21:45:41 +0200
commit5b5021812ea6dc859312e00b6b0f078eea54c88d (patch)
tree0a8840ee0429cc405cb597438a73d03bca970c1a /tests/codeigniter/helpers/file_helper_test.php
parent49d08053257b55db511eaca08b8ab5d12149f3b6 (diff)
parentdbad54e09a39a77c7404dee9ca1a6b34299469d0 (diff)
Merge upstream branch
Diffstat (limited to 'tests/codeigniter/helpers/file_helper_test.php')
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php143
1 files changed, 70 insertions, 73 deletions
diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php
index 4b9c29485..9b03da9d7 100644
--- a/tests/codeigniter/helpers/file_helper_test.php
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -5,24 +5,23 @@ class File_helper_Test extends CI_TestCase {
public function set_up()
{
$this->helper('file');
-
+
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
-
+
$this->_test_dir = vfsStreamWrapper::getRoot();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_read_file()
{
$this->assertFalse(read_file('does_not_exist'));
-
+
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
- $file = vfsStream::newFile('my_file.txt')->withContent($content)
- ->at($this->_test_dir);
-
+
+ $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir);
+
$this->assertEquals($content, read_file(vfsStream::url('my_file.txt')));
}
@@ -31,126 +30,124 @@ class File_helper_Test extends CI_TestCase {
public function test_octal_permissions()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('777', octal_permissions($file->getPermissions()));
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('777', octal_permissions($file->getPermissions()));
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
/**
* More tests should happen here, since I'm not hitting the whole function.
*/
public function test_symbolic_permissions()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
public function test_get_mime_by_extension()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('text/plain',
- get_mime_by_extension(vfsStream::url('my_file.txt')));
-
- // Test a mime with an array, such as png
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt')));
+
+ // Test a mime with an array, such as png
$file = vfsStream::newFile('foo.png')->at($this->_test_dir);
-
- $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
-
+
+ $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
+
// Test a file not in the mimes array
$file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir);
-
+
$this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar')));
}
- // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
public function test_get_file_info()
{
// Test Bad File
$this->assertFalse(get_file_info('i_am_bad_boo'));
-
+
// Test the rest
-
+
// First pass in an array
$vals = array(
'name', 'server_path', 'size', 'date',
- 'readable', 'writable', 'executable', 'fileperms'
+ 'readable', 'writable', 'executable', 'fileperms'
);
-
+
$this->_test_get_file_info($vals);
// Test passing in vals as a string.
- $vals = 'name, server_path, size, date, readable, writable, executable, fileperms';
- $this->_test_get_file_info($vals);
+ $this->_test_get_file_info(implode(', ', $vals));
}
-
+
private function _test_get_file_info($vals)
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
$last_modified = time() - 86400;
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified($last_modified)
- ->at($this->_test_dir);
-
+ ->lastModified($last_modified)
+ ->at($this->_test_dir);
+
$ret_values = array(
- 'name' => 'my_file.txt',
- 'server_path' => 'vfs://my_file.txt',
- 'size' => 57,
- 'date' => $last_modified,
+ 'name' => 'my_file.txt',
+ 'server_path' => 'vfs://my_file.txt',
+ 'size' => 57,
+ 'date' => $last_modified,
'readable' => TRUE,
- 'writable' => TRUE,
- 'executable' => TRUE,
+ 'writable' => TRUE,
+ 'executable' => TRUE,
'fileperms' => 33279
);
-
+
$info = get_file_info(vfsStream::url('my_file.txt'), $vals);
-
+
foreach ($info as $k => $v)
{
$this->assertEquals($ret_values[$k], $v);
}
}
-
- // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
// Skipping for now, as it's not implemented in vfsStreamWrapper
// flock(): vfsStreamWrapper::stream_lock is not implemented!
-
+
// public function test_write_file()
// {
- // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
- // {
- // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
- // }
- //
- // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
- //
- // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
- // ->lastModified(time() - 86400)
- // ->at($this->_test_dir);
- //
- // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
- //
+ // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
+ // {
+ // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
+ // }
+ //
+ // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ //
+ // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
+ // ->lastModified(time() - 86400)
+ // ->at($this->_test_dir);
+ //
+ // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
+ //
// }
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
} \ No newline at end of file