Define archive builders and formatters
nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php nouveau fichier: core/lib/Thelia/Core/FileFormat/FormatInterface.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/test_file nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.zip nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php nouveau fichier: core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php nouveau fichier: core/lib/Thelia/Tests/Tools/FakeFileDownloader.php nouveau fichier: core/lib/Thelia/Tests/Tools/FileDownloaderTest.php nouveau fichier: core/lib/Thelia/Tools/FileDownload/FileDownloader.php nouveau fichier: core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php nouveau fichier: core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php modifié: core/lib/Thelia/Tools/URL.php
This commit is contained in:
@@ -40,65 +40,115 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->zip = new ZipArchiveBuilder();
|
||||
|
||||
<<<<<<< HEAD
|
||||
$this->zip->setEnvironment("dev");
|
||||
|
||||
$this->loadedZip = $this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/well_formatted.zip"
|
||||
=======
|
||||
$this->loadedZip = $this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/well_formatted.zip",
|
||||
"dev"
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method formats a path to be compatible with \ZipArchive
|
||||
<<<<<<< HEAD
|
||||
*/
|
||||
public function testFormatFilePath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->zip->formatFilePath("foo")
|
||||
=======
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function testGetFilePath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->zip->getFilePath("foo")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("/foo")
|
||||
=======
|
||||
$this->zip->getFilePath("/foo")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("foo/")
|
||||
=======
|
||||
$this->zip->getFilePath("foo/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("/foo/")
|
||||
=======
|
||||
$this->zip->getFilePath("/foo/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("foo/bar")
|
||||
=======
|
||||
$this->zip->getFilePath("foo/bar")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("/foo/bar")
|
||||
=======
|
||||
$this->zip->getFilePath("/foo/bar")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("/foo//bar/")
|
||||
=======
|
||||
$this->zip->getFilePath("/foo//bar/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("/foo/bar/")
|
||||
=======
|
||||
$this->zip->getFilePath("/foo/bar/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("foo/bar/baz")
|
||||
=======
|
||||
$this->zip->getFilePath("foo/bar/baz")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatFilePath("//foo/bar///baz/")
|
||||
);
|
||||
}
|
||||
@@ -108,58 +158,110 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
$this->zip->formatDirectoryPath("foo")
|
||||
=======
|
||||
$this->zip->getFilePath("//foo/bar///baz/")
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetDirectoryPath()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
$this->zip->getDirectoryPath("foo")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("/foo")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("/foo")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("foo/")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("foo/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("/foo/")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("/foo/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("foo/bar")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("foo/bar")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("/foo/bar")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("/foo/bar")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("/foo//bar/")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("/foo//bar/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("/foo/bar/")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("/foo/bar/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("foo/bar/baz")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("foo/bar/baz")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz/",
|
||||
<<<<<<< HEAD
|
||||
$this->zip->formatDirectoryPath("//foo/bar///baz/")
|
||||
=======
|
||||
$this->zip->getDirectoryPath("//foo/bar///baz/")
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadValidZip()
|
||||
{
|
||||
$loadedZip = $this->zip->loadArchive(
|
||||
<<<<<<< HEAD
|
||||
__DIR__ . DS . "TestResources/well_formatted.zip"
|
||||
=======
|
||||
__DIR__ . DS . "TestResources/well_formatted.zip",
|
||||
"dev"
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
@@ -169,13 +271,22 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
|
||||
=======
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException
|
||||
>>>>>>> Define archive builders and formatters
|
||||
* @expectedExceptionMessage [Zip Error] The file is not a zip archive
|
||||
*/
|
||||
public function testLoadNotValidZip()
|
||||
{
|
||||
$this->zip->loadArchive(
|
||||
<<<<<<< HEAD
|
||||
__DIR__ . DS . "TestResources/bad_formatted.zip"
|
||||
=======
|
||||
__DIR__ . DS . "TestResources/bad_formatted.zip",
|
||||
"dev"
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
@@ -185,31 +296,56 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoadNotExistingFile()
|
||||
{
|
||||
$this->zip->loadArchive(
|
||||
<<<<<<< HEAD
|
||||
__DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip"
|
||||
=======
|
||||
__DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip",
|
||||
"dev"
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadOnlineAvailableAndValidFile()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
$this->zip->setFileDownloader(FakeFileDownloader::getInstance());
|
||||
|
||||
$this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/well_formatted.zip",
|
||||
true
|
||||
=======
|
||||
$this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/well_formatted.zip",
|
||||
"dev",
|
||||
true,
|
||||
FakeFileDownloader::getInstance()
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
|
||||
=======
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException
|
||||
>>>>>>> Define archive builders and formatters
|
||||
* @expectedExceptionMessage [Zip Error] The file is not a zip archive
|
||||
*/
|
||||
public function testLoadOnlineAvailableAndNotValidFile()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
$this->zip->setFileDownloader(FakeFileDownloader::getInstance());
|
||||
|
||||
$this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/bad_formatted.zip",
|
||||
true
|
||||
=======
|
||||
$this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/bad_formatted.zip",
|
||||
"dev",
|
||||
true,
|
||||
FakeFileDownloader::getInstance()
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
@@ -218,11 +354,19 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testLoadOnlineNotExistingFile()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
$this->zip->setFileDownloader(FakeFileDownloader::getInstance());
|
||||
|
||||
$this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip",
|
||||
true
|
||||
=======
|
||||
$this->zip->loadArchive(
|
||||
__DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip",
|
||||
"dev",
|
||||
true,
|
||||
FakeFileDownloader::getInstance()
|
||||
>>>>>>> Define archive builders and formatters
|
||||
);
|
||||
}
|
||||
|
||||
@@ -325,7 +469,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testBuildArchiveResponse()
|
||||
{
|
||||
$loadedArchiveResponse = $this->loadedZip
|
||||
<<<<<<< HEAD
|
||||
->buildArchiveResponse("test")
|
||||
=======
|
||||
->buildArchiveResponse()
|
||||
>>>>>>> Define archive builders and formatters
|
||||
;
|
||||
|
||||
$loadedArchiveResponseContent = $loadedArchiveResponse->getContent();
|
||||
@@ -337,6 +485,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$loadedArchiveResponseContent
|
||||
);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
public function testAddValidFileFromString()
|
||||
{
|
||||
@@ -396,3 +545,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
}
|
||||
=======
|
||||
}
|
||||
>>>>>>> Define archive builders and formatters
|
||||
|
||||
@@ -72,4 +72,8 @@ class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->manager->delete("foo");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
=======
|
||||
}
|
||||
>>>>>>> Define archive builders and formatters
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\FileFormat\Formatter;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Thelia\Core\FileFormat\Formatter\AbstractFormatter;
|
||||
use Thelia\Core\FileFormat\Formatter\FormatterManager;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Class FormatterManagerTest
|
||||
* @package Thelia\Tests\FileFormat\Formatter
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class FormatterManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var FormatterManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
new Translator(
|
||||
new Container()
|
||||
);
|
||||
$this->manager = new FormatterManager();
|
||||
}
|
||||
|
||||
public function testAddFormatter()
|
||||
{
|
||||
/** @var AbstractFormatter $instance */
|
||||
$instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter");
|
||||
|
||||
$this->manager->add($instance);
|
||||
|
||||
$archiveBuilders = $this->manager->getAll();
|
||||
|
||||
$this->assertTrue(
|
||||
array_key_exists($instance->getName(), $archiveBuilders)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDeleteFormatter()
|
||||
{
|
||||
/** @var AbstractFormatter $instance */
|
||||
$instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter");
|
||||
|
||||
$this->manager->add($instance);
|
||||
|
||||
$this->manager->delete($instance->getName());
|
||||
|
||||
$this->assertTrue(
|
||||
count($this->manager->getAll()) === 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testDeleteNotExistingFormatter()
|
||||
{
|
||||
$this->manager->delete("foo");
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,13 @@ use Thelia\Tools\FileDownload\FileDownloader;
|
||||
class FakeFileDownloader extends FileDownloader
|
||||
{
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* @param string $url
|
||||
* @param string $pathToStore
|
||||
=======
|
||||
* @param string $url
|
||||
* @param string $pathToStore
|
||||
>>>>>>> Define archive builders and formatters
|
||||
* @throws \Thelia\Exception\FileNotFoundException
|
||||
* @throws \ErrorException
|
||||
* @throws \HttpUrlException
|
||||
@@ -41,4 +46,8 @@ class FakeFileDownloader extends FileDownloader
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
=======
|
||||
}
|
||||
>>>>>>> Define archive builders and formatters
|
||||
|
||||
@@ -14,7 +14,11 @@ namespace Thelia\Tests\Type;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Log\Tlog;
|
||||
<<<<<<< HEAD
|
||||
use Thelia\Tools\FileDownload\FileDownloader;
|
||||
=======
|
||||
use Thelia\Tools\FileDownloader;
|
||||
>>>>>>> Define archive builders and formatters
|
||||
|
||||
/**
|
||||
* Class FileDownloaderTest
|
||||
@@ -60,4 +64,8 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->downloader->download("https://github.com/thelia/thelia", "php://temp");
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
=======
|
||||
}
|
||||
>>>>>>> Define archive builders and formatters
|
||||
|
||||
@@ -787,7 +787,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase
|
||||
->getMock();
|
||||
|
||||
$stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile')
|
||||
->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubUploadedFile->expects($this->any())
|
||||
->method('getClientOriginalExtension')
|
||||
@@ -814,7 +814,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase
|
||||
->getMock();
|
||||
|
||||
$stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile')
|
||||
->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubUploadedFile->expects($this->any())
|
||||
->method('getClientOriginalExtension')
|
||||
|
||||
Reference in New Issue
Block a user