7
7
namespace Magento \Cms \Model \Wysiwyg \Images ;
8
8
9
9
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 ;
10
14
11
15
/**
12
16
* Test methods of class Storage
@@ -29,22 +33,27 @@ class StorageTest extends \PHPUnit\Framework\TestCase
29
33
private $ objectManager ;
30
34
31
35
/**
32
- * @var \Magento\Framework\ Filesystem
36
+ * @var Filesystem
33
37
*/
34
38
private $ filesystem ;
35
39
36
40
/**
37
- * @var \Magento\Cms\Model\Wysiwyg\Images\ Storage
41
+ * @var Storage
38
42
*/
39
43
private $ storage ;
40
44
45
+ /**
46
+ * @var DriverInterface
47
+ */
48
+ private $ driver ;
49
+
41
50
/**
42
51
* @inheritdoc
43
52
*/
44
53
// phpcs:disable
45
54
public static function setUpBeforeClass (): void
46
55
{
47
- self ::$ _baseDir = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
56
+ self ::$ _baseDir = Bootstrap::getObjectManager ()->get (
48
57
\Magento \Cms \Helper \Wysiwyg \Images::class
49
58
)->getCurrentPath () . 'MagentoCmsModelWysiwygImagesStorageTest ' ;
50
59
if (!file_exists (self ::$ _baseDir )) {
@@ -60,8 +69,8 @@ public static function setUpBeforeClass(): void
60
69
// phpcs:ignore
61
70
public static function tearDownAfterClass (): void
62
71
{
63
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
64
- \ Magento \ Framework \ Filesystem \ Driver \ File::class
72
+ Bootstrap::getObjectManager ()->create (
73
+ File::class
65
74
)->deleteDirectory (
66
75
self ::$ _baseDir
67
76
);
@@ -72,9 +81,10 @@ public static function tearDownAfterClass(): void
72
81
*/
73
82
protected function setUp (): void
74
83
{
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);
78
88
}
79
89
80
90
/**
@@ -83,17 +93,29 @@ protected function setUp(): void
83
93
*/
84
94
public function testGetFilesCollection (): void
85
95
{
86
- \ Magento \ TestFramework \ Helper \ Bootstrap::getInstance ()
96
+ Bootstrap::getInstance ()
87
97
->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
+ );
88
106
$ collection = $ this ->storage ->getFilesCollection (self ::$ _baseDir , 'media ' );
89
107
$ this ->assertInstanceOf (\Magento \Cms \Model \Wysiwyg \Images \Storage \Collection::class, $ collection );
90
108
foreach ($ collection as $ item ) {
91
109
$ this ->assertInstanceOf (\Magento \Framework \DataObject::class, $ item );
92
- $ this ->assertStringEndsWith ('/1.swf ' , $ item ->getUrl ());
110
+ $ this ->assertStringEndsWith ('/ ' . $ fileName , $ item ->getUrl ());
93
111
$ 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 ' ,
95
113
$ item ->getThumbUrl ()
96
114
);
115
+ $ this ->assertEquals (
116
+ 'jpg ' ,
117
+ $ item ->getMimeType ()
118
+ );
97
119
return ;
98
120
}
99
121
}
@@ -121,7 +143,7 @@ public function testDeleteDirectory(): void
121
143
$ this ->storage ->createDirectory ($ dir , $ path );
122
144
$ this ->assertFileExists ($ fullPath );
123
145
$ this ->storage ->deleteDirectory ($ fullPath );
124
- $ this ->assertFileNotExists ($ fullPath );
146
+ $ this ->assertFileDoesNotExist ($ fullPath );
125
147
}
126
148
127
149
/**
@@ -142,7 +164,7 @@ public function testDeleteDirectoryWithExcludedDirPath(): void
142
164
public function testUploadFile (): void
143
165
{
144
166
$ 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 );
146
168
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
147
169
// phpcs:disable
148
170
$ fixtureDir = realpath (__DIR__ . '/../../../../Catalog/_files ' );
@@ -172,7 +194,7 @@ public function testUploadFileWithExcludedDirPath(): void
172
194
);
173
195
174
196
$ 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 );
176
198
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
177
199
// phpcs:disable
178
200
$ fixtureDir = realpath (__DIR__ . '/../../../../Catalog/_files ' );
@@ -204,7 +226,7 @@ public function testUploadFileWithWrongExtension(string $fileName, string $fileT
204
226
$ this ->expectException (\Magento \Framework \Exception \LocalizedException::class);
205
227
$ this ->expectExceptionMessage ('File validation failed. ' );
206
228
207
- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
229
+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
208
230
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
209
231
// phpcs:disable
210
232
$ fixtureDir = realpath (__DIR__ . '/../../../_files ' );
@@ -251,7 +273,7 @@ public function testUploadFileWithWrongFile(): void
251
273
$ this ->expectExceptionMessage ('File validation failed. ' );
252
274
253
275
$ fileName = 'file.gif ' ;
254
- $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (\ Magento \ Framework \ App \ Filesystem \ DirectoryList::SYS_TMP );
276
+ $ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::SYS_TMP );
255
277
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
256
278
// phpcs:disable
257
279
$ file = fopen ($ filePath , "wb " );
0 commit comments