*/ class FileSystemComponentTest extends TestCase { /** @var common_configuration_FileSystemComponent */ private $subject; protected function setUp(): void { parent::setUp(); $this->subject = new common_configuration_FileSystemComponent( '/path', 'rw', false, false, false ); } public function testGetters() { $this->assertEquals('/path', $this->subject->getLocation()); $this->assertEquals('rw', $this->subject->getExpectedRights()); $this->assertFalse($this->subject->isOptional()); $this->assertFalse($this->subject->getRecursive()); $this->assertFalse($this->subject->getMustCheckIfEmpty()); } public function testSetters() { $this->subject->setLocation('/otherPath'); $this->subject->setExpectedRights('r'); $this->subject->setOptional(true); $this->subject->setRecursive(true); $this->subject->setMustCheckIfEmpty(true); $this->assertEquals('/otherPath', $this->subject->getLocation()); $this->assertEquals('r', $this->subject->getExpectedRights()); $this->assertTrue($this->subject->isOptional()); $this->assertTrue($this->subject->getRecursive()); $this->assertTrue($this->subject->getMustCheckIfEmpty()); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testIsReadable() { vfsStream::setup('testDir1', 0777); $this->assertTrue($this->subject->isReadable(vfsStream::url('testDir1'))); vfsStream::setup('testDir2', 0333); $this->assertFalse($this->subject->isWritable(vfsStream::url('testDir2'))); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testIsWritable() { vfsStream::setup('testDir3', 0777); $this->assertTrue($this->subject->isWritable(vfsStream::url('testDir3'))); vfsStream::setup('testDir4', 0555); $this->assertFalse($this->subject->isWritable(vfsStream::url('testDir4'))); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testIsExecutable() { vfsStream::setup('testDir5', 0777); file_put_contents(vfsStream::url('testDir5/test.txt'), 'data'); chmod(vfsStream::url('testDir5/test.txt'), 0777); $this->assertTrue($this->subject->isExecutable(vfsStream::url('testDir5/test.txt'))); vfsStream::setup('testDir6', 0777); file_put_contents(vfsStream::url('testDir6/test.txt'), 'data'); chmod(vfsStream::url('testDir6/test.txt'), 0666); $this->assertFalse($this->subject->isExecutable(vfsStream::url('testDir6/test.txt'))); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testCheckDirectoryPermissionsSuccess() { vfsStream::setup('testDir7', 0777); $this->subject->setLocation(vfsStream::url('testDir7')); $this->subject->setExpectedRights('rw'); $output = $this->subject->check(); $this->assertEquals(common_configuration_Report::VALID, $output->getStatus()); $this->assertEquals( "File system component 'tao.configuration.filesystem' in 'vfs://testDir7 is compliant with expected rights (rw).'", $output->getMessage() ); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testCheckFilePermissionsSuccess() { vfsStream::setup('testDir8', 0777); file_put_contents(vfsStream::url('testDir8/test.txt'), 'data'); chmod(vfsStream::url('testDir8/test.txt'), 0777); $this->subject->setLocation(vfsStream::url('testDir8/test.txt')); $this->subject->setExpectedRights('rwx'); $output = $this->subject->check(); $this->assertEquals(common_configuration_Report::VALID, $output->getStatus()); $this->assertEquals( "File system component 'tao.configuration.filesystem' in 'vfs://testDir8/test.txt is compliant with expected rights (rwx).'", $output->getMessage() ); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testCheckDirectoryContentFailure() { vfsStream::setup('testDir9', 0777); file_put_contents(vfsStream::url('testDir9/test.txt'), 'data'); chmod(vfsStream::url('testDir9/test.txt'), 0777); $this->subject->setLocation(vfsStream::url('testDir9')); $this->subject->setExpectedRights('rw'); $this->subject->setMustCheckIfEmpty(true); $output = $this->subject->check(); $this->assertEquals(common_configuration_Report::INVALID, $output->getStatus()); $this->assertEquals( "File system component 'tao.configuration.filesystem' in 'vfs://testDir9 is not empty.", $output->getMessage() ); } /** * @depends testSkipIfVfsStreamNotAvailable */ public function testCheckDirectoryContentSuccess() { vfsStream::setup('testDir10', 0777); $this->subject->setLocation(vfsStream::url('testDir10')); $this->subject->setExpectedRights('rw'); $this->subject->setMustCheckIfEmpty(true); $output = $this->subject->check(); $this->assertEquals(common_configuration_Report::VALID, $output->getStatus()); $this->assertEquals( "File system component 'tao.configuration.filesystem' in 'vfs://testDir10 is compliant with expected rights (rw).'", $output->getMessage() ); } /** * @doesNotPerformAssertions */ public function testSkipIfVfsStreamNotAvailable() { if (!class_exists('org\bovigo\vfs\vfsStream')) { $this->markTestSkipped('VfsStream is not available.'); } } }