Skip to content

Commit

Permalink
Add some tests for FileListing class
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Sep 21, 2018
1 parent 82eb1a0 commit 05b064c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
5 changes: 1 addition & 4 deletions libraries/classes/FileListing.php
Expand Up @@ -88,10 +88,7 @@ public function supportedDecompressions(): string
$compressions = '';

if ($cfg['GZipDump'] && function_exists('gzopen')) {
if (!empty($compressions)) {
$compressions .= '|';
}
$compressions .= 'gz';
$compressions = 'gz';
}
if ($cfg['BZipDump'] && function_exists('bzopen')) {
if (!empty($compressions)) {
Expand Down
62 changes: 62 additions & 0 deletions test/classes/FileListingTest.php
@@ -0,0 +1,62 @@
<?php
/**
* Tests for PhpMyAdmin\FileListing
* @package PhpMyAdmin\Tests
*/

namespace PhpMyAdmin\Tests;

use PhpMyAdmin\FileListing;
use PHPUnit\Framework\TestCase;

/**
* Class FileListingTest
* @package PhpMyAdmin\Tests
*/
class FileListingTest extends TestCase
{
/**
* @var FileListing $fileListing
*/
private $fileListing;

/**
* @return void
*/
protected function setUp(): void
{
$this->fileListing = new FileListing();
}

/**
* @return void
*/
public function testGetDirContent(): void
{
$this->assertFalse($this->fileListing->getDirContent('nonexistent directory'));
}

/**
* @return void
*/
public function testGetFileSelectOptions(): void
{
$this->assertFalse($this->fileListing->getFileSelectOptions('nonexistent directory'));
}

/**
* @return void
*/
public function testSupportedDecompressions(): void
{
$GLOBALS['cfg']['ZipDump'] = false;
$GLOBALS['cfg']['GZipDump'] = false;
$GLOBALS['cfg']['BZipDump'] = false;
$this->assertEmpty($this->fileListing->supportedDecompressions());

$GLOBALS['cfg']['ZipDump'] = true;
$GLOBALS['cfg']['GZipDump'] = true;
$GLOBALS['cfg']['BZipDump'] = true;
$this->assertEquals('gz|bz2|zip', $this->fileListing->supportedDecompressions());
}
}

0 comments on commit 05b064c

Please sign in to comment.