ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\Filesystem\Util\ZipTest Class Reference
+ Inheritance diagram for ILIAS\Filesystem\Util\ZipTest:
+ Collaboration diagram for ILIAS\Filesystem\Util\ZipTest:

Public Member Functions

 testZip ()
 
 testZip2 ()
 
 testZip3 ()
 
 testLegacyZip ()
 
 LegacyZipWithTop ()
 
 testUnzip (string $zip, bool $has_multiple_root_entries, int $expected_amount_directories, array $expected_directories, int $expected_amount_files, array $expected_files)
 
 testWrongZip ()
 
 testLargeZIPs ()
 
 testLegacyUnzip (string $zip, bool $has_multiple_root_entries, int $expected_amount_directories, array $expected_directories, int $expected_amount_files, array $expected_files)
 

Static Public Member Functions

static getZips ()
 

Data Fields

const ZIPPED_ZIP = 'zipped.zip'
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Protected Attributes

string $zips_dir = __DIR__ . '/zips/'
 
string $unzips_dir = __DIR__ . '/unzips/'
 

Static Protected Attributes

static array $files_mixed
 
static array $directories_mixed
 
static array $files_three
 

Private Member Functions

 recurseRmdir (string $path_to_directory)
 
 directoryToArray (string $path_to_directory)
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 41 of file ZipTest.php.

Member Function Documentation

◆ directoryToArray()

ILIAS\Filesystem\Util\ZipTest::directoryToArray ( string  $path_to_directory)
private
Returns
string[]|string[][]

Definition at line 302 of file ZipTest.php.

302 : array
303 {
304 $iterator = new \RecursiveIteratorIterator(
305 new \RecursiveDirectoryIterator($path_to_directory, \RecursiveDirectoryIterator::SKIP_DOTS),
306 \RecursiveIteratorIterator::SELF_FIRST,
307 \RecursiveIteratorIterator::CATCH_GET_CHILD
308 );
309 $paths = [];
310 foreach ($iterator as $item) {
311 $relative_path = str_replace($path_to_directory . '/', '', $item->getPathname());
312 $paths[] = $item->isDir() ? $relative_path . '/' : $relative_path;
313 }
314
315 sort($paths);
316
317 return $paths;
318 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ getZips()

static ILIAS\Filesystem\Util\ZipTest::getZips ( )
static

Definition at line 322 of file ZipTest.php.

322 : \Iterator
323 {
324 yield ['1_folder_mac.zip', false, 10, self::$directories_one, 15, self::$files_one];
325 yield ['1_folder_win.zip', false, 10, self::$directories_one, 15, self::$files_one];
326 yield ['3_folders_mac.zip', true, 9, self::$directories_three, 12, self::$files_three];
327 yield ['3_folders_win.zip', true, 9, self::$directories_three, 12, self::$files_three];
328 yield ['1_folder_1_file_mac.zip', true, 3, self::$directories_mixed, 5, self::$files_mixed];
329 }
static array $directories_mixed
Definition: ZipTest.php:339

◆ LegacyZipWithTop()

ILIAS\Filesystem\Util\ZipTest::LegacyZipWithTop ( )

Definition at line 153 of file ZipTest.php.

153 : void
154 {
155 $legacy = new LegacyArchives();
156
157 define('CLIENT_WEB_DIR', __DIR__);
158 define('ILIAS_WEB_DIR', 'public/data');
159 define('CLIENT_ID', 'test');
160 define('CLIENT_DATA_DIR', __DIR__);
161 define('ILIAS_ABSOLUTE_PATH', __DIR__);
162
163 mkdir($this->unzips_dir);
164 $legacy->zip($this->zips_dir, $this->unzips_dir . self::ZIPPED_ZIP, true);
165 $this->assertFileExists($this->unzips_dir . self::ZIPPED_ZIP);
166
167 $unzip_again = new Unzip(
168 new UnzipOptions(),
169 Streams::ofResource(fopen($this->unzips_dir . self::ZIPPED_ZIP, 'r'))
170 );
171 $this->assertSame(5, $unzip_again->getAmountOfFiles());
172
173 $depth = 0;
174 foreach ($unzip_again->getPaths() as $path) {
175 $parts = explode('/', $path);
176 $depth = max($depth, count($parts));
177 }
178 $this->assertEquals(2, $depth);
179 $this->recurseRmdir($this->unzips_dir);
180 }
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64
recurseRmdir(string $path_to_directory)
Definition: ZipTest.php:288
$path
Definition: ltiservices.php:30
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61

References $parts, $path, ILIAS\Filesystem\Stream\Streams\ofResource(), and ILIAS\Filesystem\Util\ZipTest\recurseRmdir().

+ Here is the call graph for this function:

◆ recurseRmdir()

ILIAS\Filesystem\Util\ZipTest::recurseRmdir ( string  $path_to_directory)
private

Definition at line 288 of file ZipTest.php.

288 : bool
289 {
290 $files = array_diff(scandir($path_to_directory), ['.', '..']);
291 foreach ($files as $file) {
292 (is_dir("$path_to_directory/$file") && !is_link("$path_to_directory/$file")) ? $this->recurseRmdir(
293 "$path_to_directory/$file"
294 ) : unlink("$path_to_directory/$file");
295 }
296 return rmdir($path_to_directory);
297 }

Referenced by ILIAS\Filesystem\Util\ZipTest\LegacyZipWithTop(), ILIAS\Filesystem\Util\ZipTest\tearDown(), and ILIAS\Filesystem\Util\ZipTest\testLegacyZip().

+ Here is the caller graph for this function:

◆ setUp()

ILIAS\Filesystem\Util\ZipTest::setUp ( )
protected

Definition at line 47 of file ZipTest.php.

47 : void
48 {
49 if (file_exists($this->unzips_dir . self::ZIPPED_ZIP)) {
50 unlink($this->unzips_dir . self::ZIPPED_ZIP);
51 }
52 if (!file_exists($this->unzips_dir)) {
53 mkdir($this->unzips_dir);
54 }
55 }

◆ tearDown()

ILIAS\Filesystem\Util\ZipTest::tearDown ( )
protected

Definition at line 57 of file ZipTest.php.

57 : void
58 {
59 if (file_exists($this->unzips_dir)) {
60 $this->recurseRmdir($this->unzips_dir);
61 }
62 }

References ILIAS\Filesystem\Util\ZipTest\recurseRmdir().

+ Here is the call graph for this function:

◆ testLargeZIPs()

ILIAS\Filesystem\Util\ZipTest::testLargeZIPs ( )

Definition at line 225 of file ZipTest.php.

225 : void
226 {
227 // get ulimit
228 $ulimit = (int) shell_exec('ulimit -n');
229 $limit = 2500;
230 if ($ulimit >= $limit) {
231 $this->markTestSkipped('ulimit is too high and would take too much resources');
232 }
233 $this->assertLessThan($limit, $ulimit);
234
235 $zip = new Zip(new ZipOptions());
236
237 $file_names = [];
238
239 for ($i = 0; $i < $ulimit * 2; $i++) {
240 $path_inside_zip = $file_names[] = 'test' . $i;
241 $zip->addStream(Streams::ofString('-'), $path_inside_zip);
242 }
243 $this->assertTrue(true); // no warning or error
244
245 // check if the zip now contains all files
246 $unzip = new Unzip(new UnzipOptions(), $zip->get());
247 $file_names_in_zip = iterator_to_array($unzip->getFiles());
248 sort($file_names);
249 sort($file_names_in_zip);
250 $this->assertEquals($file_names, $file_names_in_zip);
251 }
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41

References ILIAS\Repository\int(), ILIAS\Filesystem\Stream\Streams\ofString(), and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ testLegacyUnzip()

ILIAS\Filesystem\Util\ZipTest::testLegacyUnzip ( string  $zip,
bool  $has_multiple_root_entries,
int  $expected_amount_directories,
array  $expected_directories,
int  $expected_amount_files,
array  $expected_files 
)
Parameters
mixed[]$expected_directories
mixed[]$expected_files

Definition at line 258 of file ZipTest.php.

265 : void {
266 $legacy = new LegacyArchives();
267
268 $this->assertStringContainsString('.zip', $zip);
269 $zip_path = $this->zips_dir . $zip;
270 $this->assertFileExists($zip_path);
271
272 $temp_unzip_path = $this->unzips_dir . uniqid('unzip', true);
273
274 $return = $legacy->unzip(
275 $zip_path,
276 $temp_unzip_path
277 );
278
279 $this->assertTrue($return);
280
281 $unzipped_files = $this->directoryToArray($temp_unzip_path);
282 $expected_paths = array_merge($expected_directories, $expected_files);
283 sort($expected_paths);
284 $this->assertEquals($expected_paths, $unzipped_files);
285 $this->assertTrue($this->recurseRmdir($temp_unzip_path));
286 }
directoryToArray(string $path_to_directory)
Definition: ZipTest.php:302

◆ testLegacyZip()

ILIAS\Filesystem\Util\ZipTest::testLegacyZip ( )

Definition at line 111 of file ZipTest.php.

111 : void
112 {
113 $legacy = new LegacyArchives();
114
115 define('CLIENT_WEB_DIR', __DIR__);
116 define('ILIAS_WEB_DIR', 'public/data');
117 define('CLIENT_ID', 'test');
118 define('CLIENT_DATA_DIR', __DIR__);
119 define('ILIAS_ABSOLUTE_PATH', __DIR__);
120
121 $legacy->zip($this->zips_dir, $this->unzips_dir . self::ZIPPED_ZIP, false);
122 $this->assertFileExists($this->unzips_dir . self::ZIPPED_ZIP);
123
124 $unzip_again = new Unzip(
125 new UnzipOptions(),
126 Streams::ofResource(fopen($this->unzips_dir . self::ZIPPED_ZIP, 'r'))
127 );
128 $expected = [
129 0 => './',
130 1 => '3_folders_win.zip',
131 2 => '1_folder_mac.zip',
132 3 => '3_folders_mac.zip',
133 4 => '1_folder_win.zip',
134 5 => '1_folder_1_file_mac.zip'
135 ];
136 sort($expected);
137
138 $actual = iterator_to_array($unzip_again->getPaths());
139 sort($actual);
140
141 $this->assertSame($expected, $actual);
142 $this->assertSame(5, $unzip_again->getAmountOfFiles());
143
144 $depth = 0;
145 foreach ($unzip_again->getPaths() as $path) {
146 $parts = explode('/', $path);
147 $depth = max($depth, count($parts));
148 }
149 $this->assertEquals(2, $depth);
150 $this->recurseRmdir($this->unzips_dir);
151 }

References $parts, $path, ILIAS\Filesystem\Stream\Streams\ofResource(), ILIAS\Filesystem\Util\ZipTest\recurseRmdir(), and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ testUnzip()

ILIAS\Filesystem\Util\ZipTest::testUnzip ( string  $zip,
bool  $has_multiple_root_entries,
int  $expected_amount_directories,
array  $expected_directories,
int  $expected_amount_files,
array  $expected_files 
)
Parameters
mixed[]$expected_directories
mixed[]$expected_files

Definition at line 187 of file ZipTest.php.

194 : void {
195 $this->assertStringContainsString('.zip', $zip);
196 $zip_path = $this->zips_dir . $zip;
197 $this->assertFileExists($zip_path);
198
199 $stream = Streams::ofResource(fopen($zip_path, 'rb'));
200 $options = new UnzipOptions();
201 $unzip = new Unzip($options, $stream);
202
203 $this->assertFalse($unzip->hasZipReadingError());
204 $this->assertSame($has_multiple_root_entries, $unzip->hasMultipleRootEntriesInZip());
205 $this->assertSame($expected_amount_directories, $unzip->getAmountOfDirectories());
206 $this->assertEquals($expected_directories, iterator_to_array($unzip->getDirectories()));
207 $this->assertSame($expected_amount_files, $unzip->getAmountOfFiles());
208 $this->assertEquals($expected_files, iterator_to_array($unzip->getFiles()));
209 }

◆ testWrongZip()

ILIAS\Filesystem\Util\ZipTest::testWrongZip ( )

Definition at line 211 of file ZipTest.php.

211 : void
212 {
213 $stream = Streams::ofResource(fopen(__FILE__, 'rb'));
214 $options = new UnzipOptions();
215 $unzip = new Unzip($options, $stream);
216 $this->assertTrue($unzip->hasZipReadingError());
217 $this->assertFalse($unzip->hasMultipleRootEntriesInZip());
218 $this->assertCount(0, iterator_to_array($unzip->getFiles()));
219 $this->assertCount(0, iterator_to_array($unzip->getDirectories()));
220 $this->assertCount(0, iterator_to_array($unzip->getPaths()));
221 $this->assertSame([], iterator_to_array($unzip->getDirectories()));
222 $this->assertSame([], iterator_to_array($unzip->getFiles()));
223 }

References ILIAS\UI\Implementation\Component\Input\Field\$options, and ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

◆ testZip()

ILIAS\Filesystem\Util\ZipTest::testZip ( )

Definition at line 64 of file ZipTest.php.

64 : void
65 {
66 $zip_options = new ZipOptions();
67 $streams = [
68 Streams::ofResource(fopen($this->zips_dir . '1_folder_1_file_mac.zip', 'r')),
69 Streams::ofResource(fopen($this->zips_dir . '1_folder_win.zip', 'r')),
70 ];
71 $zip = new Zip($zip_options, ...$streams);
72 $zip_stream = $zip->get();
73 $this->assertGreaterThan(0, $zip_stream->getSize());
74
75 $unzip_again = new Unzip(new UnzipOptions(), $zip_stream);
76 $this->assertSame(2, $unzip_again->getAmountOfFiles());
77 }

References ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

◆ testZip2()

ILIAS\Filesystem\Util\ZipTest::testZip2 ( )

Definition at line 79 of file ZipTest.php.

79 : void
80 {
81 $zip_options = new ZipOptions();
82 $streams = [
83 Streams::ofResource(fopen($this->zips_dir . '1_folder_1_file_mac.zip', 'r')),
84 ];
85 $zip = new Zip($zip_options, ...$streams);
86 $zip_stream = $zip->get();
87 $this->assertGreaterThan(0, $zip_stream->getSize());
88
89 $unzip_again = new Unzip(new UnzipOptions(), $zip_stream);
90 $this->assertSame(1, $unzip_again->getAmountOfFiles());
91 }

References ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

◆ testZip3()

ILIAS\Filesystem\Util\ZipTest::testZip3 ( )

Definition at line 93 of file ZipTest.php.

93 : void
94 {
95 $zip_options = new ZipOptions();
96 $streams = [
97 Streams::ofResource(fopen($this->zips_dir . '1_folder_1_file_mac.zip', 'r')),
98 Streams::ofResource(fopen($this->zips_dir . '1_folder_mac.zip', 'r')),
99 Streams::ofResource(fopen($this->zips_dir . '1_folder_win.zip', 'r')),
100 Streams::ofResource(fopen($this->zips_dir . '3_folders_mac.zip', 'r')),
101 Streams::ofResource(fopen($this->zips_dir . '3_folders_win.zip', 'r')),
102 ];
103 $zip = new Zip($zip_options, ...$streams);
104 $zip_stream = $zip->get();
105 $this->assertGreaterThan(0, $zip_stream->getSize());
106
107 $unzip_again = new Unzip(new UnzipOptions(), $zip_stream);
108 $this->assertSame(5, $unzip_again->getAmountOfFiles());
109 }

References ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

Field Documentation

◆ $directories_mixed

array ILIAS\Filesystem\Util\ZipTest::$directories_mixed
staticprotected

Definition at line 339 of file ZipTest.php.

◆ $files_mixed

array ILIAS\Filesystem\Util\ZipTest::$files_mixed
staticprotected
Initial value:
= [
0 => '03_Test.pdf',
1 => 'Ordner A/01_Test.pdf',
2 => 'Ordner A/02_Test.pdf',
3 => 'Ordner A/Ordner A_2/07_Test.pdf',
4 => 'Ordner A/Ordner A_2/08_Test.pdf'
]

Definition at line 331 of file ZipTest.php.

◆ $files_three

array ILIAS\Filesystem\Util\ZipTest::$files_three
staticprotected
Initial value:
= [
0 => 'Ordner A/01_Test.pdf',
1 => 'Ordner A/02_Test.pdf',
2 => 'Ordner A/Ordner A_2/07_Test.pdf',
3 => 'Ordner A/Ordner A_2/08_Test.pdf',
4 => 'Ordner B/03_Test.pdf',
5 => 'Ordner B/04_Test.pdf',
6 => 'Ordner B/Ordner B_2/09_Test.pdf',
7 => 'Ordner B/Ordner B_2/10_Test.pdf',
8 => 'Ordner C/05_Test.pdf',
9 => 'Ordner C/06_Test.pdf',
10 => 'Ordner C/Ordner C_2/11_Test.pdf',
11 => 'Ordner C/Ordner C_2/12_Test.pdf',
]

Definition at line 387 of file ZipTest.php.

◆ $unzips_dir

string ILIAS\Filesystem\Util\ZipTest::$unzips_dir = __DIR__ . '/unzips/'
protected

Definition at line 45 of file ZipTest.php.

◆ $zips_dir

string ILIAS\Filesystem\Util\ZipTest::$zips_dir = __DIR__ . '/zips/'
protected

Definition at line 44 of file ZipTest.php.

◆ ZIPPED_ZIP

const ILIAS\Filesystem\Util\ZipTest::ZIPPED_ZIP = 'zipped.zip'

Definition at line 43 of file ZipTest.php.


The documentation for this class was generated from the following file: