blob: 9581357df1c87cbdb665a90f46a53e7180fde48f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\FileListing;
use function array_values;
use function extension_loaded;
use function is_bool;
class FileListingTest extends AbstractTestCase
{
/** @var FileListing $fileListing */
private $fileListing;
protected function setUp(): void
{
parent::setUp();
$this->fileListing = new FileListing();
}
public function testGetDirContent(): void
{
$this->assertFalse($this->fileListing->getDirContent('nonexistent directory'));
$fixturesDir = ROOT_PATH . 'test/classes/_data/file_listing';
$dirContent = $this->fileListing->getDirContent($fixturesDir);
if (is_bool($dirContent)) {
$dirContent = [];
}
$this->assertSame(
array_values([
'one.txt',
'two.md',
]),
array_values($dirContent)
);
}
public function testGetFileSelectOptions(): void
{
$fixturesDir = ROOT_PATH . 'test/classes/_data/file_listing';
$this->assertFalse($this->fileListing->getFileSelectOptions('nonexistent directory'));
$expectedHtmlWithoutActive =
' <option value="one.txt">' . "\n"
. ' one.txt' . "\n"
. ' </option>' . "\n"
. ' <option value="two.md">' . "\n"
. ' two.md' . "\n"
. ' </option>' . "\n";
$this->assertSame(
$expectedHtmlWithoutActive,
$this->fileListing->getFileSelectOptions($fixturesDir)
);
$expectedHtmlWithActive =
' <option value="one.txt">' . "\n"
. ' one.txt' . "\n"
. ' </option>' . "\n"
. ' <option value="two.md" selected="selected">' . "\n"
. ' two.md' . "\n"
. ' </option>' . "\n";
$this->assertSame(
$expectedHtmlWithActive,
$this->fileListing->getFileSelectOptions($fixturesDir, '', 'two.md')
);
$expectedFilteredHtml =
' <option value="one.txt">' . "\n"
. ' one.txt' . "\n"
. ' </option>' . "\n";
$this->assertSame(
$expectedFilteredHtml,
$this->fileListing->getFileSelectOptions($fixturesDir, '/.*\.txt/')
);
}
public function testSupportedDecompressionsEmptyList(): void
{
$GLOBALS['cfg']['ZipDump'] = false;
$GLOBALS['cfg']['GZipDump'] = false;
$GLOBALS['cfg']['BZipDump'] = false;
$this->assertEmpty($this->fileListing->supportedDecompressions());
}
/**
* @requires extension bz2 1
*/
public function testSupportedDecompressionsFull(): void
{
$GLOBALS['cfg']['ZipDump'] = true;
$GLOBALS['cfg']['GZipDump'] = true;
$GLOBALS['cfg']['BZipDump'] = true;
$this->assertEquals('gz|bz2|zip', $this->fileListing->supportedDecompressions());
}
public function testSupportedDecompressionsPartial(): void
{
$GLOBALS['cfg']['ZipDump'] = true;
$GLOBALS['cfg']['GZipDump'] = true;
$GLOBALS['cfg']['BZipDump'] = true;
$extensionString = 'gz';
if (extension_loaded('bz2')) {
$extensionString .= '|bz2';
}
$extensionString .= '|zip';
$this->assertEquals($extensionString, $this->fileListing->supportedDecompressions());
}
}
|