Finish Tar archive builder
modifié: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php modifié: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.tar modifié: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php
This commit is contained in:
@@ -13,9 +13,10 @@
|
||||
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
|
||||
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
|
||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException;
|
||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Thelia;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Exception\FileNotReadableException;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Tools\FileDownload\FileDownloaderInterface;
|
||||
|
||||
@@ -68,7 +69,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
|
||||
$this->compression = $compressionType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->tar instanceof \PharData) {
|
||||
@@ -76,7 +77,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
|
||||
unlink($this->cacheFile);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath It is the path to access the file.
|
||||
@@ -118,6 +119,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
|
||||
|
||||
$this->tar->addFile($filePath, $name);
|
||||
|
||||
/**
|
||||
* And clear the download temp file
|
||||
*/
|
||||
unlink($fileDownloadCache);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -257,9 +263,32 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
|
||||
*/
|
||||
public function buildArchiveResponse()
|
||||
{
|
||||
$this->tar->setMetadata("comment", "Generated by Thelia v" . Thelia::THELIA_VERSION);
|
||||
$this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION);
|
||||
|
||||
if (!is_file($this->cacheFile)) {
|
||||
$this->throwFileNotFound($this->cacheFile);
|
||||
}
|
||||
|
||||
if (!is_readable($this->cacheFile)) {
|
||||
throw new FileNotReadableException(
|
||||
$this->translator->trans(
|
||||
"The file %file is not readable",
|
||||
[
|
||||
"%file" => $this->cacheFile
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->cacheFile);
|
||||
|
||||
return new Response(
|
||||
$content,
|
||||
200,
|
||||
[
|
||||
"Content-Type" => $this->getMimeType(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -132,7 +132,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testDeleteFile()
|
||||
{
|
||||
$this->tar->addFileFromString(
|
||||
@@ -149,4 +148,138 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->tar->hasFile("bar")
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadValidArchive()
|
||||
{
|
||||
$tar = TarArchiveBuilder::loadArchive(
|
||||
__DIR__ . DS . "TestResources/well_formatted.tar",
|
||||
"dev"
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
get_class($this->tar),
|
||||
$tar
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$tar->hasFile("LICENSE.txt")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException
|
||||
*/
|
||||
public function testLoadInvalidArchive()
|
||||
{
|
||||
$tar = TarArchiveBuilder::loadArchive(
|
||||
__DIR__ . DS . "TestResources/bad_formatted.tar",
|
||||
"dev"
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatDirectoryPath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"foo/",
|
||||
$this->tar->formatDirectoryPath("foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/",
|
||||
$this->tar->formatDirectoryPath("/foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/",
|
||||
$this->tar->formatDirectoryPath("foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/",
|
||||
$this->tar->formatDirectoryPath("/foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/",
|
||||
$this->tar->formatDirectoryPath("foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/",
|
||||
$this->tar->formatDirectoryPath("/foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/",
|
||||
$this->tar->formatDirectoryPath("/foo//bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/",
|
||||
$this->tar->formatDirectoryPath("/foo/bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/baz/",
|
||||
$this->tar->formatDirectoryPath("foo/bar/baz")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/baz/",
|
||||
$this->tar->formatDirectoryPath("//foo/bar///baz/")
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatFilePath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->tar->formatFilePath("foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->tar->formatFilePath("/foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->tar->formatFilePath("foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->tar->formatFilePath("/foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar",
|
||||
$this->tar->formatFilePath("foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar",
|
||||
$this->tar->formatFilePath("/foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar",
|
||||
$this->tar->formatFilePath("/foo//bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar",
|
||||
$this->tar->formatFilePath("/foo/bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/baz",
|
||||
$this->tar->formatFilePath("foo/bar/baz")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo/bar/baz",
|
||||
$this->tar->formatFilePath("//foo/bar///baz/")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
foo
|
||||
bar
|
||||
Binary file not shown.
@@ -49,7 +49,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* This method formats a path to be compatible with \ZipArchive
|
||||
*/
|
||||
public function testGetFilePath()
|
||||
public function testFormatFilePath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
@@ -102,7 +102,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetDirectoryPath()
|
||||
public function testFormatDirectoryPath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
|
||||
Reference in New Issue
Block a user