6
6
*/
7
7
namespace Magento \Cms \Model \Wysiwyg \Images ;
8
8
9
+ use Magento \Cms \Model \Wysiwyg \Images \Storage \Collection ;
9
10
use 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 ;
10
16
11
17
/**
12
18
* Test methods of class Storage
@@ -29,22 +35,27 @@ class StorageTest extends \PHPUnit\Framework\TestCase
29
35
private $ objectManager ;
30
36
31
37
/**
32
- * @var \Magento\Framework\ Filesystem
38
+ * @var Filesystem
33
39
*/
34
40
private $ filesystem ;
35
41
36
42
/**
37
- * @var \Magento\Cms\Model\Wysiwyg\Images\ Storage
43
+ * @var Storage
38
44
*/
39
45
private $ storage ;
40
46
47
+ /**
48
+ * @var DriverInterface
49
+ */
50
+ private $ driver ;
51
+
41
52
/**
42
53
* @inheritdoc
43
54
*/
44
55
// phpcs:disable
45
56
public static function setUpBeforeClass (): void
46
57
{
47
- self ::$ _baseDir = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
58
+ self ::$ _baseDir = Bootstrap::getObjectManager ()->get (
48
59
\Magento \Cms \Helper \Wysiwyg \Images::class
49
60
)->getCurrentPath () . 'MagentoCmsModelWysiwygImagesStorageTest ' ;
50
61
if (!file_exists (self ::$ _baseDir )) {
@@ -60,8 +71,8 @@ public static function setUpBeforeClass(): void
60
71
// phpcs:ignore
61
72
public static function tearDownAfterClass (): void
62
73
{
63
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
64
- \ Magento \ Framework \ Filesystem \ Driver \ File::class
74
+ Bootstrap::getObjectManager ()->create (
75
+ File::class
65
76
)->deleteDirectory (
66
77
self ::$ _baseDir
67
78
);
@@ -72,9 +83,10 @@ public static function tearDownAfterClass(): void
72
83
*/
73
84
protected function setUp (): void
74
85
{
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);
78
90
}
79
91
80
92
/**
@@ -83,16 +95,31 @@ protected function setUp(): void
83
95
*/
84
96
public function testGetFilesCollection (): void
85
97
{
86
- \ Magento \ TestFramework \ Helper \ Bootstrap::getInstance ()
98
+ Bootstrap::getInstance ()
87
99
->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 );
90
111
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 "
96
123
);
97
124
return ;
98
125
}
@@ -121,7 +148,7 @@ public function testDeleteDirectory(): void
121
148
$ this ->storage ->createDirectory ($ dir , $ path );
122
149
$ this ->assertFileExists ($ fullPath );
123
150
$ this ->storage ->deleteDirectory ($ fullPath );
124
- $ this ->assertFileNotExists ($ fullPath );
151
+ $ this ->assertFileDoesNotExist ($ fullPath );
125
152
}
126
153
127
154
/**
@@ -142,7 +169,7 @@ public function testDeleteDirectoryWithExcludedDirPath(): void
142
169
public function testUploadFile (): void
143
170
{
144
171
$ 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 );
146
173
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
147
174
// phpcs:disable
148
175
$ fixtureDir = realpath (__DIR__ . '/../../../../Catalog/_files ' );
@@ -172,7 +199,7 @@ public function testUploadFileWithExcludedDirPath(): void
172
199
);
173
200
174
201
$ 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 );
176
203
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
177
204
// phpcs:disable
178
205
$ fixtureDir = realpath (__DIR__ . '/../../../../Catalog/_files ' );
@@ -204,7 +231,7 @@ public function testUploadFileWithWrongExtension(string $fileName, string $fileT
204
231
$ this ->expectException (\Magento \Framework \Exception \LocalizedException::class);
205
232
$ this ->expectExceptionMessage ('File validation failed. ' );
206
233
207
- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
234
+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
208
235
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
209
236
// phpcs:disable
210
237
$ fixtureDir = realpath (__DIR__ . '/../../../_files ' );
@@ -251,7 +278,7 @@ public function testUploadFileWithWrongFile(): void
251
278
$ this ->expectExceptionMessage ('File validation failed. ' );
252
279
253
280
$ fileName = 'file.gif ' ;
254
- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
281
+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
255
282
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
256
283
// phpcs:disable
257
284
$ file = fopen ($ filePath , "wb " );
0 commit comments