5
5
*/
6
6
namespace Magento \Framework \Image \Adapter ;
7
7
8
+ use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
10
+
8
11
/**
12
+ * @magentoDataFixture Magento/Framework/Image/_files/image_fixture.php
9
13
* @magentoAppIsolation enabled
10
14
*/
11
15
class InterfaceTest extends \PHPUnit \Framework \TestCase
@@ -20,6 +24,19 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase
20
24
\Magento \Framework \Image \Adapter \AdapterInterface::ADAPTER_IM ,
21
25
];
22
26
27
+ /**
28
+ * @var \Magento\Framework\ObjectManagerInterface
29
+ */
30
+ private $ objectManager ;
31
+
32
+ /**
33
+ * @inheritdoc
34
+ */
35
+ protected function setUp (): void
36
+ {
37
+ $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
38
+ }
39
+
23
40
/**
24
41
* Add adapters to each data provider case
25
42
*
@@ -79,14 +96,14 @@ protected function _compareColors($colorBefore, $colorAfter)
79
96
*/
80
97
protected function _getFixture ($ pattern )
81
98
{
82
- $ dir = dirname (__DIR__ ) . '/_files/ ' ;
83
- $ data = glob ($ dir . $ pattern );
84
-
85
- if (!empty ($ data )) {
86
- return $ data [0 ];
99
+ if (!$ pattern ) {
100
+ return null ;
87
101
}
88
-
89
- return null ;
102
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
103
+ /** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
104
+ $ rootDirectory = $ objectManager ->get (\Magento \Framework \Filesystem \Directory \TargetDirectory::class)
105
+ ->getDirectoryWrite (DirectoryList::TMP );
106
+ return $ rootDirectory ->getAbsolutePath ('image/test/ ' . $ pattern );
90
107
}
91
108
92
109
/**
@@ -114,8 +131,7 @@ protected function _getAdapter($adapterType)
114
131
{
115
132
$ adapter = null ;
116
133
try {
117
- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
118
- $ adapter = $ objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ($ adapterType );
134
+ $ adapter = $ this ->objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ($ adapterType );
119
135
} catch (\Exception $ e ) {
120
136
$ this ->markTestSkipped ($ e ->getMessage ());
121
137
}
@@ -206,29 +222,36 @@ public function testImageSize($image, $adapterType)
206
222
207
223
/**
208
224
* @param string $image
209
- * @param array $tempPath (dirName, newName)
225
+ * @param array $tmpDir (dirName, newName)
210
226
* @param string $adapterType
211
227
*
228
+ * @throws \Magento\Framework\Exception\FileSystemException
229
+ *
212
230
* @dataProvider saveDataProvider
213
231
* @depends testOpen
214
232
*/
215
- public function testSave ($ image , $ tempPath , $ adapterType )
233
+ public function testSave ($ image , $ tmpDir , $ adapterType )
216
234
{
217
235
$ adapter = $ this ->_getAdapter ($ adapterType );
218
236
$ adapter ->open ($ image );
219
- try {
220
- call_user_func_array ([$ adapter , 'save ' ], $ tempPath );
221
- $ tempPath = join ('' , $ tempPath );
222
- $ this ->assertFileExists ($ tempPath );
223
- unlink ($ tempPath );
224
- } catch (\Exception $ e ) {
225
- $ this ->assertFalse (is_dir ($ tempPath [0 ]) && is_writable ($ tempPath [0 ]));
226
- }
237
+
238
+ /** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
239
+ $ rootDirectory = $ this ->objectManager ->get (\Magento \Framework \Filesystem \Directory \TargetDirectory::class)
240
+ ->getDirectoryWrite (DirectoryList::TMP );
241
+
242
+ call_user_func_array ([$ adapter , 'save ' ], $ tmpDir );
243
+ $ tmpDir = join ('' , $ tmpDir );
244
+ $ this ->assertTrue ($ rootDirectory ->isExist ($ tmpDir ));
245
+ $ rootDirectory ->delete ($ tmpDir );
227
246
}
228
247
229
248
public function saveDataProvider ()
230
249
{
231
- $ dir = \Magento \TestFramework \Helper \Bootstrap::getInstance ()->getAppTempDir () . '/ ' ;
250
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
251
+ /** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
252
+ $ rootDirectory = $ objectManager ->get (\Magento \Framework \Filesystem \Directory \TargetDirectory::class)
253
+ ->getDirectoryWrite (DirectoryList::TMP );
254
+ $ dir = $ rootDirectory ->getAbsolutePath ('image/ ' );
232
255
return $ this ->_prepareData (
233
256
[
234
257
[$ this ->_getFixture ('image_adapters_test.png ' ), [$ dir . uniqid ('test_image_adapter ' )]],
@@ -640,9 +663,7 @@ public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expe
640
663
$ adapter = $ this ->_getAdapter ($ adapterType );
641
664
642
665
/** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */
643
- $ readFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
644
- \Magento \Framework \Filesystem \Directory \ReadFactory::class
645
- );
666
+ $ readFactory = $ this ->objectManager ->get (\Magento \Framework \Filesystem \Directory \ReadFactory::class);
646
667
$ reader = $ readFactory ->create (BP );
647
668
$ path = $ reader ->getAbsolutePath ('lib/internal/LinLibertineFont/LinLibertine_Re-4.4.1.ttf ' );
648
669
$ adapter ->createPngFromString ('T ' , $ path );
@@ -698,8 +719,7 @@ public function createPngFromStringDataProvider()
698
719
699
720
public function testValidateUploadFile ()
700
721
{
701
- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
702
- $ imageAdapter = $ objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
722
+ $ imageAdapter = $ this ->objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
703
723
$ this ->assertTrue ($ imageAdapter ->validateUploadFile ($ this ->_getFixture ('magento_thumbnail.jpg ' )));
704
724
}
705
725
@@ -713,8 +733,7 @@ public function testValidateUploadFileException($fileName, $expectedErrorMsg, $u
713
733
{
714
734
$ this ->expectException (\InvalidArgumentException::class);
715
735
716
- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
717
- $ imageAdapter = $ objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
736
+ $ imageAdapter = $ this ->objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
718
737
$ filePath = $ useFixture ? $ this ->_getFixture ($ fileName ) : $ fileName ;
719
738
720
739
try {
0 commit comments