mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Date & filesystem helper tests
This commit is contained in:
parent
f8e5926deb
commit
0aef5c083d
@ -23,7 +23,7 @@ final class DateHelperTest extends \CIUnitTestCase
|
||||
public function testNowDefault()
|
||||
{
|
||||
$time = new \DateTime();
|
||||
$this->assertLessThan(1, abs(now() - time()));
|
||||
$this->assertLessThan(1, abs(now() - time())); // close enough
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -32,13 +32,6 @@ final class DateHelperTest extends \CIUnitTestCase
|
||||
{
|
||||
// Chicago should be two hours ahead of Vancouver
|
||||
$this->assertEquals(7200,now('America/Chicago')-now('America/Vancouver'));
|
||||
// $zone = 'America/Vancouver';
|
||||
// $time = new \DateTime('now', new \DateTimeZone($zone));
|
||||
// echo now($zone) . '\n';
|
||||
// echo now() . '\n';
|
||||
// echo $time->getTimestamp() . '\n';
|
||||
//
|
||||
// $this->assertLessThan(1, abs(now($zone) - $time->getTimestamp()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,294 +5,201 @@ use org\bovigo\vfs\vfsStream;
|
||||
class FilesystemHelperTest extends \CIUnitTestCase
|
||||
{
|
||||
|
||||
public function testDirectoryMapDefaults()
|
||||
{
|
||||
helper('filesystem');
|
||||
$this->assertTrue(function_exists('directory_map'));
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
$this->structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
}
|
||||
|
||||
$expected = [
|
||||
'foo' . DIRECTORY_SEPARATOR => [
|
||||
'bar',
|
||||
'baz'
|
||||
],
|
||||
'boo' . DIRECTORY_SEPARATOR => [
|
||||
'far',
|
||||
'faz'
|
||||
],
|
||||
'AnEmptyFolder' . DIRECTORY_SEPARATOR => [],
|
||||
'simpleFile'
|
||||
];
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
$root = vfsStream::setup('root', null, $structure);
|
||||
$this->assertTrue($root->hasChild('foo'));
|
||||
public function testDirectoryMapDefaults()
|
||||
{
|
||||
helper('filesystem');
|
||||
$this->assertTrue(function_exists('directory_map'));
|
||||
|
||||
$this->assertEquals($expected, directory_map(vfsStream::url('root')));
|
||||
}
|
||||
$expected = [
|
||||
'foo' . DIRECTORY_SEPARATOR => [
|
||||
'bar',
|
||||
'baz'
|
||||
],
|
||||
'boo' . DIRECTORY_SEPARATOR => [
|
||||
'far',
|
||||
'faz'
|
||||
],
|
||||
'AnEmptyFolder' . DIRECTORY_SEPARATOR => [],
|
||||
'simpleFile'
|
||||
];
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
$root = vfsStream::setup('root', null, $this->structure);
|
||||
$this->assertTrue($root->hasChild('foo'));
|
||||
|
||||
public function testDirectoryMapShowsHiddenFiles()
|
||||
{
|
||||
helper('filesystem');
|
||||
$this->assertTrue(function_exists('directory_map'));
|
||||
$this->assertEquals($expected, directory_map(vfsStream::url('root')));
|
||||
}
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
public function testDirectoryMapShowsHiddenFiles()
|
||||
{
|
||||
helper('filesystem');
|
||||
$this->assertTrue(function_exists('directory_map'));
|
||||
|
||||
$expected = [
|
||||
'foo' . DIRECTORY_SEPARATOR => [
|
||||
'bar',
|
||||
'baz'
|
||||
],
|
||||
'boo' . DIRECTORY_SEPARATOR => [
|
||||
'far',
|
||||
'faz'
|
||||
],
|
||||
'AnEmptyFolder' . DIRECTORY_SEPARATOR => [],
|
||||
'simpleFile',
|
||||
'.hidden'
|
||||
];
|
||||
$expected = [
|
||||
'foo' . DIRECTORY_SEPARATOR => [
|
||||
'bar',
|
||||
'baz'
|
||||
],
|
||||
'boo' . DIRECTORY_SEPARATOR => [
|
||||
'far',
|
||||
'faz'
|
||||
],
|
||||
'AnEmptyFolder' . DIRECTORY_SEPARATOR => [],
|
||||
'simpleFile',
|
||||
'.hidden'
|
||||
];
|
||||
|
||||
$root = vfsStream::setup('root', null, $structure);
|
||||
$this->assertTrue($root->hasChild('foo'));
|
||||
$root = vfsStream::setup('root', null, $this->structure);
|
||||
$this->assertTrue($root->hasChild('foo'));
|
||||
|
||||
$this->assertEquals($expected, directory_map(vfsStream::url('root'), false, true));
|
||||
}
|
||||
$this->assertEquals($expected, directory_map(vfsStream::url('root'), false, true));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
public function testDirectoryMapLimitsRecursion()
|
||||
{
|
||||
$this->assertTrue(function_exists('directory_map'));
|
||||
|
||||
public function testDirectoryMapLimitsRecursion()
|
||||
{
|
||||
$this->assertTrue(function_exists('directory_map'));
|
||||
$expected = [
|
||||
'foo' . DIRECTORY_SEPARATOR,
|
||||
'boo' . DIRECTORY_SEPARATOR,
|
||||
'AnEmptyFolder' . DIRECTORY_SEPARATOR,
|
||||
'simpleFile',
|
||||
'.hidden'
|
||||
];
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
$root = vfsStream::setup('root', null, $this->structure);
|
||||
$this->assertTrue($root->hasChild('foo'));
|
||||
|
||||
$expected = [
|
||||
'foo' . DIRECTORY_SEPARATOR,
|
||||
'boo' . DIRECTORY_SEPARATOR,
|
||||
'AnEmptyFolder' . DIRECTORY_SEPARATOR,
|
||||
'simpleFile',
|
||||
'.hidden'
|
||||
];
|
||||
$this->assertEquals($expected, directory_map(vfsStream::url('root'), 1, true));
|
||||
}
|
||||
|
||||
$root = vfsStream::setup('root', null, $structure);
|
||||
$this->assertTrue($root->hasChild('foo'));
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
$this->assertEquals($expected, directory_map(vfsStream::url('root'), 1, true));
|
||||
}
|
||||
public function testWriteFileSuccess()
|
||||
{
|
||||
$vfs = vfsStream::setup('root');
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
$this->assertTrue(write_file(vfsStream::url('root/test.php'), 'Simple'));
|
||||
$this->assertFileExists($vfs->getChild('test.php')->url());
|
||||
}
|
||||
|
||||
public function testWriteFileSuccess()
|
||||
{
|
||||
$vfs = vfsStream::setup('root');
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
$this->assertTrue(write_file(vfsStream::url('root/test.php'), 'Simple'));
|
||||
$this->assertFileExists($vfs->getChild('test.php')->url());
|
||||
}
|
||||
public function testDeleteFilesDefaultsToOneLevelDeep()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
$vfs = vfsStream::setup('root', null, $this->structure);
|
||||
|
||||
public function testDeleteFilesDefaultsToOneLevelDeep()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
delete_files(vfsStream::url('root'));
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
$this->assertFalse($vfs->hasChild('simpleFile'));
|
||||
$this->assertFalse($vfs->hasChild('.hidden'));
|
||||
$this->assertTrue($vfs->hasChild('foo'));
|
||||
$this->assertTrue($vfs->hasChild('boo'));
|
||||
$this->assertTrue($vfs->hasChild('AnEmptyFolder'));
|
||||
}
|
||||
|
||||
$vfs = vfsStream::setup('root', null, $structure);
|
||||
public function testDeleteFilesHandlesRecursion()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
|
||||
delete_files(vfsStream::url('root'));
|
||||
$vfs = vfsStream::setup('root', null, $this->structure);
|
||||
|
||||
$this->assertFalse($vfs->hasChild('simpleFile'));
|
||||
$this->assertFalse($vfs->hasChild('.hidden'));
|
||||
$this->assertTrue($vfs->hasChild('foo'));
|
||||
$this->assertTrue($vfs->hasChild('boo'));
|
||||
$this->assertTrue($vfs->hasChild('AnEmptyFolder'));
|
||||
}
|
||||
delete_files(vfsStream::url('root'), true);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
$this->assertFalse($vfs->hasChild('simpleFile'));
|
||||
$this->assertFalse($vfs->hasChild('.hidden'));
|
||||
$this->assertFalse($vfs->hasChild('foo'));
|
||||
$this->assertFalse($vfs->hasChild('boo'));
|
||||
$this->assertFalse($vfs->hasChild('AnEmptyFolder'));
|
||||
}
|
||||
|
||||
public function testDeleteFilesHandlesRecursion()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
public function testDeleteFilesLeavesHTFiles()
|
||||
{
|
||||
$structure = array_merge($this->structure, [
|
||||
'.htaccess' => 'Deny All',
|
||||
'index.html' => 'foo',
|
||||
'index.php' => 'blah'
|
||||
]);
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
$vfs = vfsStream::setup('root', null, $structure);
|
||||
|
||||
$vfs = vfsStream::setup('root', null, $structure);
|
||||
delete_files(vfsStream::url('root'), true, true);
|
||||
|
||||
delete_files(vfsStream::url('root'), true);
|
||||
$this->assertFalse($vfs->hasChild('simpleFile'));
|
||||
$this->assertFalse($vfs->hasChild('foo'));
|
||||
$this->assertFalse($vfs->hasChild('boo'));
|
||||
$this->assertFalse($vfs->hasChild('AnEmptyFolder'));
|
||||
$this->assertTrue($vfs->hasChild('.htaccess'));
|
||||
$this->assertTrue($vfs->hasChild('index.html'));
|
||||
$this->assertTrue($vfs->hasChild('index.php'));
|
||||
}
|
||||
|
||||
$this->assertFalse($vfs->hasChild('simpleFile'));
|
||||
$this->assertFalse($vfs->hasChild('.hidden'));
|
||||
$this->assertFalse($vfs->hasChild('foo'));
|
||||
$this->assertFalse($vfs->hasChild('boo'));
|
||||
$this->assertFalse($vfs->hasChild('AnEmptyFolder'));
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
public function testGetFilenames()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
|
||||
public function testDeleteFilesLeavesHTFiles()
|
||||
{
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon',
|
||||
'.htaccess' => 'Deny All',
|
||||
'index.html' => 'foo',
|
||||
'index.php' => 'blah'
|
||||
];
|
||||
// Not sure the directory names should actually show up
|
||||
// here but this matches v3.x results.
|
||||
$expected = [
|
||||
'foo',
|
||||
'boo',
|
||||
'AnEmptyFolder',
|
||||
'simpleFile'
|
||||
];
|
||||
|
||||
$vfs = vfsStream::setup('root', null, $structure);
|
||||
$vfs = vfsStream::setup('root', null, $this->structure);
|
||||
|
||||
delete_files(vfsStream::url('root'), true, true);
|
||||
$this->assertEquals($expected, get_filenames($vfs->url(), false));
|
||||
}
|
||||
|
||||
$this->assertFalse($vfs->hasChild('simpleFile'));
|
||||
$this->assertFalse($vfs->hasChild('foo'));
|
||||
$this->assertFalse($vfs->hasChild('boo'));
|
||||
$this->assertFalse($vfs->hasChild('AnEmptyFolder'));
|
||||
$this->assertTrue($vfs->hasChild('.htaccess'));
|
||||
$this->assertTrue($vfs->hasChild('index.html'));
|
||||
$this->assertTrue($vfs->hasChild('index.php'));
|
||||
}
|
||||
public function testGetFilenamesWithSource()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Not sure the directory names should actually show up
|
||||
// here but this matches v3.x results.
|
||||
$expected = [
|
||||
DIRECTORY_SEPARATOR . 'foo',
|
||||
DIRECTORY_SEPARATOR . 'boo',
|
||||
DIRECTORY_SEPARATOR . 'AnEmptyFolder',
|
||||
DIRECTORY_SEPARATOR . 'simpleFile'
|
||||
];
|
||||
|
||||
public function testGetFilenames()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
$vfs = vfsStream::setup('root', null, $this->structure);
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
|
||||
// Not sure the directory names should actually show up
|
||||
// here but this matches v3.x results.
|
||||
$expected = [
|
||||
'foo',
|
||||
'boo',
|
||||
'AnEmptyFolder',
|
||||
'simpleFile'
|
||||
];
|
||||
|
||||
$vfs = vfsStream::setup('root', null, $structure);
|
||||
|
||||
$this->assertEquals($expected, get_filenames($vfs->url(), false));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testGetFilenamesWithSource()
|
||||
{
|
||||
$this->assertTrue(function_exists('delete_files'));
|
||||
|
||||
$structure = [
|
||||
'foo' => [
|
||||
'bar' => 'Once upon a midnight dreary',
|
||||
'baz' => 'While I pondered weak and weary'
|
||||
],
|
||||
'boo' => [
|
||||
'far' => 'Upon a tome of long-forgotten lore',
|
||||
'faz' => 'There came a tapping up on the door'
|
||||
],
|
||||
'AnEmptyFolder' => [],
|
||||
'simpleFile' => 'A tap-tap-tapping upon my door',
|
||||
'.hidden' => 'There is no spoon'
|
||||
];
|
||||
|
||||
// Not sure the directory names should actually show up
|
||||
// here but this matches v3.x results.
|
||||
$expected = [
|
||||
DIRECTORY_SEPARATOR . 'foo',
|
||||
DIRECTORY_SEPARATOR . 'boo',
|
||||
DIRECTORY_SEPARATOR . 'AnEmptyFolder',
|
||||
DIRECTORY_SEPARATOR . 'simpleFile'
|
||||
];
|
||||
|
||||
$vfs = vfsStream::setup('root', null, $structure);
|
||||
|
||||
$this->assertEquals($expected, get_filenames($vfs->url(), true));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
$this->assertEquals($expected, get_filenames($vfs->url(), true));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testGetFileInfo(){
|
||||
$vfs = vfsStream::setup('root', null, $this->structure);
|
||||
|
||||
$this->assertEquals($expected, get_filenames($vfs->url(), true));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user