19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
40 protected function setUp(): void
43 $this->zip_file = tempnam(sys_get_temp_dir(),
'irss_dir_test_');
44 $this->zip =
new ZipArchive();
45 $this->zip->open($this->zip_file, ZipArchive::OVERWRITE);
47 $this->source_directory = $this->zip_file .
'_source';
48 mkdir($this->source_directory .
'/docs/nested', 0777,
true);
49 file_put_contents($this->source_directory .
'/root.txt',
'root');
50 file_put_contents($this->source_directory .
'/docs/one.txt',
'one');
51 file_put_contents($this->source_directory .
'/docs/nested/two.txt',
'two');
57 if ($this->zip->filename !==
'') {
60 @unlink($this->zip_file);
66 if (!is_dir($directory)) {
69 $iterator = new \RecursiveIteratorIterator(
70 new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS),
71 \RecursiveIteratorIterator::CHILD_FIRST
74 $file->isDir() ? @rmdir($file->getPathname()) : @unlink($file->getPathname());
81 $method = new \ReflectionMethod(ResourceBuilder::class,
'addDirectoryToZIP');
82 $builder = (new \ReflectionClass(ResourceBuilder::class))->newInstanceWithoutConstructor();
84 return $method->invoke($builder, $this->zip,
$source_directory, $path_inside_container);
92 $verify =
new ZipArchive();
93 $verify->open($this->zip_file);
95 for ($i = 0; $i < $verify->numFiles; $i++) {
96 $name = $verify->getNameIndex($i);
97 if (!str_ends_with($name,
'/')) {
109 $added = $this->
invoke($this->source_directory,
'');
112 $this->assertSame(3, $added);
114 [
'docs/nested/two.txt',
'docs/one.txt',
'root.txt'],
121 $added = $this->
invoke($this->source_directory,
'target');
124 $this->assertSame(3, $added);
126 [
'target/docs/nested/two.txt',
'target/docs/one.txt',
'target/root.txt'],
133 $this->
invoke($this->source_directory . DIRECTORY_SEPARATOR,
'');
137 [
'docs/nested/two.txt',
'docs/one.txt',
'root.txt'],
144 $this->
invoke($this->source_directory,
'/');
148 $this->assertNotEmpty($entries);
149 foreach ($entries as $entry) {
150 $this->assertStringStartsNotWith(
'/', $entry,
"ZIP entry must not start with '/': {$entry}");
156 $this->zip->addFromString(
'existing.txt',
'already in the container');
158 $this->
invoke($this->source_directory,
'');
161 $this->assertContains(
'existing.txt', $this->
fileEntries());
166 $empty_directory = $this->source_directory .
'/empty';
167 mkdir($empty_directory);
169 $this->assertSame(0, $this->
invoke($empty_directory,
''));
Mantis 48134: appending the contents of a ZIP to a container used to add one file per addStreamToCont...
testNoEntryStartsWithASlash()
testAnEmptyDirectoryAddsNothing()
testATrailingSeparatorOnTheSourceDirectoryDoesNotAffectTheEntries()
testEntriesArePrefixedWithTheCurrentLevel()
testExistingEntriesAreKept()
testAllFilesAreAddedKeepingTheDirectoryStructure()
invoke(string $source_directory, string $path_inside_container)
removeDirectory(string $directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...