ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
LegacyPathHelperTest.php
Go to the documentation of this file.
1<?php
2
4
5require_once('./libs/composer/vendor/autoload.php');
6
10use Mockery;
11use Mockery\MockInterface;
12use PHPUnit\Framework\TestCase;
13
24class LegacyPathHelperTest extends TestCase
25{
26 private $libsPath;
28 private $tempPath;
29 private $storagePath;
30 private $webPath;
35
36
40 protected function setUp()
41 {
42 parent::setUp();
43
44 $iliasAbsolutePath = '/dummy/var/www/html/ilias';
45 $dataDir = '/dummy/var/www/ildata';
46 $webDir = 'data';
47 $clientId = 'default';
48
49 //constants needed for test subject
50 define("CLIENT_DATA_DIR", $dataDir . '/' . $clientId);
51 define("CLIENT_WEB_DIR", $iliasAbsolutePath . '/' . $webDir . '/' . $clientId);
52 define("ILIAS_ABSOLUTE_PATH", $iliasAbsolutePath);
53 define("ILIAS_WEB_DIR", $webDir);
54 define("CLIENT_ID", 'default');
55
56 $this->customizingPath = $iliasAbsolutePath . '/' . 'Customizing';
57 $this->libsPath = $iliasAbsolutePath . '/' . 'libs';
58 $this->webPath = CLIENT_WEB_DIR;
59 $this->storagePath = CLIENT_DATA_DIR;
60 $this->tempPath = sys_get_temp_dir();
61
62 //create mock DI container
63 $this->filesystemsMock = \Mockery::mock(Filesystems::class);
64
65 $containerMock = Mockery::mock(Container::class);
66 $containerMock->shouldReceive('filesystem')
67 ->withNoArgs()
68 ->zeroOrMoreTimes()
69 ->andReturn($this->filesystemsMock);
70
71 $GLOBALS['DIC'] = $containerMock;
72 }
73
74
80 {
81 $target = $this->webPath . '/testtarget';
82
83 $this->filesystemsMock
84 ->shouldReceive('web')
85 ->once()
86 ->andReturn(Mockery::mock(Filesystem::class));
87
89 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
90 }
91
92
98 {
99 $target = $this->storagePath . '/testtarget';
100
101 $this->filesystemsMock
102 ->shouldReceive('storage')
103 ->once()
104 ->andReturn(Mockery::mock(Filesystem::class));
105
107 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
108 }
109
110
116 {
117 $target = './libs/bower/bower_components/mediaelement/build';
118
119 $this->filesystemsMock
120 ->shouldReceive('libs')
121 ->once()
122 ->andReturn(Mockery::mock(Filesystem::class));
123
125 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
126 }
127
133 {
134 $target = $this->libsPath . 'libs/bower/bower_components/mediaelement/build';
135
136 $this->filesystemsMock
137 ->shouldReceive('libs')
138 ->once()
139 ->andReturn(Mockery::mock(Filesystem::class));
140
142 $this->assertTrue($filesystem instanceof Filesystem, 'Expecting filesystem instance.');
143 }
144
145
151 {
152 $target = '/invalid/path/to/testtarget';
153
154 $this->expectException(\InvalidArgumentException::class);
155 $this->expectExceptionMessage("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$target}'");
156
158 }
159
160
166 {
167 $expectedPath = 'testtarget/subdir';
168 $target = $this->webPath . '/' . $expectedPath;
169
171 $this->assertEquals($expectedPath, $result);
172 }
173
174
180 {
181 $expectedPath = 'testtarget/subdir';
182 $target = $this->storagePath . '/' . $expectedPath;
183
185 $this->assertEquals($expectedPath, $result);
186 }
187
188
194 {
195 $target = '/invalid/path/to/target';
196
197 $this->expectException(\InvalidArgumentException::class);
198 $this->expectExceptionMessage("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$target}'");
199
201 }
202}
$result
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:16
testDeriveFilesystemFromWithRelativeLibsTargetWhichShouldSucceed()
@Test @small
testDeriveFilesystemFromWithAbsoluteLibsTargetWhichShouldSucceed()
@Test @small
static deriveFilesystemFrom($absolute_path)
Tries to fetch the filesystem responsible for the absolute path.
static createRelativePath($absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Interface Filesystem.
Definition: Filesystem.php:26
Class FlySystemFileAccessTest.
$iliasAbsolutePath