diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index d34824cfe..b9ccb6a6a 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -14,6 +14,7 @@ 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\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; @@ -202,7 +203,24 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getFileContent($pathToFile) { + $pathToFile = $this->formatFilePath($pathToFile); + if (!$this->hasFile($pathToFile)) { + $this->throwFileNotFound($pathToFile); + } + + /** @var \PharFileInfo $fileInfo*/ + $fileInfo = $this->tar[$pathToFile]; + + /** @var \SplFileObject $file */ + $file = $fileInfo->openFile(); + $content = ""; + + while (false !== ($char = $file->fgetc())) { + $content .= $char; + } + + return $content; } @@ -239,6 +257,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function buildArchiveResponse() { + $this->tar->setMetadata("comment", "Generated by Thelia v" . Thelia::THELIA_VERSION); + } @@ -267,8 +287,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $instance->setFileDownloader($fileDownloader); } - $instance->setCacheFile($instance->getCacheFile()) - ->copyFile($pathToArchive, $isOnline); + $instance->setCacheFile($instance->generateCacheFile($environment)) + ->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); /** * This throws TarArchiveBuilderException if diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 055ae03c9..6c3bc61a7 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -33,12 +33,11 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase Tlog::getNewInstance(); $this->tar = new TarArchiveBuilder(); + $this->tar->setEnvironment("dev"); } public function testAddFileAndDirectory() { - $this->tar->setEnvironment("dev"); - /** * File */ @@ -86,6 +85,68 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testAddValidFileFromString() { + $this->tar->addFileFromString( + "foo", "bar" + ); + $this->assertTrue( + $this->tar->hasFile("bar") + ); + + $this->assertEquals( + "foo", + $this->tar->getFileContent("bar") + ); + + $this->tar->addFileFromString( + "foo", "bar", "baz" + ); + + $this->assertTrue( + $this->tar->hasFile("baz/bar") + ); + + $this->assertEquals( + "foo", + $this->tar->getFileContent("baz/bar") + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileFromString() + { + $this->tar->addFileFromString( + "foo", $this + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileValueFromString() + { + $this->tar->addFileFromString( + $this, "foo" + ); + } + + + public function testDeleteFile() + { + $this->tar->addFileFromString( + "foo", "bar" + ); + + $this->assertTrue( + $this->tar->hasFile("bar") + ); + + $this->tar->deleteFile("bar"); + + $this->assertFalse( + $this->tar->hasFile("bar") + ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index 10eb1ef88..be8b8f53a 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -17,6 +17,7 @@ use Thelia\Core\Translation\Translator as TheliaTranslator; use Thelia\Exception\FileNotFoundException; use Thelia\Exception\HttpUrlException; use Thelia\Log\Tlog; +use Thelia\Tools\URL; /** * Class FileDownloader diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 569b15780..ab52472e6 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -315,7 +315,7 @@ class URL $clean; } - public function checkUrl($url, array $protocols = ["http", "https"]) + public static function checkUrl($url, array $protocols = ["http", "https"]) { $pattern = sprintf(UrlValidator::PATTERN, implode('|', $protocols));