19declare(strict_types=1);
23use PHPUnit\Framework\Attributes\DataProvider;
24use PHPUnit\Framework\TestCase;
39 protected function setUp(): void
42 $this->zip_file = tempnam(sys_get_temp_dir(),
'irss_zip_test_');
43 $this->zip =
new ZipArchive();
44 $this->zip->open($this->zip_file, ZipArchive::OVERWRITE);
50 if ($this->zip->filename !==
'') {
53 @unlink($this->zip_file);
56 #[DataProvider('filePathProvider')]
59 $method = new \ReflectionMethod(ResourceBuilder::class,
'ensurePathInZIP');
60 $builder = (new \ReflectionClass(ResourceBuilder::class))->newInstanceWithoutConstructor();
62 $result = $method->invoke($builder, $this->zip, $input,
true);
64 $this->assertSame($expected, $result);
65 $this->assertStringStartsNotWith(
'/', $result);
70 yield
'root file, no slash' => [
'index.html',
'index.html'];
71 yield
'root file, leading slash' => [
'/index.html',
'index.html'];
72 yield
'subdir file, no slash' => [
'assets/style.css',
'assets/style.css'];
73 yield
'subdir file, leading slash' => [
'/assets/style.css',
'assets/style.css'];
74 yield
'nested file, no slash' => [
'assets/css/osd.css',
'assets/css/osd.css'];
75 yield
'nested file, leading slash' => [
'/assets/css/osd.css',
'assets/css/osd.css'];
80 $method = new \ReflectionMethod(ResourceBuilder::class,
'ensurePathInZIP');
81 $builder = (new \ReflectionClass(ResourceBuilder::class))->newInstanceWithoutConstructor();
83 $result = $method->invoke($builder, $this->zip,
'/dir/sub',
false);
85 $this->assertStringStartsNotWith(
'/', $result);
86 $this->assertSame(
'dir/sub/', $result);
91 $method = new \ReflectionMethod(ResourceBuilder::class,
'ensurePathInZIP');
92 $builder = (new \ReflectionClass(ResourceBuilder::class))->newInstanceWithoutConstructor();
94 $entry = $method->invoke($builder, $this->zip,
'/index.html',
true);
95 $this->zip->addFromString($entry,
'<html></html>');
98 $verify =
new ZipArchive();
99 $verify->open($this->zip_file);
101 for ($i = 0; $i < $verify->numFiles; $i++) {
102 $names[] = $verify->getNameIndex($i);
106 foreach ($names as $name) {
107 $this->assertStringStartsNotWith(
'/', $name,
"ZIP entry must not start with '/': {$name}");
109 $this->assertContains(
'index.html', $names);
Regression tests for Mantis 0045580 / 0047237: entries written to a ZIP container must not start with...
static filePathProvider()
testDirectoryPathHasNoLeadingSlash()
testWritingRootFileProducesRelativeEntry()
testFilePathHasNoLeadingSlash(string $input, string $expected)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...