Translated using Weblate (Lithuanian)
[phpmyadmin.git] / test / classes / FileListingTest.php
blob9e0a61cc94d6398afc334f4235d0d0362951cf5b
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests;
7 use PhpMyAdmin\FileListing;
9 use function array_values;
10 use function extension_loaded;
11 use function is_bool;
13 /**
14 * @covers \PhpMyAdmin\FileListing
16 class FileListingTest extends AbstractTestCase
18 /** @var FileListing $fileListing */
19 private $fileListing;
21 protected function setUp(): void
23 parent::setUp();
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)) {
35 $dirContent = [];
38 $this->assertSame(
40 'one.txt',
41 'two.md',
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"
54 . ' one.txt' . "\n"
55 . ' </option>' . "\n"
56 . ' <option value="two.md">' . "\n"
57 . ' two.md' . "\n"
58 . ' </option>' . "\n";
60 $this->assertSame(
61 $expectedHtmlWithoutActive,
62 $this->fileListing->getFileSelectOptions($fixturesDir)
65 $expectedHtmlWithActive = ' <option value="one.txt">' . "\n"
66 . ' one.txt' . "\n"
67 . ' </option>' . "\n"
68 . ' <option value="two.md" selected="selected">' . "\n"
69 . ' two.md' . "\n"
70 . ' </option>' . "\n";
72 $this->assertSame(
73 $expectedHtmlWithActive,
74 $this->fileListing->getFileSelectOptions($fixturesDir, '', 'two.md')
77 $expectedFilteredHtml = ' <option value="one.txt">' . "\n"
78 . ' one.txt' . "\n"
79 . ' </option>' . "\n";
81 $this->assertSame(
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());
95 /**
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());