3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\FileListing
;
9 use PHPUnit\Framework\Attributes\CoversClass
;
10 use PHPUnit\Framework\Attributes\RequiresPhpExtension
;
12 use function array_values
;
13 use function extension_loaded
;
16 #[CoversClass(FileListing::class)]
17 class FileListingTest
extends AbstractTestCase
19 private FileListing
$fileListing;
21 protected function setUp(): void
25 $this->fileListing
= new FileListing();
28 public function testGetDirContent(): void
30 self
::assertFalse($this->fileListing
->getDirContent('nonexistent directory'));
32 $fixturesDir = __DIR__
. '/_data/file_listing';
34 $dirContent = $this->fileListing
->getDirContent($fixturesDir);
35 if (is_bool($dirContent)) {
40 ['one.txt', 'two.md'],
41 array_values($dirContent),
45 public function testGetFileSelectOptions(): void
47 $fixturesDir = __DIR__
. '/_data/file_listing';
49 self
::assertFalse($this->fileListing
->getFileSelectOptions('nonexistent directory'));
51 $expectedHtmlWithoutActive = ' <option value="one.txt">' . "\n"
54 . ' <option value="two.md">' . "\n"
56 . ' </option>' . "\n";
59 $expectedHtmlWithoutActive,
60 $this->fileListing
->getFileSelectOptions($fixturesDir),
63 $expectedHtmlWithActive = ' <option value="one.txt">' . "\n"
66 . ' <option value="two.md" selected>' . "\n"
68 . ' </option>' . "\n";
71 $expectedHtmlWithActive,
72 $this->fileListing
->getFileSelectOptions($fixturesDir, '', 'two.md'),
75 $expectedFilteredHtml = ' <option value="one.txt">' . "\n"
77 . ' </option>' . "\n";
80 $expectedFilteredHtml,
81 $this->fileListing
->getFileSelectOptions($fixturesDir, '/.*\.txt/'),
85 public function testSupportedDecompressionsEmptyList(): void
87 $config = Config
::getInstance();
88 $config->settings
['ZipDump'] = false;
89 $config->settings
['GZipDump'] = false;
90 $config->settings
['BZipDump'] = false;
91 self
::assertEmpty($this->fileListing
->supportedDecompressions());
94 #[RequiresPhpExtension('bz2')]
95 public function testSupportedDecompressionsFull(): void
97 $config = Config
::getInstance();
98 $config->settings
['ZipDump'] = true;
99 $config->settings
['GZipDump'] = true;
100 $config->settings
['BZipDump'] = true;
101 self
::assertSame('gz|bz2|zip', $this->fileListing
->supportedDecompressions());
104 public function testSupportedDecompressionsPartial(): void
106 $config = Config
::getInstance();
107 $config->settings
['ZipDump'] = true;
108 $config->settings
['GZipDump'] = true;
109 $config->settings
['BZipDump'] = true;
110 $extensionString = 'gz';
111 if (extension_loaded('bz2')) {
112 $extensionString .= '|bz2';
115 $extensionString .= '|zip';
116 self
::assertSame($extensionString, $this->fileListing
->supportedDecompressions());