ILIAS  release_8 Revision v8.24
LegacyPathHelperTest.php
Go to the documentation of this file.
1<?php
2
4
8use Mockery;
9use Mockery\MockInterface;
10use PHPUnit\Framework\TestCase;
11
12/******************************************************************************
13 *
14 * This file is part of ILIAS, a powerful learning management system.
15 *
16 * ILIAS is licensed with the GPL-3.0, you should have received a copy
17 * of said license along with the source code.
18 *
19 * If this is not the case or you just want to try ILIAS, you'll find
20 * us at:
21 * https://www.ilias.de
22 * https://github.com/ILIAS-eLearning
23 *
24 *****************************************************************************/
35class LegacyPathHelperTest extends TestCase
36{
37 private $libsPath;
39 private $tempPath;
40 private $storagePath;
41 private $webPath;
46
47
51 protected function setUp(): void
52 {
53 parent::setUp();
54
55 $iliasAbsolutePath = '/dummy/var/www/html/ilias';
56 $dataDir = '/dummy/var/www/ildata';
57 $webDir = 'data';
58 $clientId = 'default';
59
60 //constants needed for test subject
61 define("CLIENT_DATA_DIR", $dataDir . '/' . $clientId);
62 define("CLIENT_WEB_DIR", $iliasAbsolutePath . '/' . $webDir . '/' . $clientId);
63 define("ILIAS_ABSOLUTE_PATH", $iliasAbsolutePath);
64 define("ILIAS_WEB_DIR", $webDir);
65 define("CLIENT_ID", 'default');
66
67 $this->customizingPath = $iliasAbsolutePath . '/' . 'Customizing';
68 $this->libsPath = $iliasAbsolutePath . '/' . 'libs';
69 $this->webPath = CLIENT_WEB_DIR;
70 $this->storagePath = CLIENT_DATA_DIR;
71 $this->tempPath = sys_get_temp_dir();
72
73 //create mock DI container
74 $this->filesystemsMock = \Mockery::mock(Filesystems::class);
75
76 $containerMock = Mockery::mock(Container::class);
77 $containerMock->shouldReceive('filesystem')
78 ->withNoArgs()
79 ->zeroOrMoreTimes()
80 ->andReturn($this->filesystemsMock);
81
82 $GLOBALS['DIC'] = $containerMock;
83 }
84
85
91 {
92 $target = $this->webPath . '/testtarget';
93
94 $this->filesystemsMock
95 ->shouldReceive('web')
96 ->once()
97 ->andReturn(Mockery::mock(Filesystem::class));
98
99 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
100 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
101 }
102
103
109 {
110 $target = $this->storagePath . '/testtarget';
111
112 $this->filesystemsMock
113 ->shouldReceive('storage')
114 ->once()
115 ->andReturn(Mockery::mock(Filesystem::class));
116
117 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
118 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
119 }
120
121
127 {
128 $target = './libs/bower/bower_components/mediaelement/build';
129
130 $this->filesystemsMock
131 ->shouldReceive('libs')
132 ->once()
133 ->andReturn(Mockery::mock(Filesystem::class));
134
135 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
136 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
137 }
138
144 {
145 $target = $this->libsPath . 'libs/bower/bower_components/mediaelement/build';
146
147 $this->filesystemsMock
148 ->shouldReceive('libs')
149 ->once()
150 ->andReturn(Mockery::mock(Filesystem::class));
151
152 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
153 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
154 }
155
156
162 {
163 $target = '/invalid/path/to/testtarget';
164
165 $this->expectException(\InvalidArgumentException::class);
166 $this->expectExceptionMessage("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$target}'");
167
169 }
170
171
177 {
178 $expectedPath = 'testtarget/subdir';
179 $target = $this->webPath . '/' . $expectedPath;
180
181 $result = LegacyPathHelper::createRelativePath($target);
182 $this->assertEquals($expectedPath, $result);
183 }
184
185
191 {
192 $expectedPath = 'testtarget/subdir';
193 $target = $this->storagePath . '/' . $expectedPath;
194
195 $result = LegacyPathHelper::createRelativePath($target);
196 $this->assertEquals($expectedPath, $result);
197 }
198
199
205 {
206 $target = '/invalid/path/to/target';
207
208 $this->expectException(\InvalidArgumentException::class);
209 $this->expectExceptionMessage("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$target}'");
210
212 }
213}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
testDeriveFilesystemFromWithRelativeLibsTargetWhichShouldSucceed()
@Test @small
testDeriveFilesystemFromWithAbsoluteLibsTargetWhichShouldSucceed()
@Test @small
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.
static deriveFilesystemFrom(string $absolute_path)
Tries to fetch the filesystem responsible for the absolute path.
const CLIENT_WEB_DIR
Definition: constants.php:47
const CLIENT_DATA_DIR
Definition: constants.php:46
$iliasAbsolutePath
Definition: imgupload.php:49
Interface Filesystem.
Definition: Filesystem.php:40
$clientId
Definition: ltiregend.php:27
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...