Skip to content

Commit c09a261

Browse files
Cover changes with Integration test
1 parent d312ab5 commit c09a261

File tree

1 file changed

+38
-16
lines changed
  • dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images

1 file changed

+38
-16
lines changed

dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
namespace Magento\Cms\Model\Wysiwyg\Images;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem;
11+
use Magento\Framework\Filesystem\Driver\File;
12+
use Magento\Framework\Filesystem\DriverInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
1014

1115
/**
1216
* Test methods of class Storage
@@ -29,22 +33,27 @@ class StorageTest extends \PHPUnit\Framework\TestCase
2933
private $objectManager;
3034

3135
/**
32-
* @var \Magento\Framework\Filesystem
36+
* @var Filesystem
3337
*/
3438
private $filesystem;
3539

3640
/**
37-
* @var \Magento\Cms\Model\Wysiwyg\Images\Storage
41+
* @var Storage
3842
*/
3943
private $storage;
4044

45+
/**
46+
* @var DriverInterface
47+
*/
48+
private $driver;
49+
4150
/**
4251
* @inheritdoc
4352
*/
4453
// phpcs:disable
4554
public static function setUpBeforeClass(): void
4655
{
47-
self::$_baseDir = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
56+
self::$_baseDir = Bootstrap::getObjectManager()->get(
4857
\Magento\Cms\Helper\Wysiwyg\Images::class
4958
)->getCurrentPath() . 'MagentoCmsModelWysiwygImagesStorageTest';
5059
if (!file_exists(self::$_baseDir)) {
@@ -60,8 +69,8 @@ public static function setUpBeforeClass(): void
6069
// phpcs:ignore
6170
public static function tearDownAfterClass(): void
6271
{
63-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
64-
\Magento\Framework\Filesystem\Driver\File::class
72+
Bootstrap::getObjectManager()->create(
73+
File::class
6574
)->deleteDirectory(
6675
self::$_baseDir
6776
);
@@ -72,9 +81,10 @@ public static function tearDownAfterClass(): void
7281
*/
7382
protected function setUp(): void
7483
{
75-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
76-
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
77-
$this->storage = $this->objectManager->create(\Magento\Cms\Model\Wysiwyg\Images\Storage::class);
84+
$this->objectManager = Bootstrap::getObjectManager();
85+
$this->filesystem = $this->objectManager->get(Filesystem::class);
86+
$this->storage = $this->objectManager->create(Storage::class);
87+
$this->driver = Bootstrap::getObjectManager()->get(DriverInterface::class);
7888
}
7989

8090
/**
@@ -83,17 +93,29 @@ protected function setUp(): void
8393
*/
8494
public function testGetFilesCollection(): void
8595
{
86-
\Magento\TestFramework\Helper\Bootstrap::getInstance()
96+
Bootstrap::getInstance()
8797
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
98+
$fileName = 'magento_image.jpg';
99+
$imagePath = realpath(__DIR__ . '/../../../../Catalog/_files/' . $fileName);
100+
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
101+
$modifiableFilePath = $mediaDirectory->getAbsolutePath($fileName);
102+
$this->driver->copy(
103+
$imagePath,
104+
$modifiableFilePath
105+
);
88106
$collection = $this->storage->getFilesCollection(self::$_baseDir, 'media');
89107
$this->assertInstanceOf(\Magento\Cms\Model\Wysiwyg\Images\Storage\Collection::class, $collection);
90108
foreach ($collection as $item) {
91109
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $item);
92-
$this->assertStringEndsWith('/1.swf', $item->getUrl());
110+
$this->assertStringEndsWith('/' . $fileName, $item->getUrl());
93111
$this->assertStringMatchesFormat(
94-
'http://%s/static/%s/adminhtml/%s/%s/Magento_Cms/images/placeholder_thumbnail.jpg',
112+
'http://%s/static/%s/adminhtml/%s/%s/Magento_Cms/images/magento_image.jpg',
95113
$item->getThumbUrl()
96114
);
115+
$this->assertEquals(
116+
'jpg',
117+
$item->getMimeType()
118+
);
97119
return;
98120
}
99121
}
@@ -121,7 +143,7 @@ public function testDeleteDirectory(): void
121143
$this->storage->createDirectory($dir, $path);
122144
$this->assertFileExists($fullPath);
123145
$this->storage->deleteDirectory($fullPath);
124-
$this->assertFileNotExists($fullPath);
146+
$this->assertFileDoesNotExist($fullPath);
125147
}
126148

127149
/**
@@ -142,7 +164,7 @@ public function testDeleteDirectoryWithExcludedDirPath(): void
142164
public function testUploadFile(): void
143165
{
144166
$fileName = 'magento_small_image.jpg';
145-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
167+
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
146168
$filePath = $tmpDirectory->getAbsolutePath($fileName);
147169
// phpcs:disable
148170
$fixtureDir = realpath(__DIR__ . '/../../../../Catalog/_files');
@@ -172,7 +194,7 @@ public function testUploadFileWithExcludedDirPath(): void
172194
);
173195

174196
$fileName = 'magento_small_image.jpg';
175-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
197+
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
176198
$filePath = $tmpDirectory->getAbsolutePath($fileName);
177199
// phpcs:disable
178200
$fixtureDir = realpath(__DIR__ . '/../../../../Catalog/_files');
@@ -204,7 +226,7 @@ public function testUploadFileWithWrongExtension(string $fileName, string $fileT
204226
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
205227
$this->expectExceptionMessage('File validation failed.');
206228

207-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
229+
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
208230
$filePath = $tmpDirectory->getAbsolutePath($fileName);
209231
// phpcs:disable
210232
$fixtureDir = realpath(__DIR__ . '/../../../_files');
@@ -251,7 +273,7 @@ public function testUploadFileWithWrongFile(): void
251273
$this->expectExceptionMessage('File validation failed.');
252274

253275
$fileName = 'file.gif';
254-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
276+
$tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
255277
$filePath = $tmpDirectory->getAbsolutePath($fileName);
256278
// phpcs:disable
257279
$file = fopen($filePath, "wb");

0 commit comments

Comments
 (0)