3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\FileListing
;
9 use function array_values
;
10 use function extension_loaded
;
14 * @covers \PhpMyAdmin\FileListing
16 class FileListingTest
extends AbstractTestCase
18 /** @var FileListing $fileListing */
21 protected function setUp(): void
24 $this->fileListing
= new FileListing();
27 public function testGetDirContent(): void
29 $this->assertFalse($this->fileListing
->getDirContent('nonexistent directory'));
31 $fixturesDir = ROOT_PATH
. 'test/classes/_data/file_listing';
33 $dirContent = $this->fileListing
->getDirContent($fixturesDir);
34 if (is_bool($dirContent)) {
43 array_values($dirContent)
47 public function testGetFileSelectOptions(): void
49 $fixturesDir = ROOT_PATH
. 'test/classes/_data/file_listing';
51 $this->assertFalse($this->fileListing
->getFileSelectOptions('nonexistent directory'));
53 $expectedHtmlWithoutActive = ' <option value="one.txt">' . "\n"
56 . ' <option value="two.md">' . "\n"
58 . ' </option>' . "\n";
61 $expectedHtmlWithoutActive,
62 $this->fileListing
->getFileSelectOptions($fixturesDir)
65 $expectedHtmlWithActive = ' <option value="one.txt">' . "\n"
68 . ' <option value="two.md" selected="selected">' . "\n"
70 . ' </option>' . "\n";
73 $expectedHtmlWithActive,
74 $this->fileListing
->getFileSelectOptions($fixturesDir, '', 'two.md')
77 $expectedFilteredHtml = ' <option value="one.txt">' . "\n"
79 . ' </option>' . "\n";
82 $expectedFilteredHtml,
83 $this->fileListing
->getFileSelectOptions($fixturesDir, '/.*\.txt/')
87 public function testSupportedDecompressionsEmptyList(): void
89 $GLOBALS['cfg']['ZipDump'] = false;
90 $GLOBALS['cfg']['GZipDump'] = false;
91 $GLOBALS['cfg']['BZipDump'] = false;
92 $this->assertEmpty($this->fileListing
->supportedDecompressions());
96 * @requires extension bz2 1
98 public function testSupportedDecompressionsFull(): void
100 $GLOBALS['cfg']['ZipDump'] = true;
101 $GLOBALS['cfg']['GZipDump'] = true;
102 $GLOBALS['cfg']['BZipDump'] = true;
103 $this->assertEquals('gz|bz2|zip', $this->fileListing
->supportedDecompressions());
106 public function testSupportedDecompressionsPartial(): void
108 $GLOBALS['cfg']['ZipDump'] = true;
109 $GLOBALS['cfg']['GZipDump'] = true;
110 $GLOBALS['cfg']['BZipDump'] = true;
111 $extensionString = 'gz';
112 if (extension_loaded('bz2')) {
113 $extensionString .= '|bz2';
116 $extensionString .= '|zip';
117 $this->assertEquals($extensionString, $this->fileListing
->supportedDecompressions());