From c09a26144f24548271e908efb4232baec079b92a Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Thu, 3 Sep 2020 11:39:31 +0530 Subject: [PATCH] Cover changes with Integration test --- .../Cms/Model/Wysiwyg/Images/StorageTest.php | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php b/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php index a68a546c20bc6..7baf52780e03c 100644 --- a/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php +++ b/dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php @@ -7,6 +7,10 @@ namespace Magento\Cms\Model\Wysiwyg\Images; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Driver\File; +use Magento\Framework\Filesystem\DriverInterface; +use Magento\TestFramework\Helper\Bootstrap; /** * Test methods of class Storage @@ -29,22 +33,27 @@ class StorageTest extends \PHPUnit\Framework\TestCase private $objectManager; /** - * @var \Magento\Framework\Filesystem + * @var Filesystem */ private $filesystem; /** - * @var \Magento\Cms\Model\Wysiwyg\Images\Storage + * @var Storage */ private $storage; + /** + * @var DriverInterface + */ + private $driver; + /** * @inheritdoc */ // phpcs:disable public static function setUpBeforeClass(): void { - self::$_baseDir = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + self::$_baseDir = Bootstrap::getObjectManager()->get( \Magento\Cms\Helper\Wysiwyg\Images::class )->getCurrentPath() . 'MagentoCmsModelWysiwygImagesStorageTest'; if (!file_exists(self::$_baseDir)) { @@ -60,8 +69,8 @@ public static function setUpBeforeClass(): void // phpcs:ignore public static function tearDownAfterClass(): void { - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Framework\Filesystem\Driver\File::class + Bootstrap::getObjectManager()->create( + File::class )->deleteDirectory( self::$_baseDir ); @@ -72,9 +81,10 @@ public static function tearDownAfterClass(): void */ protected function setUp(): void { - $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class); - $this->storage = $this->objectManager->create(\Magento\Cms\Model\Wysiwyg\Images\Storage::class); + $this->objectManager = Bootstrap::getObjectManager(); + $this->filesystem = $this->objectManager->get(Filesystem::class); + $this->storage = $this->objectManager->create(Storage::class); + $this->driver = Bootstrap::getObjectManager()->get(DriverInterface::class); } /** @@ -83,17 +93,29 @@ protected function setUp(): void */ public function testGetFilesCollection(): void { - \Magento\TestFramework\Helper\Bootstrap::getInstance() + Bootstrap::getInstance() ->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE); + $fileName = 'magento_image.jpg'; + $imagePath = realpath(__DIR__ . '/../../../../Catalog/_files/' . $fileName); + $mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); + $modifiableFilePath = $mediaDirectory->getAbsolutePath($fileName); + $this->driver->copy( + $imagePath, + $modifiableFilePath + ); $collection = $this->storage->getFilesCollection(self::$_baseDir, 'media'); $this->assertInstanceOf(\Magento\Cms\Model\Wysiwyg\Images\Storage\Collection::class, $collection); foreach ($collection as $item) { $this->assertInstanceOf(\Magento\Framework\DataObject::class, $item); - $this->assertStringEndsWith('/1.swf', $item->getUrl()); + $this->assertStringEndsWith('/' . $fileName, $item->getUrl()); $this->assertStringMatchesFormat( - 'http://%s/static/%s/adminhtml/%s/%s/Magento_Cms/images/placeholder_thumbnail.jpg', + 'http://%s/static/%s/adminhtml/%s/%s/Magento_Cms/images/magento_image.jpg', $item->getThumbUrl() ); + $this->assertEquals( + 'jpg', + $item->getMimeType() + ); return; } } @@ -121,7 +143,7 @@ public function testDeleteDirectory(): void $this->storage->createDirectory($dir, $path); $this->assertFileExists($fullPath); $this->storage->deleteDirectory($fullPath); - $this->assertFileNotExists($fullPath); + $this->assertFileDoesNotExist($fullPath); } /** @@ -142,7 +164,7 @@ public function testDeleteDirectoryWithExcludedDirPath(): void public function testUploadFile(): void { $fileName = 'magento_small_image.jpg'; - $tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP); + $tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); $filePath = $tmpDirectory->getAbsolutePath($fileName); // phpcs:disable $fixtureDir = realpath(__DIR__ . '/../../../../Catalog/_files'); @@ -172,7 +194,7 @@ public function testUploadFileWithExcludedDirPath(): void ); $fileName = 'magento_small_image.jpg'; - $tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP); + $tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); $filePath = $tmpDirectory->getAbsolutePath($fileName); // phpcs:disable $fixtureDir = realpath(__DIR__ . '/../../../../Catalog/_files'); @@ -204,7 +226,7 @@ public function testUploadFileWithWrongExtension(string $fileName, string $fileT $this->expectException(\Magento\Framework\Exception\LocalizedException::class); $this->expectExceptionMessage('File validation failed.'); - $tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP); + $tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); $filePath = $tmpDirectory->getAbsolutePath($fileName); // phpcs:disable $fixtureDir = realpath(__DIR__ . '/../../../_files'); @@ -251,7 +273,7 @@ public function testUploadFileWithWrongFile(): void $this->expectExceptionMessage('File validation failed.'); $fileName = 'file.gif'; - $tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP); + $tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); $filePath = $tmpDirectory->getAbsolutePath($fileName); // phpcs:disable $file = fopen($filePath, "wb");