Skip to content
Snippets Groups Projects
Commit 35ebf646 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Christian Kuhn
Browse files

[TASK] Tests: Decouple InstallTool unit tests from real filesystem

Change the FolderStructure tests to use a vfsStream virtual filesystem
for all tests that work with files, directories and permissions to make
the tests less reliant on the capabilities of the user running the
testsuite and the real filesystem.

Resolves: #71053
Releases: master
Change-Id: Ife42f43008215b382f70d5fe956d3dcf9590f5b9
Reviewed-on: https://review.typo3.org/44301


Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent c1eae866
Branches
Tags
No related merge requests found
...@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; ...@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
/** /**
* Test case * Test case
*/ */
class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase class AbstractNodeTest extends \TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase
{ {
/** /**
* @test * @test
...@@ -116,15 +116,14 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -116,15 +116,14 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestDir('dir_');
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$this->assertTrue($node->_call('exists')); $this->assertTrue($node->_call('exists'));
} }
/** /**
* @test * @test
* @see https://github.com/mikey179/vfsStream/wiki/Known-Issues - symlink doesn't work with vfsStream
*/ */
public function existsReturnsTrueIfIsLinkAndTargetIsDead() public function existsReturnsTrueIfIsLinkAndTargetIsDead()
{ {
...@@ -148,7 +147,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -148,7 +147,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$this->assertFalse($node->_call('exists')); $this->assertFalse($node->_call('exists'));
} }
...@@ -193,12 +192,10 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -193,12 +192,10 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
); );
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue('')); $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
$node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false)); $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false));
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_'); $path = $this->getVirtualTestDir('root_');
mkdir($path);
$subPath = $path . '/' . $this->getUniqueId('dir_'); $subPath = $path . '/' . $this->getUniqueId('dir_');
mkdir($subPath); mkdir($subPath);
chmod($path, 02000); chmod($path, 02000);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
$node->_set('targetPermission', '2770'); $node->_set('targetPermission', '2770');
$this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $node->_call('fixPermission')); $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $node->_call('fixPermission'));
...@@ -226,12 +223,10 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -226,12 +223,10 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
); );
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue('')); $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
$node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false)); $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false));
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_'); $path = $this->getVirtualTestDir('root_');
mkdir($path);
$subPath = $path . '/' . $this->getUniqueId('dir_'); $subPath = $path . '/' . $this->getUniqueId('dir_');
mkdir($subPath); mkdir($subPath);
chmod($path, 02000); chmod($path, 02000);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
$node->_set('targetPermission', '2770'); $node->_set('targetPermission', '2770');
$this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $node->_call('fixPermission')); $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $node->_call('fixPermission'));
...@@ -256,12 +251,10 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -256,12 +251,10 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
); );
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue('')); $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
$node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false)); $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(false));
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_'); $path = $this->getVirtualTestDir('root_');
mkdir($path);
$subPath = $path . '/' . $this->getUniqueId('dir_'); $subPath = $path . '/' . $this->getUniqueId('dir_');
mkdir($subPath); mkdir($subPath);
chmod($path, 02770); chmod($path, 02770);
$this->testFilesToDelete[] = $path;
$node->_set('targetPermission', '2770'); $node->_set('targetPermission', '2770');
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
$this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $node->_call('fixPermission')); $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $node->_call('fixPermission'));
...@@ -303,9 +296,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -303,9 +296,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
} }
/** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestDir('dir_');
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
chmod($path, 02775); chmod($path, 02775);
clearstatcache(); clearstatcache();
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
...@@ -322,9 +313,8 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -322,9 +313,8 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
} }
/** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\AbstractNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array('getAbsolutePath'), array(), '', false);
$file = PATH_site . 'typo3temp/' . $this->getUniqueId('file_'); $file = $this->getVirtualTestFilePath('file_');
touch($file); touch($file);
$this->testFilesToDelete[] = $file;
chmod($file, 0770); chmod($file, 0770);
clearstatcache(); clearstatcache();
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
......
...@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; ...@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
/** /**
* Test case * Test case
*/ */
class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase class DirectoryNodeTest extends \TYPO3\CMS\Install\Tests\Unit\FolderStructureTestCase
{ {
/** /**
* @test * @test
...@@ -123,13 +123,14 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -123,13 +123,14 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock( $node = $this->getAccessibleMock(
\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'), array('getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
array(), array(),
'', '',
false false
); );
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestDir('dir_');
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->expects($this->any())->method('exists')->will($this->returnValue(true)); $node->expects($this->any())->method('exists')->will($this->returnValue(true));
$node->expects($this->any())->method('isDirectory')->will($this->returnValue(true)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(true));
$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true)); $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
...@@ -145,13 +146,14 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -145,13 +146,14 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock( $node = $this->getAccessibleMock(
\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'), array('getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
array(), array(),
'', '',
false false
); );
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestDir('dir_');
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->expects($this->any())->method('exists')->will($this->returnValue(false)); $node->expects($this->any())->method('exists')->will($this->returnValue(false));
$node->expects($this->any())->method('isDirectory')->will($this->returnValue(false)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(false));
$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false)); $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false));
...@@ -170,15 +172,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -170,15 +172,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock( $node = $this->getAccessibleMock(
\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'), array('getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
array(), array(),
'', '',
false false
); );
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
touch($path); touch($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->expects($this->any())->method('exists')->will($this->returnValue(true)); $node->expects($this->any())->method('exists')->will($this->returnValue(true));
$node->expects($this->any())->method('isDirectory')->will($this->returnValue(false)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(false));
$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true)); $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
...@@ -197,15 +199,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -197,15 +199,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock( $node = $this->getAccessibleMock(
\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'), array('getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
array(), array(),
'', '',
false false
); );
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
touch($path); touch($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->expects($this->any())->method('exists')->will($this->returnValue(true)); $node->expects($this->any())->method('exists')->will($this->returnValue(true));
$node->expects($this->any())->method('isDirectory')->will($this->returnValue(true)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(true));
$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true)); $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
...@@ -224,15 +226,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -224,15 +226,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock( $node = $this->getAccessibleMock(
\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'), array('getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
array(), array(),
'', '',
false false
); );
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
touch($path); touch($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->expects($this->any())->method('exists')->will($this->returnValue(true)); $node->expects($this->any())->method('exists')->will($this->returnValue(true));
$node->expects($this->any())->method('isDirectory')->will($this->returnValue(true)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(true));
$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false)); $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(false));
...@@ -251,15 +253,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -251,15 +253,15 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock( $node = $this->getAccessibleMock(
\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, \TYPO3\CMS\Install\FolderStructure\DirectoryNode::class,
array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'), array('getAbsolutePath', 'getRelativePathBelowSiteRoot', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
array(), array(),
'', '',
false false
); );
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
touch($path); touch($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->expects($this->any())->method('exists')->will($this->returnValue(true)); $node->expects($this->any())->method('exists')->will($this->returnValue(true));
$node->expects($this->any())->method('isDirectory')->will($this->returnValue(true)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(true));
$node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true)); $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(true));
...@@ -444,11 +446,11 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -444,11 +446,11 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
public function createDirectoryCreatesDirectory() public function createDirectoryCreatesDirectory()
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
$this->testFilesToDelete[] = $path;
$node->expects($this->once())->method('exists')->will($this->returnValue(false)); $node->expects($this->once())->method('exists')->will($this->returnValue(false));
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$node->_call('createDirectory'); $node->_call('createDirectory');
$this->assertTrue(is_dir($path)); $this->assertTrue(is_dir($path));
} }
...@@ -459,11 +461,11 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -459,11 +461,11 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
public function createDirectoryReturnsOkStatusIfDirectoryWasCreated() public function createDirectoryReturnsOkStatusIfDirectoryWasCreated()
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
$this->testFilesToDelete[] = $path;
$node->expects($this->once())->method('exists')->will($this->returnValue(false)); $node->expects($this->once())->method('exists')->will($this->returnValue(false));
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($path));
$this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createDirectory')); $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createDirectory'));
} }
...@@ -476,14 +478,13 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -476,14 +478,13 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
$this->markTestSkipped('Test not available on Windows OS.'); $this->markTestSkipped('Test not available on Windows OS.');
} }
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('exists', 'getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_'); $path = $this->getVirtualTestDir('root_');
mkdir($path);
chmod($path, 02550); chmod($path, 02550);
$subPath = $path . '/' . $this->getUniqueId('dir_'); $subPath = $path . '/' . $this->getUniqueId('dir_');
$this->testFilesToDelete[] = $path;
$node->expects($this->once())->method('exists')->will($this->returnValue(false)); $node->expects($this->once())->method('exists')->will($this->returnValue(false));
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
$node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue($subPath));
$this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createDirectory')); $this->assertInstanceOf(\TYPO3\CMS\Install\Status\StatusInterface::class, $node->_call('createDirectory'));
} }
...@@ -574,7 +575,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -574,7 +575,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestFilePath('dir_');
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$this->assertFalse($node->isWritable()); $this->assertFalse($node->isWritable());
} }
...@@ -586,9 +587,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -586,9 +587,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_'); $path = $this->getVirtualTestDir('root_');
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$this->assertTrue($node->isWritable()); $this->assertTrue($node->isWritable());
} }
...@@ -606,9 +605,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -606,9 +605,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
} }
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_'); $path = $this->getVirtualTestDir('root_');
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
chmod($path, 02550); chmod($path, 02550);
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$this->assertFalse($node->isWritable()); $this->assertFalse($node->isWritable());
...@@ -621,15 +618,14 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -621,15 +618,14 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{ {
/** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
$node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false); $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\DirectoryNode::class, array('getAbsolutePath'), array(), '', false);
$path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_'); $path = $this->getVirtualTestDir('dir_');
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
$node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
$this->assertTrue($node->_call('isDirectory')); $this->assertTrue($node->_call('isDirectory'));
} }
/** /**
* @test * @test
* @see https://github.com/mikey179/vfsStream/wiki/Known-Issues - symlink doesn't work with vfsStream
*/ */
public function isDirectoryReturnsFalseIfNameIsALinkToADirectory() public function isDirectoryReturnsFalseIfNameIsALinkToADirectory()
{ {
......
...@@ -338,6 +338,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -338,6 +338,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** /**
* @test * @test
* @see https://github.com/mikey179/vfsStream/wiki/Known-Issues - symlink doesn't work with vfsStream
*/ */
public function isTargetCorrectReturnsTrueIfActualTargetIsIdenticalToSpecifiedTarget() public function isTargetCorrectReturnsTrueIfActualTargetIsIdenticalToSpecifiedTarget()
{ {
...@@ -364,6 +365,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase ...@@ -364,6 +365,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
/** /**
* @test * @test
* @see https://github.com/mikey179/vfsStream/wiki/Known-Issues - symlink doesn't work with vfsStream
*/ */
public function isTargetCorrectReturnsFalseIfActualTargetIsNotIdenticalToSpecifiedTarget() public function isTargetCorrectReturnsFalseIfActualTargetIsNotIdenticalToSpecifiedTarget()
{ {
......
<?php
namespace TYPO3\CMS\Install\Tests\Unit;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use org\bovigo\vfs\vfsStream;
/**
* Test case
*/
abstract class FolderStructureTestCase extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
/**
* Create a random directory in the virtual file system and return the path.
*
* @param string $prefix
* @return string
*/
protected function getVirtualTestDir($prefix = 'root_')
{
$root = vfsStream::setup();
$path = $root->url() . '/typo3temp/' . $this->getUniqueId($prefix);
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path);
return $path;
}
/**
* Return a random test filename within a virtual test directory
*
* @param string $prefix
* @return string
*/
protected function getVirtualTestFilePath($prefix = 'file_')
{
return $this->getVirtualTestDir() . '/' . $this->getUniqueId($prefix);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment