19declare(strict_types=1);
21use PHPUnit\Framework\Attributes\DataProvider;
22use PHPUnit\Framework\TestCase;
28 protected function setUp(): void
30 $this->dir = sys_get_temp_dir() .
'/htlm_start_file_' . bin2hex(random_bytes(4));
36 $it =
new RecursiveIteratorIterator(
37 new RecursiveDirectoryIterator($this->dir, FilesystemIterator::SKIP_DOTS),
38 RecursiveIteratorIterator::CHILD_FIRST
40 foreach ($it as $file) {
41 $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname());
51 $path = $this->dir .
'/lm.zip';
52 $zip =
new ZipArchive();
54 foreach (
$files as $file) {
55 $zip->addFromString($file,
'content');
59 $zip =
new ZipArchive();
60 $zip->open($path, ZipArchive::RDONLY);
67 'stored start file wins' => [[
'index.html',
'sub/start.html'],
'sub/start.html',
'sub/start.html'],
68 'empty start file falls back to index.html' => [[
'index.html',
'page.html'],
'',
'index.html'],
69 'empty start file falls back to index.htm' => [[
'index.htm',
'page.html'],
'',
'index.htm'],
70 'index.html is preferred over index.htm' => [[
'index.htm',
'index.html'],
'',
'index.html'],
71 'stored start file missing falls back' => [[
'index.html'],
'gone.html',
'index.html'],
72 'nested index is not used' => [[
'sub/index.html'],
'',
''],
73 'nothing found' => [[
'page.html'],
'',
''],
80 #[DataProvider('archiveProvider')]
91 'stored start file is kept' => [[
'index.html'],
'start.html',
'start.html'],
92 'index.html' => [[
'index.html',
'index.htm'],
'',
'index.html'],
93 'index.htm' => [[
'index.htm'],
'',
'index.htm'],
94 'nothing found' => [[
'page.html'],
'',
''],
101 #[DataProvider('directoryProvider')]
104 foreach (
$files as $file) {
105 touch($this->dir .
'/' . $file);
108 public function determine(
string $lm_path,
string $start_file):
string
110 return $this->determineStartFile($lm_path, $start_file);
113 $this->assertSame($expected, $migration->determine($this->dir, $stored));
testMigrationDeterminesStartFile(array $files, string $stored, string $expected)
static directoryProvider()
testLocateStartFileInArchive(array $files, string $stored, string $expected)
static locateStartFileInArchive(\ZipArchive $archive, string $start_file)
Returns the stored start file if the archive contains it, otherwise falls back to index....