66 */
77namespace Magento \Cms \Model \Wysiwyg \Images ;
88
9+ use Magento \Cms \Model \Wysiwyg \Images \Storage \Collection ;
910use Magento \Framework \App \Filesystem \DirectoryList ;
11+ use Magento \Framework \DataObject ;
12+ use Magento \Framework \Filesystem ;
13+ use Magento \Framework \Filesystem \Driver \File ;
14+ use Magento \Framework \Filesystem \DriverInterface ;
15+ use Magento \TestFramework \Helper \Bootstrap ;
1016
1117/**
1218 * Test methods of class Storage
@@ -29,22 +35,27 @@ class StorageTest extends \PHPUnit\Framework\TestCase
2935 private $ objectManager ;
3036
3137 /**
32- * @var \Magento\Framework\ Filesystem
38+ * @var Filesystem
3339 */
3440 private $ filesystem ;
3541
3642 /**
37- * @var \Magento\Cms\Model\Wysiwyg\Images\ Storage
43+ * @var Storage
3844 */
3945 private $ storage ;
4046
47+ /**
48+ * @var DriverInterface
49+ */
50+ private $ driver ;
51+
4152 /**
4253 * @inheritdoc
4354 */
4455 // phpcs:disable
4556 public static function setUpBeforeClass (): void
4657 {
47- self ::$ _baseDir = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
58+ self ::$ _baseDir = Bootstrap::getObjectManager ()->get (
4859 \Magento \Cms \Helper \Wysiwyg \Images::class
4960 )->getCurrentPath () . 'MagentoCmsModelWysiwygImagesStorageTest ' ;
5061 if (!file_exists (self ::$ _baseDir )) {
@@ -60,8 +71,8 @@ public static function setUpBeforeClass(): void
6071 // phpcs:ignore
6172 public static function tearDownAfterClass (): void
6273 {
63- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
64- \ Magento \ Framework \ Filesystem \ Driver \ File::class
74+ Bootstrap::getObjectManager ()->create (
75+ File::class
6576 )->deleteDirectory (
6677 self ::$ _baseDir
6778 );
@@ -72,9 +83,10 @@ public static function tearDownAfterClass(): void
7283 */
7384 protected function setUp (): void
7485 {
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);
86+ $ this ->objectManager = Bootstrap::getObjectManager ();
87+ $ this ->filesystem = $ this ->objectManager ->get (Filesystem::class);
88+ $ this ->storage = $ this ->objectManager ->create (Storage::class);
89+ $ this ->driver = Bootstrap::getObjectManager ()->get (DriverInterface::class);
7890 }
7991
8092 /**
@@ -83,16 +95,31 @@ protected function setUp(): void
8395 */
8496 public function testGetFilesCollection (): void
8597 {
86- \ Magento \ TestFramework \ Helper \ Bootstrap::getInstance ()
98+ Bootstrap::getInstance ()
8799 ->loadArea (\Magento \Backend \App \Area \FrontNameResolver::AREA_CODE );
88- $ collection = $ this ->storage ->getFilesCollection (self ::$ _baseDir , 'media ' );
89- $ this ->assertInstanceOf (\Magento \Cms \Model \Wysiwyg \Images \Storage \Collection::class, $ collection );
100+ $ fileName = 'magento_image.jpg ' ;
101+ $ imagePath = realpath (__DIR__ . '/../../../../Catalog/_files/ ' . $ fileName );
102+ $ mediaDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
103+ $ modifiableFilePath = $ mediaDirectory ->getAbsolutePath ('MagentoCmsModelWysiwygImagesStorageTest/ ' . $ fileName );
104+ $ this ->driver ->copy (
105+ $ imagePath ,
106+ $ modifiableFilePath
107+ );
108+ $ this ->storage ->resizeFile ($ modifiableFilePath );
109+ $ collection = $ this ->storage ->getFilesCollection (self ::$ _baseDir , 'image ' );
110+ $ this ->assertInstanceOf (Collection::class, $ collection );
90111 foreach ($ collection as $ item ) {
91- $ this ->assertInstanceOf (\Magento \Framework \DataObject::class, $ item );
92- $ this ->assertStringEndsWith ('/1.swf ' , $ item ->getUrl ());
93- $ this ->assertStringMatchesFormat (
94- 'http://%s/static/%s/adminhtml/%s/%s/Magento_Cms/images/placeholder_thumbnail.jpg ' ,
95- $ item ->getThumbUrl ()
112+ $ this ->assertInstanceOf (DataObject::class, $ item );
113+ $ this ->assertStringEndsWith ('/ ' . $ fileName , $ item ->getUrl ());
114+ $ this ->assertEquals (
115+ '/pub/media/.thumbsMagentoCmsModelWysiwygImagesStorageTest/magento_image.jpg ' ,
116+ parse_url ($ item ->getThumbUrl (), PHP_URL_PATH ),
117+ "Check if Thumbnail URL is equal to the generated URL "
118+ );
119+ $ this ->assertEquals (
120+ 'image/jpeg ' ,
121+ $ item ->getMimeType (),
122+ "Check if Mime Type is equal to the image in the file system "
96123 );
97124 return ;
98125 }
@@ -121,7 +148,7 @@ public function testDeleteDirectory(): void
121148 $ this ->storage ->createDirectory ($ dir , $ path );
122149 $ this ->assertFileExists ($ fullPath );
123150 $ this ->storage ->deleteDirectory ($ fullPath );
124- $ this ->assertFileNotExists ($ fullPath );
151+ $ this ->assertFileDoesNotExist ($ fullPath );
125152 }
126153
127154 /**
@@ -142,7 +169,7 @@ public function testDeleteDirectoryWithExcludedDirPath(): void
142169 public function testUploadFile (): void
143170 {
144171 $ fileName = 'magento_small_image.jpg ' ;
145- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
172+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
146173 $ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
147174 // phpcs:disable
148175 $ fixtureDir = realpath (__DIR__ . '/../../../../Catalog/_files ' );
@@ -172,7 +199,7 @@ public function testUploadFileWithExcludedDirPath(): void
172199 );
173200
174201 $ fileName = 'magento_small_image.jpg ' ;
175- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
202+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
176203 $ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
177204 // phpcs:disable
178205 $ fixtureDir = realpath (__DIR__ . '/../../../../Catalog/_files ' );
@@ -204,7 +231,7 @@ public function testUploadFileWithWrongExtension(string $fileName, string $fileT
204231 $ this ->expectException (\Magento \Framework \Exception \LocalizedException::class);
205232 $ this ->expectExceptionMessage ('File validation failed. ' );
206233
207- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
234+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
208235 $ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
209236 // phpcs:disable
210237 $ fixtureDir = realpath (__DIR__ . '/../../../_files ' );
@@ -251,7 +278,7 @@ public function testUploadFileWithWrongFile(): void
251278 $ this ->expectExceptionMessage ('File validation failed. ' );
252279
253280 $ fileName = 'file.gif ' ;
254- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
281+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
255282 $ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
256283 // phpcs:disable
257284 $ file = fopen ($ filePath , "wb " );
0 commit comments