View source
<?php
namespace org\bovigo\vfs;
require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
class vfsStreamWrapperMkDirTestCase extends vfsStreamWrapperBaseTestCase {
public function mkdirNoNewRoot() {
$this
->assertFalse(mkdir(vfsStream::url('another')));
$this
->assertEquals(2, count($this->foo
->getChildren()));
$this
->assertSame($this->foo, vfsStreamWrapper::getRoot());
}
public function mkdirNoNewRootRecursively() {
$this
->assertFalse(mkdir(vfsStream::url('another/more'), 0777, true));
$this
->assertEquals(2, count($this->foo
->getChildren()));
$this
->assertSame($this->foo, vfsStreamWrapper::getRoot());
}
public function mkdirNonRecursively() {
$this
->assertFalse(mkdir($this->barURL . '/another/more'));
$this
->assertEquals(2, count($this->foo
->getChildren()));
$this
->assertTrue(mkdir($this->fooURL . '/another'));
$this
->assertEquals(3, count($this->foo
->getChildren()));
$this
->assertEquals(0777, $this->foo
->getChild('another')
->getPermissions());
}
public function mkdirRecursively() {
$this
->assertTrue(mkdir($this->fooURL . '/another/more', 0777, true));
$this
->assertEquals(3, count($this->foo
->getChildren()));
$another = $this->foo
->getChild('another');
$this
->assertTrue($another
->hasChild('more'));
$this
->assertEquals(0777, $this->foo
->getChild('another')
->getPermissions());
$this
->assertEquals(0777, $this->foo
->getChild('another')
->getChild('more')
->getPermissions());
}
public function mkdirWithDots() {
$this
->assertTrue(mkdir($this->fooURL . '/another/../more/.', 0777, true));
$this
->assertEquals(3, count($this->foo
->getChildren()));
$this
->assertTrue($this->foo
->hasChild('more'));
}
public function mkdirWithoutRootCreatesNewRoot() {
vfsStreamWrapper::register();
$this
->assertTrue(@mkdir(vfsStream::url('foo')));
$this
->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()
->getType());
$this
->assertEquals('foo', vfsStreamWrapper::getRoot()
->getName());
$this
->assertEquals(0777, vfsStreamWrapper::getRoot()
->getPermissions());
}
public function mkdirOnFileReturnsFalse() {
$this
->assertFalse(mkdir($this->baz1URL . '/another/more', 0777, true));
}
public function mkdirNonRecursivelyDifferentPermissions() {
$this
->assertTrue(mkdir($this->fooURL . '/another', 0755));
$this
->assertEquals(0755, $this->foo
->getChild('another')
->getPermissions());
}
public function mkdirRecursivelyDifferentPermissions() {
$this
->assertTrue(mkdir($this->fooURL . '/another/more', 0755, true));
$this
->assertEquals(3, count($this->foo
->getChildren()));
$another = $this->foo
->getChild('another');
$this
->assertTrue($another
->hasChild('more'));
$this
->assertEquals(0755, $this->foo
->getChild('another')
->getPermissions());
$this
->assertEquals(0755, $this->foo
->getChild('another')
->getChild('more')
->getPermissions());
}
public function mkdirRecursivelyUsesDefaultPermissions() {
$this->foo
->chmod(0700);
$this
->assertTrue(mkdir($this->fooURL . '/another/more', 0777, true));
$this
->assertEquals(3, count($this->foo
->getChildren()));
$another = $this->foo
->getChild('another');
$this
->assertTrue($another
->hasChild('more'));
$this
->assertEquals(0777, $this->foo
->getChild('another')
->getPermissions());
$this
->assertEquals(0777, $this->foo
->getChild('another')
->getChild('more')
->getPermissions());
}
public function mkdirWithoutRootCreatesNewRootDifferentPermissions() {
vfsStreamWrapper::register();
$this
->assertTrue(@mkdir(vfsStream::url('foo'), 0755));
$this
->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()
->getType());
$this
->assertEquals('foo', vfsStreamWrapper::getRoot()
->getName());
$this
->assertEquals(0755, vfsStreamWrapper::getRoot()
->getPermissions());
}
public function mkdirWithoutRootCreatesNewRootWithDefaultPermissions() {
vfsStreamWrapper::register();
$this
->assertTrue(@mkdir(vfsStream::url('foo')));
$this
->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()
->getType());
$this
->assertEquals('foo', vfsStreamWrapper::getRoot()
->getName());
$this
->assertEquals(0777, vfsStreamWrapper::getRoot()
->getPermissions());
}
public function mkdirDirCanNotCreateNewDirInNonWritingDirectory() {
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
vfsStreamWrapper::getRoot()
->addChild(new vfsStreamDirectory('restrictedFolder', 00));
$this
->assertFalse(is_writable(vfsStream::url('root/restrictedFolder/')));
$this
->assertFalse(mkdir(vfsStream::url('root/restrictedFolder/newFolder')));
$this
->assertFalse(vfsStreamWrapper::getRoot()
->hasChild('restrictedFolder/newFolder'));
}
public function mkDirShouldNotOverwriteExistingDirectories() {
vfsStream::setup('root');
$dir = vfsStream::url('root/dir');
$this
->assertTrue(mkdir($dir));
$this
->assertFalse(@mkdir($dir));
}
public function mkDirShouldNotOverwriteExistingDirectoriesAndTriggerE_USER_WARNING() {
vfsStream::setup('root');
$dir = vfsStream::url('root/dir');
$this
->assertTrue(mkdir($dir));
$this
->assertFalse(mkdir($dir));
}
public function mkDirShouldNotOverwriteExistingFiles() {
$root = vfsStream::setup('root');
vfsStream::newFile('test.txt')
->at($root);
$this
->assertFalse(@mkdir(vfsStream::url('root/test.txt')));
}
public function mkDirShouldNotOverwriteExistingFilesAndTriggerE_USER_WARNING() {
$root = vfsStream::setup('root');
vfsStream::newFile('test.txt')
->at($root);
$this
->assertFalse(mkdir(vfsStream::url('root/test.txt')));
}
public function canNotIterateOverNonReadableDirectory() {
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 00));
$this
->assertFalse(@opendir(vfsStream::url('root')));
$this
->assertFalse(@dir(vfsStream::url('root')));
}
public function is_dir() {
$this
->assertTrue(is_dir($this->fooURL));
$this
->assertTrue(is_dir($this->fooURL . '/.'));
$this
->assertTrue(is_dir($this->barURL));
$this
->assertTrue(is_dir($this->barURL . '/.'));
$this
->assertFalse(is_dir($this->baz1URL));
$this
->assertFalse(is_dir($this->baz2URL));
$this
->assertFalse(is_dir($this->fooURL . '/another'));
$this
->assertFalse(is_dir(vfsStream::url('another')));
}
public function canNotUnlinkDirectoryWithoutRoot() {
vfsStreamWrapper::register();
$this
->assertFalse(@rmdir(vfsStream::url('foo')));
}
public function rmdirCanNotRemoveFiles() {
$this
->assertFalse(rmdir($this->baz1URL));
$this
->assertFalse(rmdir($this->baz2URL));
}
public function rmdirCanNotRemoveNonExistingDirectory() {
$this
->assertFalse(rmdir($this->fooURL . '/another'));
}
public function rmdirCanNotRemoveNonEmptyDirectory() {
$this
->assertFalse(rmdir($this->fooURL));
$this
->assertFalse(rmdir($this->barURL));
}
public function rmdirCanRemoveEmptyDirectory() {
vfsStream::newDirectory('empty')
->at($this->foo);
$this
->assertTrue($this->foo
->hasChild('empty'));
$this
->assertTrue(rmdir($this->fooURL . '/empty'));
$this
->assertFalse($this->foo
->hasChild('empty'));
}
public function rmdirCanRemoveEmptyDirectoryWithDot() {
vfsStream::newDirectory('empty')
->at($this->foo);
$this
->assertTrue($this->foo
->hasChild('empty'));
$this
->assertTrue(rmdir($this->fooURL . '/empty/.'));
$this
->assertFalse($this->foo
->hasChild('empty'));
}
public function rmdirCanRemoveEmptyRoot() {
$this->foo
->removeChild('bar');
$this->foo
->removeChild('baz2');
$this
->assertTrue(rmdir($this->fooURL));
$this
->assertFalse(file_exists($this->fooURL));
$this
->assertNull(vfsStreamWrapper::getRoot());
}
public function rmdirDirCanNotRemoveDirFromNonWritingDirectory() {
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 00));
vfsStreamWrapper::getRoot()
->addChild(new vfsStreamDirectory('nonRemovableFolder'));
$this
->assertFalse(is_writable(vfsStream::url('root')));
$this
->assertFalse(rmdir(vfsStream::url('root/nonRemovableFolder')));
$this
->assertTrue(vfsStreamWrapper::getRoot()
->hasChild('nonRemovableFolder'));
}
public function issue17() {
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0770));
vfsStreamWrapper::getRoot()
->chgrp(vfsStream::GROUP_USER_1)
->chown(vfsStream::OWNER_USER_1);
$this
->assertFalse(mkdir(vfsStream::url('root/doesNotWork')));
$this
->assertFalse(vfsStreamWrapper::getRoot()
->hasChild('doesNotWork'));
}
public function accessWithDoubleDotReturnsCorrectContent() {
$this
->assertEquals('baz2', file_get_contents(vfsStream::url('foo/bar/../baz2')));
}
public function accessWithExcessDoubleDotsReturnsCorrectContent() {
$this
->assertEquals('baz2', file_get_contents(vfsStream::url('foo/../../../../bar/../baz2')));
}
public function alwaysResolvesRootDirectoryAsOwnParentWithDoubleDot() {
vfsStreamWrapper::getRoot()
->chown(vfsStream::OWNER_USER_1);
$this
->assertTrue(is_dir(vfsStream::url('foo/..')));
$stat = stat(vfsStream::url('foo/..'));
$this
->assertEquals(vfsStream::OWNER_USER_1, $stat['uid']);
}
public function unlinkCanNotRemoveNonEmptyDirectory() {
try {
$this
->assertFalse(unlink($this->barURL));
} catch (\PHPUnit_Framework_Error $fe) {
$this
->assertEquals('unlink(vfs://foo/bar): Operation not permitted', $fe
->getMessage());
}
$this
->assertTrue($this->foo
->hasChild('bar'));
$this
->assertFileExists($this->barURL);
}
public function unlinkCanNotRemoveEmptyDirectory() {
vfsStream::newDirectory('empty')
->at($this->foo);
try {
$this
->assertTrue(unlink($this->fooURL . '/empty'));
} catch (\PHPUnit_Framework_Error $fe) {
$this
->assertEquals('unlink(vfs://foo/empty): Operation not permitted', $fe
->getMessage());
}
$this
->assertTrue($this->foo
->hasChild('empty'));
$this
->assertFileExists($this->fooURL . '/empty');
}
public function canCreateFolderOfSameNameAsParentFolder() {
$root = vfsStream::setup('testFolder');
mkdir(vfsStream::url('testFolder') . '/testFolder/subTestFolder', 0777, true);
$this
->assertTrue(file_exists(vfsStream::url('testFolder/testFolder/subTestFolder/.')));
}
public function canRetrieveFolderOfSameNameAsParentFolder() {
$root = vfsStream::setup('testFolder');
mkdir(vfsStream::url('testFolder') . '/testFolder/subTestFolder', 0777, true);
$this
->assertTrue($root
->hasChild('testFolder'));
$this
->assertNotNull($root
->getChild('testFolder'));
}
}