From cef3787d68b17578ed3caee5d3a4a19bebc4d0fd Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 24 Sep 2013 19:06:10 +0200 Subject: [PATCH] Working : Fix : Unit test --- .../Thelia/Tests/Tools/FileManagerTest.php | 37 +++++++++++++++++++ core/lib/Thelia/Tools/FileManager.php | 23 ++++++------ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index 7530a793a..8dce5afcc 100644 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -740,9 +740,46 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('/admin/folders/update/1?current_tab=documents', $actual); $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_DOCUMENTS); $this->assertEquals(false, $actual); + + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, 'bad'); + $this->assertEquals(false, $actual); } + /** + * @covers Thelia\Tools\FileManager::getFormId + */ + public function testGetFormId() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager($stubContainer); + + $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.product.image.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.category.image.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.content.image.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.folder.image.modification', $actual); + $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(false, $actual); + + $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.product.document.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.category.document.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.content.document.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.folder.document.modification', $actual); + $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(false, $actual); + } + /** * @covers Thelia\Tools\FileManager::renameFile */ diff --git a/core/lib/Thelia/Tools/FileManager.php b/core/lib/Thelia/Tools/FileManager.php index 45c633fde..6c06fb416 100644 --- a/core/lib/Thelia/Tools/FileManager.php +++ b/core/lib/Thelia/Tools/FileManager.php @@ -306,7 +306,7 @@ class FileManager * Delete image from file storage and database * * @param CategoryImage|ProductImage|ContentImage|FolderImage|CategoryDocument|ProductDocument|ContentDocument|FolderDocument $model File being deleted - * @param string $parentType Parent type + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * @param string $fileType File type ex FileManager::FILE_TYPE_DOCUMENTS * * @todo refactor make all pictures using propel inheritance and factorise image behaviour into one single clean action @@ -322,7 +322,7 @@ class FileManager /** * Get image model from type * - * @param string $parentType Parent type + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * * @return null|\Thelia\Model\CategoryImage|\Thelia\Model\ContentImage|\Thelia\Model\FolderImage|\Thelia\Model\ProductImage * @@ -353,7 +353,7 @@ class FileManager /** * Get document model from type * - * @param string $parentType Parent type + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * * @return null|ProductDocument|CategoryDocument|ContentDocument|FolderDocument * @@ -384,7 +384,7 @@ class FileManager /** * Get image model query from type * - * @param string $parentType + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * * @return null|\Thelia\Model\CategoryImageQuery|\Thelia\Model\ContentImageQuery|\Thelia\Model\FolderImageQuery|\Thelia\Model\ProductImageQuery * @@ -415,7 +415,7 @@ class FileManager /** * Get document model query from type * - * @param string $parentType + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * * @return null|ProductDocumentQuery|CategoryDocumentQuery|ContentDocumentQuery|FolderDocumentQuery * @@ -446,7 +446,8 @@ class FileManager /** * Get form service id from type * - * @param string $parentType + * @param string $parentType Parent type ex : self::TYPE_PRODUCT + * @param string $fileType Parent id * * @return string * @@ -488,8 +489,8 @@ class FileManager /** * Get image parent model from type * - * @param string $parentType - * @param int $parentId + * @param string $parentType Parent type ex : self::TYPE_PRODUCT + * @param int $parentId Parent Id * * @return null|\Thelia\Model\Category|\Thelia\Model\Content|\Thelia\Model\Folder|\Thelia\Model\Product * @@ -520,7 +521,7 @@ class FileManager /** * Get image parent model from type * - * @param string $parentType Parent type + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * @param Request $request Request service * * @todo refactor make all pictures using propel inheritance and factorise image behaviour into one single clean action @@ -552,7 +553,7 @@ class FileManager /** * Get document parent model from type * - * @param string $parentType Parent type + * @param string $parentType Parent type ex : self::TYPE_PRODUCT * @param Request $request Request service * * @todo refactor make all document using propel inheritance and factorise image behaviour into one single clean action @@ -585,7 +586,7 @@ class FileManager * Get image upload dir * * @param string $parentType Parent type ex FileManager::TYPE_PRODUCT - * @param string $fileType File type + * @param string $fileType File type ex : self::FILE_TYPE_DOCUMENTS * * @return string Uri */