Finish implementing and testing zip
modifié: core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php renommé: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php -> core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php modifié: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php modifié: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php modifié: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?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\Archive\ArchiveBuilder;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Class TarArchiveBuilderTest
|
||||
* @package Thelia\Tests\FileFormat\Archive\ArchiveBuilder
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var TarArchiveBuilder */
|
||||
protected $tar;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
new Translator(new Container());
|
||||
|
||||
Tlog::getNewInstance();
|
||||
|
||||
$this->tar = new TarArchiveBuilder();
|
||||
}
|
||||
|
||||
public function testAddFileAndDirectory()
|
||||
{
|
||||
$this->tar->setEnvironment("dev");
|
||||
|
||||
/**
|
||||
* File
|
||||
*/
|
||||
$tar = $this->tar->addFile(
|
||||
__DIR__ . DS . "TestResources/test_file"
|
||||
);
|
||||
|
||||
$this->assertTrue($tar->hasFile("test_file"));
|
||||
|
||||
$this->assertFalse($tar->hasDirectory("test_file"));
|
||||
|
||||
$tar = $this->tar->addFile(
|
||||
__DIR__ . DS . "TestResources/test_file",
|
||||
null,
|
||||
"TEST.txt"
|
||||
);
|
||||
|
||||
$this->assertTrue($tar->hasFile("TEST.txt"));
|
||||
|
||||
$this->assertFalse($tar->hasDirectory("TEST.txt"));
|
||||
|
||||
/**
|
||||
* Directory
|
||||
*/
|
||||
$this->tar->addDirectory("foo");
|
||||
|
||||
$this->assertTrue($tar->hasDirectory("foo"));
|
||||
|
||||
$this->assertFalse($tar->hasFile("foo"));
|
||||
|
||||
/**s
|
||||
* File in a directory
|
||||
*/
|
||||
$this->tar->addFile(
|
||||
__DIR__ . DS . "TestResources/test_file",
|
||||
"bar",
|
||||
"baz"
|
||||
);
|
||||
|
||||
$this->assertTrue($this->tar->hasFile("bar/baz"));
|
||||
|
||||
$this->assertTrue($this->tar->hasDirectory("bar"));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -53,52 +53,52 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->zip->getFilePath("foo")
|
||||
$this->zip->formatFilePath("foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->zip->getFilePath("/foo")
|
||||
$this->zip->formatFilePath("/foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->zip->getFilePath("foo/")
|
||||
$this->zip->formatFilePath("foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->zip->getFilePath("/foo/")
|
||||
$this->zip->formatFilePath("/foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
$this->zip->getFilePath("foo/bar")
|
||||
$this->zip->formatFilePath("foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
$this->zip->getFilePath("/foo/bar")
|
||||
$this->zip->formatFilePath("/foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
$this->zip->getFilePath("/foo//bar/")
|
||||
$this->zip->formatFilePath("/foo//bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar",
|
||||
$this->zip->getFilePath("/foo/bar/")
|
||||
$this->zip->formatFilePath("/foo/bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz",
|
||||
$this->zip->getFilePath("foo/bar/baz")
|
||||
$this->zip->formatFilePath("foo/bar/baz")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz",
|
||||
$this->zip->getFilePath("//foo/bar///baz/")
|
||||
$this->zip->formatFilePath("//foo/bar///baz/")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -106,52 +106,52 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
$this->zip->getDirectoryPath("foo")
|
||||
$this->zip->formatDirectoryPath("foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
$this->zip->getDirectoryPath("/foo")
|
||||
$this->zip->formatDirectoryPath("/foo")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
$this->zip->getDirectoryPath("foo/")
|
||||
$this->zip->formatDirectoryPath("foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/",
|
||||
$this->zip->getDirectoryPath("/foo/")
|
||||
$this->zip->formatDirectoryPath("/foo/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
$this->zip->getDirectoryPath("foo/bar")
|
||||
$this->zip->formatDirectoryPath("foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
$this->zip->getDirectoryPath("/foo/bar")
|
||||
$this->zip->formatDirectoryPath("/foo/bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
$this->zip->getDirectoryPath("/foo//bar/")
|
||||
$this->zip->formatDirectoryPath("/foo//bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/",
|
||||
$this->zip->getDirectoryPath("/foo/bar/")
|
||||
$this->zip->formatDirectoryPath("/foo/bar/")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz/",
|
||||
$this->zip->getDirectoryPath("foo/bar/baz")
|
||||
$this->zip->formatDirectoryPath("foo/bar/baz")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"/foo/bar/baz/",
|
||||
$this->zip->getDirectoryPath("//foo/bar///baz/")
|
||||
$this->zip->formatDirectoryPath("//foo/bar///baz/")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
|
||||
* @expectedExceptionMessage [Zip Error] The file is not a zip archive
|
||||
*/
|
||||
public function testLoadNotValidZip()
|
||||
@@ -202,7 +202,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException
|
||||
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
|
||||
* @expectedExceptionMessage [Zip Error] The file is not a zip archive
|
||||
*/
|
||||
public function testLoadOnlineAvailableAndNotValidFile()
|
||||
@@ -339,4 +339,49 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$loadedArchiveResponseContent
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddValidFileFromString()
|
||||
{
|
||||
$this->loadedZip->addFileFromString(
|
||||
"foo", "bar"
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->loadedZip->hasFile("bar")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"foo",
|
||||
$this->loadedZip->getFileContent("bar")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Exception\FileNotFoundException
|
||||
*/
|
||||
public function testGetFileContentFileNotFound()
|
||||
{
|
||||
$this->loadedZip->getFileContent("bar");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \ErrorException
|
||||
*/
|
||||
public function testAddNotValidFileFromString()
|
||||
{
|
||||
$this->loadedZip->addFileFromString(
|
||||
"foo", $this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \ErrorException
|
||||
*/
|
||||
public function testAddNotValidFileValueFromString()
|
||||
{
|
||||
$this->loadedZip->addFileFromString(
|
||||
$this, "bar"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user