Fixed unit tests

This commit is contained in:
Franck Allimant
2014-06-26 11:26:49 +02:00
parent 4012761815
commit 9b455e6c87
6 changed files with 95 additions and 31 deletions

View File

@@ -208,7 +208,7 @@ class FileManager
*
* @param FileModelInterface $model File being deleted
*/
public function c($model)
public function deleteFile($model)
{
$url = $model->getUploadDir() . DS . $model->getFile();

View File

@@ -11,7 +11,6 @@ use Thelia\Form\BaseForm;
use Thelia\Form\CategoryImageModification;
use Thelia\Model\Base\CategoryImage as BaseCategoryImage;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Base\CategoryImageQuery;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
use Thelia\Files\FileModelInterface;

View File

@@ -3,23 +3,24 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Files\FileModelInterface;
use Thelia\Files\FileModelParentInterface;
use Thelia\Form\BaseForm;
use Thelia\Form\ContentDocumentModification;
use Thelia\Model\Base\ContentDocument as BaseContentDocument;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Base\ContentDocumentQuery;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Breadcrumb\FolderBreadcrumbTrait;
use Thelia\Files\FileModelInterface;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
class ContentDocument extends BaseContentDocument implements BreadcrumbInterface, FileModelInterface
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use ModelEventDispatcherTrait;
use PositionManagementTrait;
use FolderBreadcrumbTrait;
/**

View File

@@ -18,6 +18,7 @@ use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Action\Document;
use Thelia\Core\Event\Document\DocumentEvent;
use Thelia\Files\FileManager;
use Thelia\Model\ConfigQuery;
/**
@@ -39,6 +40,25 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$container->set("event_dispatcher", $dispatcher);
$fileManager = new FileManager([
"document.product" => "Thelia\\Model\\ProductDocument",
"image.product" => "Thelia\\Model\\ProductImage",
"document.category" => "Thelia\\Model\\CategoryDocument",
"image.category" => "Thelia\\Model\\CategoryImage",
"document.content" => "Thelia\\Model\\ContentDocument",
"image.content" => "Thelia\\Model\\ContentImage",
"document.folder" => "Thelia\\Model\\FolderDocument",
"image.folder" => "Thelia\\Model\\FolderImage",
"document.brand" => "Thelia\\Model\\BrandDocument",
"image.brand" => "Thelia\\Model\\BrandImage",
]);
$container->set("thelia.file_manager", $this->getFileManager());
$request = new Request();
$request->setSession($this->session);
@@ -47,6 +67,28 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
return $container;
}
public function getFileManager()
{
$fileManager = new FileManager([
"document.product" => "Thelia\\Model\\ProductDocument",
"image.product" => "Thelia\\Model\\ProductImage",
"document.category" => "Thelia\\Model\\CategoryDocument",
"image.category" => "Thelia\\Model\\CategoryImage",
"document.content" => "Thelia\\Model\\ContentDocument",
"image.content" => "Thelia\\Model\\ContentImage",
"document.folder" => "Thelia\\Model\\FolderDocument",
"image.folder" => "Thelia\\Model\\FolderImage",
"document.brand" => "Thelia\\Model\\BrandDocument",
"image.brand" => "Thelia\\Model\\BrandImage",
]);
return $fileManager;
}
public function setUp()
{
$this->session = new Session(new MockArraySessionStorage());
@@ -100,7 +142,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new DocumentEvent($this->request);
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
$document->processDocument($event);
}
@@ -115,7 +157,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new DocumentEvent($this->request);
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
$event->setCacheFilepath("blablabla.txt");
$event->setCacheSubdirectory("tests");
@@ -133,7 +175,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new DocumentEvent($this->request);
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
$event->setCacheFilepath("blablabla.pdf");
$event->setCacheSubdirectory("../../../");
@@ -151,7 +193,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setSourceFilepath(__DIR__."/assets/documents/sources/test-document-1.txt");
$event->setCacheSubdirectory("tests");
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_document_delivery_mode')->findOne();
@@ -180,7 +222,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setSourceFilepath(__DIR__."/assets/documents/sources/test-document-2.txt");
$event->setCacheSubdirectory("tests");
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_document_delivery_mode')->findOne();
@@ -205,7 +247,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setCacheSubdirectory('tests');
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
$document->clearCache($event);
}
@@ -214,7 +256,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new DocumentEvent($this->request);
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
$document->clearCache($event);
}
@@ -230,7 +272,7 @@ class DocumentTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setCacheSubdirectory('../../../..');
$document = new Document($this->getContainer());
$document = new Document($this->getFileManager());
$document->clearCache($event);
}

View File

@@ -18,6 +18,7 @@ use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Action\Image;
use Thelia\Core\Event\Image\ImageEvent;
use Thelia\Files\FileManager;
use Thelia\Model\ConfigQuery;
/**
@@ -47,6 +48,28 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
return $container;
}
public function getFileManager()
{
$fileManager = new FileManager([
"document.product" => "Thelia\\Model\\ProductDocument",
"image.product" => "Thelia\\Model\\ProductImage",
"document.category" => "Thelia\\Model\\CategoryDocument",
"image.category" => "Thelia\\Model\\CategoryImage",
"document.content" => "Thelia\\Model\\ContentDocument",
"image.content" => "Thelia\\Model\\ContentImage",
"document.folder" => "Thelia\\Model\\FolderDocument",
"image.folder" => "Thelia\\Model\\FolderImage",
"document.brand" => "Thelia\\Model\\BrandDocument",
"image.brand" => "Thelia\\Model\\BrandImage",
]);
return $fileManager;
}
public function setUp()
{
$this->session = new Session(new MockArraySessionStorage());
@@ -100,7 +123,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -115,7 +138,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$event->setCacheFilepath("blablabla.png");
$event->setCacheSubdirectory("tests");
@@ -133,7 +156,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$event->setCacheFilepath("blablabla.png");
$event->setCacheSubdirectory("../../../");
@@ -151,7 +174,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-1.png");
$event->setCacheSubdirectory("tests");
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
@@ -180,7 +203,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setSourceFilepath(__DIR__."/assets/images/sources/test-image-9.png");
$event->setCacheSubdirectory("tests");
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
// mock cache configuration.
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
@@ -214,7 +237,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setHeight(100);
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -234,7 +257,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setHeight(100);
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -251,7 +274,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setEffects(array("grayscale", "vertical_flip", "horizontal_flip", 'colorize:#00ff00', 'gamma: 0.2'));
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -271,7 +294,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setHeight(100);
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -291,7 +314,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setHeight(150);
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -309,7 +332,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setWidth(100);
$event->setHeight(100);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -327,7 +350,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setWidth(100);
$event->setHeight(100);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->processImage($event);
}
@@ -338,7 +361,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setCacheSubdirectory('tests');
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->clearCache($event);
}
@@ -347,7 +370,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
{
$event = new ImageEvent($this->request);
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->clearCache($event);
}
@@ -363,7 +386,7 @@ class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
$event->setCacheSubdirectory('../../../..');
$image = new Image($this->getContainer());
$image = new Image($this->getFileManager());
$image->clearCache($event);
}

View File

@@ -394,5 +394,4 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase
'images', 'brand'
);
}
}