8
8
9
9
namespace Magento \Theme \Test \Unit \Model \Design \Backend ;
10
10
11
+ use Magento \Config \Model \Config \Backend \File \RequestData \RequestDataInterface ;
12
+ use Magento \Framework \App \Cache \TypeListInterface ;
13
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
14
+ use Magento \Framework \Data \Collection \AbstractDb ;
15
+ use Magento \Framework \Filesystem ;
16
+ use Magento \Framework \Filesystem \Io \File ;
17
+ use Magento \Framework \Model \Context ;
18
+ use Magento \Framework \Model \ResourceModel \AbstractResource ;
19
+ use Magento \Framework \Registry ;
20
+ use Magento \Framework \UrlInterface ;
21
+ use Magento \MediaStorage \Helper \File \Storage \Database ;
22
+ use Magento \MediaStorage \Model \File \UploaderFactory ;
11
23
use Magento \Theme \Model \Design \Backend \Image ;
12
24
use PHPUnit_Framework_MockObject_MockObject ;
13
25
@@ -19,25 +31,26 @@ class ImageTest extends \PHPUnit\Framework\TestCase
19
31
/** @var Image */
20
32
private $ imageBackend ;
21
33
34
+ /** @var File */
35
+ private $ ioFileSystem ;
36
+
22
37
/**
23
38
* @inheritdoc
24
39
*/
25
40
public function setUp ()
26
41
{
27
- $ context = $ this ->getMockObject (\Magento \Framework \Model \Context::class);
28
- $ registry = $ this ->getMockObject (\Magento \Framework \Registry::class);
29
- $ config = $ this ->getMockObject (\Magento \Framework \App \Config \ScopeConfigInterface::class);
30
- $ cacheTypeList = $ this ->getMockObject (\Magento \Framework \App \Cache \TypeListInterface::class);
31
- $ uploaderFactory = $ this ->getMockObject (\Magento \MediaStorage \Model \File \UploaderFactory::class);
32
- $ requestData = $ this ->getMockObject (
33
- \Magento \Config \Model \Config \Backend \File \RequestData \RequestDataInterface::class
34
- );
35
- $ filesystem = $ this ->getMockObject (\Magento \Framework \Filesystem::class);
36
- $ urlBuilder = $ this ->getMockObject (\Magento \Framework \UrlInterface::class);
37
- $ databaseHelper = $ this ->getMockObject (\Magento \MediaStorage \Helper \File \Storage \Database::class);
38
- $ abstractResource = $ this ->getMockObject (\Magento \Framework \Model \ResourceModel \AbstractResource::class);
39
- $ abstractDb = $ this ->getMockObject (\Magento \Framework \Data \Collection \AbstractDb::class);
40
- $ ioFileSystem = $ this ->getMockObject (\Magento \Framework \Filesystem \Io \File::class);
42
+ $ context = $ this ->getMockObject (Context::class);
43
+ $ registry = $ this ->getMockObject (Registry::class);
44
+ $ config = $ this ->getMockObject (ScopeConfigInterface::class);
45
+ $ cacheTypeList = $ this ->getMockObject (TypeListInterface::class);
46
+ $ uploaderFactory = $ this ->getMockObject (UploaderFactory::class);
47
+ $ requestData = $ this ->getMockObject (RequestDataInterface::class);
48
+ $ filesystem = $ this ->getMockObject (Filesystem::class);
49
+ $ urlBuilder = $ this ->getMockObject (UrlInterface::class);
50
+ $ databaseHelper = $ this ->getMockObject (Database::class);
51
+ $ abstractResource = $ this ->getMockObject (AbstractResource::class);
52
+ $ abstractDb = $ this ->getMockObject (AbstractDb::class);
53
+ $ this ->ioFileSystem = $ this ->getMockObject (File::class);
41
54
$ this ->imageBackend = new Image (
42
55
$ context ,
43
56
$ registry ,
@@ -51,7 +64,7 @@ public function setUp()
51
64
$ abstractDb ,
52
65
[],
53
66
$ databaseHelper ,
54
- $ ioFileSystem
67
+ $ this -> ioFileSystem
55
68
);
56
69
}
57
70
@@ -86,15 +99,24 @@ private function getMockObject(string $class, array $methods = []): PHPUnit_Fram
86
99
*/
87
100
public function testBeforeSaveWithInvalidExtensionFile ()
88
101
{
102
+ $ invalidFileName = 'fileName.invalidExtension ' ;
89
103
$ this ->imageBackend ->setData (
90
104
[
91
105
'value ' => [
92
106
[
93
- 'file ' => ' fileName.invalidExtension ' ,
107
+ 'file ' => $ invalidFileName ,
94
108
]
95
109
],
96
110
]
97
111
);
112
+ $ expectedPathInfo = [
113
+ 'extension ' => 'invalidExtension '
114
+ ];
115
+ $ this ->ioFileSystem
116
+ ->expects ($ this ->any ())
117
+ ->method ('getPathInfo ' )
118
+ ->with ($ invalidFileName )
119
+ ->willReturn ($ expectedPathInfo );
98
120
$ this ->imageBackend ->beforeSave ();
99
121
}
100
122
}
0 commit comments