Fix FileDownloader test

modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php
	modifié:         core/lib/Thelia/Tools/FileDownload/FileDownloader.php
	modifié:         core/lib/Thelia/Tools/URL.php
This commit is contained in:
Benjamin Perche
2014-07-03 14:20:31 +02:00
parent 9e66c4759a
commit 4b78f23fa3
4 changed files with 87 additions and 5 deletions

View File

@@ -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

View File

@@ -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")
);
}
}

View File

@@ -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

View File

@@ -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));