ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
HandlerTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Export\ImportHandler\File\Handler as ilFileHandler;
24 use ILIAS\Export\ImportHandler\File\Namespace\Collection as ilFileNamespaceCollection;
25 use ILIAS\Export\ImportHandler\File\Namespace\Factory as ilFileNamespaceFactory;
27 use SplFileInfo;
28 
29 class HandlerTest extends TestCase
30 {
31  public function testFileHandler(): void
32  {
33  $file_name = 'TestFile.test';
34  $file_dir = 'A' . DIRECTORY_SEPARATOR
35  . 'B' . DIRECTORY_SEPARATOR
36  . 'C';
37  $file_path = $file_dir . DIRECTORY_SEPARATOR . $file_name;
38  $namespaces = $this->createMock(ilFileNamespaceCollection::class);
39 
40  $namespace = $this->createMock(ilFileNamespaceFactory::class);
41  $namespace->expects($this->any())->method('collection')->willReturn($namespaces);
42 
43  $file_info = $this->createMock(SplFileInfo::class);
44  $file_info->expects($this->any())->method('getFilename')->willReturn($file_name);
45  $file_info->expects($this->any())->method('getRealPath')->willReturn(false);
46  $file_info->expects($this->any())->method('getPath')->willReturn($file_dir);
47 
48  $file_handler = new ilFileHandler($namespace);
49  $file_handler = $file_handler->withFileInfo($file_info);
50 
51  $this->assertEquals($file_path, $file_handler->getFilePath());
52  $this->assertFalse($file_handler->fileExists());
53  $this->assertEquals($file_name, $file_handler->getFileName());
54  $this->assertEquals($namespaces, $file_handler->getNamespaces());
55  $this->assertTrue($file_handler->pathContainsFolderName('A'));
56  $this->assertTrue($file_handler->pathContainsFolderName('B'));
57  $this->assertTrue($file_handler->pathContainsFolderName('C'));
58  $this->assertFalse($file_handler->pathContainsFolderName('D'));
59  $this->assertFalse($file_handler->pathContainsFolderName('E'));
60  $this->assertEquals('B/C/TestFile.test', $file_handler->getSubPathToDirBeginningAtPathEnd('B')->getFilePath());
61  $this->assertEquals('A/B', $file_handler->getSubPathToDirBeginningAtPathStart('B')->getFilePath());
62  $this->assertEquals($file_dir, $file_handler->getPathToFileLocation());
63  $this->assertEquals('C', $file_handler->getPathPart("/C/"));
64  }
65 }
if($err=$client->getError()) $namespace