ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LegacyPathHelperTestTBD.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\Filesystem\Util;
20
21use PHPUnit\Framework\Attributes\BackupGlobals;
22use PHPUnit\Framework\Attributes\BackupStaticProperties;
23use PHPUnit\Framework\Attributes\PreserveGlobalState;
24use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
25use PHPUnit\Framework\Attributes\Test;
26use PHPUnit\Framework\Attributes\Small;
30use Mockery;
31use Mockery\MockInterface;
32use PHPUnit\Framework\TestCase;
33
38#[BackupGlobals(false)]
39#[BackupStaticProperties(false)]
40#[PreserveGlobalState(false)]
41#[RunTestsInSeparateProcesses]
42class LegacyPathHelperTest extends TestCase
43{
44 public $libsPath;
45 private string $storagePath;
46 private string $webPath;
47 private MockInterface|Filesystems $filesystemsMock;
48
49
53 protected function setUp(): void
54 {
55 parent::setUp();
56
57 $iliasAbsolutePath = '/dummy/var/www/html/ilias';
58 $dataDir = '/dummy/var/www/ildata';
59 $webDir = 'public/data';
60 $clientId = 'default';
61
62 //constants needed for test subject
63 define("CLIENT_DATA_DIR", $dataDir . '/' . $clientId);
64 define("CLIENT_WEB_DIR", $iliasAbsolutePath . '/' . $webDir . '/' . $clientId);
65 define("ILIAS_ABSOLUTE_PATH", $iliasAbsolutePath);
66 define("ILIAS_WEB_DIR", $webDir);
67 define("CLIENT_ID", 'default');
68 $this->libsPath = $iliasAbsolutePath . '/' . 'vendor';
69 $this->webPath = CLIENT_WEB_DIR;
70 $this->storagePath = CLIENT_DATA_DIR;
71
72 //create mock DI container
73 $this->filesystemsMock = \Mockery::mock(Filesystems::class);
74
75 $containerMock = Mockery::mock(Container::class);
76 $containerMock->shouldReceive('filesystem')
77 ->withNoArgs()
78 ->zeroOrMoreTimes()
79 ->andReturn($this->filesystemsMock);
80
81 $GLOBALS['DIC'] = $containerMock;
82 }
83
84
85 #[Test]
86
88 {
89 $target = $this->webPath . '/testtarget';
90
91 $this->filesystemsMock
92 ->shouldReceive('web')
93 ->once()
94 ->andReturn(Mockery::mock(Filesystem::class));
95
96 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
97 $this->assertInstanceOf(\ILIAS\Filesystem\Filesystem::class, $filesystem, 'Expecting filesystem instance.');
98 }
99
100
101 #[Test]
102
104 {
105 $target = $this->storagePath . '/testtarget';
106
107 $this->filesystemsMock
108 ->shouldReceive('storage')
109 ->once()
110 ->andReturn(Mockery::mock(Filesystem::class));
111
112 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
113 $this->assertInstanceOf(\ILIAS\Filesystem\Filesystem::class, $filesystem, 'Expecting filesystem instance.');
114 }
115
116
117 #[Test]
118
120 {
121 $target = './vendor/bower/bower_components/mediaelement/build';
122
123 $this->filesystemsMock
124 ->shouldReceive('libs')
125 ->once()
126 ->andReturn(Mockery::mock(Filesystem::class));
127
128 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
129 $this->assertInstanceOf(\ILIAS\Filesystem\Filesystem::class, $filesystem, 'Expecting filesystem instance.');
130 }
131
132 #[Test]
133
135 {
136 $target = $this->libsPath . 'vendor/bower/bower_components/mediaelement/build';
137
138 $this->filesystemsMock
139 ->shouldReceive('libs')
140 ->once()
141 ->andReturn(Mockery::mock(Filesystem::class));
142
143 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target);
144 $this->assertInstanceOf(\ILIAS\Filesystem\Filesystem::class, $filesystem, 'Expecting filesystem instance.');
145 }
146
147
148 #[Test]
149
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
161 #[Test]
162
164 {
165 $expectedPath = 'testtarget/subdir';
166 $target = $this->webPath . '/' . $expectedPath;
167
168 $result = LegacyPathHelper::createRelativePath($target);
169 $this->assertSame($expectedPath, $result);
170 }
171
172
173 #[Test]
174
176 {
177 $expectedPath = 'testtarget/subdir';
178 $target = $this->storagePath . '/' . $expectedPath;
179
180 $result = LegacyPathHelper::createRelativePath($target);
181 $this->assertSame($expectedPath, $result);
182 }
183
184
185 #[Test]
186
188 {
189 $target = '/invalid/path/to/target';
190
191 $this->expectException(\InvalidArgumentException::class);
192 $this->expectExceptionMessage("Invalid path supplied. Path must start with the web, storage, temp, customizing or libs storage location. Path given: '{$target}'");
193
195 }
196}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
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
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
Definition: Filesystems.php:30
$clientId
Definition: ltiregend.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$GLOBALS["DIC"]
Definition: wac.php:54