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
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Tests\Matomo\Decompress;
use Matomo\Decompress\Tar;
class TarTest extends TestBase
{
public function testTarGzFile()
{
$filename = $this->fixtureDirectory . '/test.tar.gz';
$unzip = new Tar($filename, 'gz');
$res = $unzip->extract($this->tempDirectory);
$this->assertTrue($res);
$content = $unzip->listContent();
$this->assertCount(3, $content);
$this->assertEquals('tarout1.txt', $content[0]['filename']);
$this->assertEquals('tardir/tarout2.txt', $content[1]['filename']);
$this->assertEquals('tardir/', $content[2]['filename']);
$this->assertFileContentsEquals('TESTDATA', $this->tempDirectory . 'tarout1.txt');
$this->assertFileContentsEquals('MORETESTDATA', $this->tempDirectory . 'tardir/tarout2.txt');
}
public function testTarBzipFile()
{
$filename = $this->fixtureDirectory . '/test.tar.bz2';
$unzip = new Tar($filename, 'bz2');
$res = $unzip->extract($this->tempDirectory);
$this->assertTrue($res);
$content = $unzip->listContent();
$this->assertCount(1, $content);
$this->assertEquals('testbz.txt', $content[0]['filename']);
$this->assertFileContentsEquals('TESTSTRING', $this->tempDirectory . 'testbz.txt');
}
public function testUnzipInvalidFile2()
{
$filename = $this->fixtureDirectory . '/NotExisting.zip';
$unzip = new Tar($filename);
$res = $unzip->extract($this->tempDirectory);
$this->assertEquals(0, $res);
$this->assertStringContainsString('Unable to open in read mode', $unzip->errorInfo());
$this->assertNull($unzip->extractInString($filename));
}
}
|