21 \Hamcrest\Util::registerGlobalFunctions();
50 private \ILIAS\Filesystem\Provider\FlySystem\FlySystemDirectoryAccess|\Mockery\MockInterface
$subject;
55 private \ILIAS\Filesystem\Provider\FlySystem\FlySystemFileAccess|\Mockery\MockInterface
$fileAccessMock;
60 protected function setUp(): void
64 $this->filesystemMock = Mockery::mock(FilesystemOperator::class);
65 $this->fileAccessMock = Mockery::mock(FlySystemFileAccess::class);
76 $path =
'/path/to/dir';
79 ->shouldReceive(
'directoryExists')
83 $exists = $this->subject->hasDir(
$path);
84 $this->assertTrue($exists);
93 $path =
'/path/to/file';
96 ->shouldReceive(
'directoryExists')
100 $exists = $this->subject->hasDir(
$path);
101 $this->assertFalse($exists);
110 $path =
'/path/to/dir';
112 $this->filesystemMock
113 ->shouldReceive(
'directoryExists')
117 $exists = $this->subject->hasDir(
$path);
118 $this->assertFalse($exists);
125 public function testListContentsWhichShouldSucceed():
void 127 $path =
'/path/to/dir';
128 $file = [
'type' =>
'file',
'path' =>
$path];
129 $dir = [
'type' =>
'dir',
'path' =>
$path];
132 FileAttributes::fromArray($file),
133 DirectoryAttributes::fromArray($dir)
135 $contentListContainer =
new DirectoryListing($content_list);
139 $this->filesystemMock
140 ->shouldReceive(
'directoryExists')
145 ->shouldReceive(
'listContents')
147 ->withArgs([
$path,
false])
148 ->andReturn($contentListContainer);
154 $content = $this->subject->listContents(
$path);
156 $this->assertSame($content_list[0][
'type'], $content[0]->getType());
157 $this->assertSame($content_list[0][
'path'], $content[0]->getPath());
158 $this->assertTrue($content[0]->isFile());
159 $this->assertFalse($content[0]->isDir());
160 $this->assertSame($content_list[1][
'type'], $content[1]->getType());
161 $this->assertSame($content_list[1][
'path'], $content[1]->getPath());
162 $this->assertTrue($content[1]->isDir());
163 $this->assertFalse($content[1]->isFile());
172 $path =
'/path/to/dir';
174 $this->filesystemMock
175 ->shouldReceive(
'directoryExists')
179 $this->expectException(DirectoryNotFoundException::class);
180 $this->expectExceptionMessage(
"Directory \"$path\" not found.");
182 $this->subject->listContents(
$path);
191 $path =
'/path/to/dir';
192 $file = [
'type' =>
'file',
'path' =>
$path];
193 $dir = [
'type' =>
'dir'];
201 $contentListContainer =
new DirectoryListing($contentList);
203 $this->filesystemMock
204 ->shouldReceive(
'directoryExists')
207 ->shouldReceive(
'listContents')
209 ->andReturn($contentListContainer)
211 ->shouldReceive(
'getMetadata')
215 $this->expectException(IOException::class);
216 $this->expectExceptionMessage(
"Directory \"$path\" not found.");
218 $this->subject->listContents(
$path);
227 $path =
'/path/to/dir';
230 $this->filesystemMock
231 ->shouldReceive(
'createDirectory')
233 ->withArgs([
$path, [
'visibility' => $access]])
236 $this->subject->createDir(
$path, $access);
245 $path =
'/path/to/dir';
248 $this->filesystemMock
249 ->shouldReceive(
'createDirectory')
251 ->withArgs([
$path, [
'visibility' => $access]])
252 ->andThrow(UnableToCreateDirectory::class);
254 $this->expectException(IOException::class);
255 $this->expectExceptionMessage(
"Could not create directory \"$path\"");
257 $this->subject->createDir(
$path, $access);
266 $path =
'/path/to/dir';
269 $this->expectException(\InvalidArgumentException::class);
270 $this->expectExceptionMessage(
"Invalid visibility expected public or private but got \"$access\".");
272 $this->subject->createDir(
$path, $access);
279 public function testCopyDirWhichShouldSucceed():
void 281 $srcPath =
'/source/path/to/dir';
282 $destPath =
'/dest/path/to/dir';
297 $fileDestinationList = [];
299 $subjectMock = Mockery::mock(
300 FlySystemDirectoryAccess::class .
'[listContents, hasDir]',
301 [$this->filesystemMock, $this->fileAccessMock]
304 ->shouldReceive(
'listContents')
305 ->withArgs([$srcPath,
true])
307 ->andReturn($fileSourceList)
309 ->shouldReceive(
'listContents')
310 ->withArgs([$destPath,
true])
312 ->andReturn($fileDestinationList);
315 ->shouldReceive(
'hasDir')
320 $this->fileAccessMock
321 ->shouldReceive(
'copy')
322 ->withArgs([$fileSourceList[0]->getPath(),
"$destPath/hello1"])
325 ->shouldReceive(
'copy')
326 ->withArgs([$fileSourceList[2]->getPath(),
"$destPath/hello2"])
329 ->shouldReceive(
'copy')
330 ->withArgs([$fileSourceList[3]->getPath(),
"$destPath/hello/subhello1"])
333 ->shouldReceive(
'copy')
334 ->withArgs([$fileSourceList[5]->getPath(),
"$destPath/hello3"])
337 ->shouldReceive(
'copy')
338 ->withArgs([$fileSourceList[6]->getPath(),
"$destPath/hello/subhello2"])
342 $subjectMock->copyDir($srcPath, $destPath);
349 public function testCopyDirWithDestinationListContentErrorWhichShouldSucceed():
void 351 $srcPath =
'/source/path/to/dir';
352 $destPath =
'/dest/path/to/dir';
367 $subjectMock = Mockery::mock(
368 FlySystemDirectoryAccess::class .
'[listContents, hasDir]',
369 [$this->filesystemMock, $this->fileAccessMock]
372 ->shouldReceive(
'listContents')
373 ->withArgs([$srcPath,
true])
375 ->andReturn($fileSourceList)
377 ->shouldReceive(
'listContents')
378 ->withArgs([$destPath,
true])
380 ->andThrow(UnableToRetrieveMetadata::class);
383 ->shouldReceive(
'hasDir')
388 $this->fileAccessMock
389 ->shouldReceive(
'copy')
390 ->withArgs([$fileSourceList[0]->getPath(),
"$destPath/hello1"])
393 ->shouldReceive(
'copy')
394 ->withArgs([$fileSourceList[2]->getPath(),
"$destPath/hello2"])
397 ->shouldReceive(
'copy')
398 ->withArgs([$fileSourceList[3]->getPath(),
"$destPath/hello/subhello1"])
401 ->shouldReceive(
'copy')
402 ->withArgs([$fileSourceList[5]->getPath(),
"$destPath/hello3"])
405 ->shouldReceive(
'copy')
406 ->withArgs([$fileSourceList[6]->getPath(),
"$destPath/hello/subhello2"])
410 $subjectMock->copyDir($srcPath, $destPath);
417 public function testCopyDirWithFullDestinationDirWhichShouldFail():
void 419 $srcPath =
'/source/path/to/dir';
420 $destPath =
'/dest/path/to/dir';
425 $fileDestinationList = [
435 $subjectMock = Mockery::mock(
436 FlySystemDirectoryAccess::class .
'[listContents, hasDir]',
437 [$this->filesystemMock, $this->fileAccessMock]
440 ->shouldReceive(
'listContents')
441 ->withArgs([$destPath,
true])
443 ->andReturn($fileDestinationList);
446 ->shouldReceive(
'hasDir')
451 $this->expectException(IOException::class);
452 $this->expectExceptionMessage(
"Destination \"$destPath\" is not empty can not copy files.");
454 $subjectMock->copyDir($srcPath, $destPath);
463 $srcPath =
'/source/path/to/dir';
464 $destPath =
'/dest/path/to/dir';
466 $subjectMock = Mockery::mock(
467 FlySystemDirectoryAccess::class .
'[hasDir]',
468 [$this->filesystemMock, $this->fileAccessMock]
471 ->shouldReceive(
'hasDir')
476 $this->expectException(DirectoryNotFoundException::class);
477 $this->expectExceptionMessage(
"Directory \"$srcPath\" not found");
479 $subjectMock->copyDir($srcPath, $destPath);
488 $path =
'/directory/which/should/be/removed';
490 $this->filesystemMock
491 ->shouldReceive(
'deleteDirectory')
495 ->shouldReceive(
'has')
500 $this->subject->deleteDir(
$path);
511 $this->filesystemMock
512 ->shouldReceive(
'deleteDirectory')
515 ->andThrow(\Exception::class);
517 $this->expectException(IOException::class);
518 $this->expectExceptionMessage(
'Could not delete directory "".');
520 $this->subject->deleteDir(
$path);
529 $path =
'/directory/which/should/be/removed';
531 $this->filesystemMock
532 ->shouldReceive(
'deleteDirectory')
535 ->andThrow(\Exception::class);
537 $this->expectException(IOException::class);
538 $this->expectExceptionMessage(
"Could not delete directory \"$path\".");
540 $this->subject->deleteDir(
$path);
Mockery LegacyMockInterface $filesystemMock
ILIAS Filesystem Provider FlySystem FlySystemDirectoryAccess Mockery MockInterface $subject
testListContentsWithInvalidMetadataWhichShouldFail()
testListContentsWithMissingRootDirectoryWhichShouldFail()
testHasDirWhichShouldSucceed()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testHasDirWithMissingDirWhichShouldSucceed()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Filesystem Provider FlySystem FlySystemFileAccess Mockery MockInterface $fileAccessMock
const PRIVATE_ACCESS
Private file visibility.
testCreateDirWithGeneralErrorWhichShouldFail()
testCreateDirWithInvalidVisibilityWhichShouldFail()
testCreateDirWhichShouldSucceed()
testDeleteDirWithRootViolationWhichShouldFail()
testDeleteDirWithGeneralErrorWhichShouldFail()
testCopyDirWithMissingSourceDirWhichShouldFail()
testHasDirWithFileTargetWhichShouldFail()
testDeleteDirWhichShouldSucceed()