3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
- namespace Magento \PageBuilder \Test \Unit \Controller \Adminhtml \ContentType \Image ;
6
+
7
+ declare (strict_types=1 );
8
+
9
+ namespace Magento \PageBuilder \Controller \Adminhtml \ContentType \Image ;
7
10
8
11
use Magento \Framework \File \Mime ;
9
12
use Magento \PageBuilder \Controller \Adminhtml \ContentType \Image \Upload as Controller ;
14
17
class UploadTest extends \PHPUnit \Framework \TestCase
15
18
{
16
19
/**
17
- * Subject under test
18
20
* @var \Magento\PageBuilder\Controller\Adminhtml\ContentType\Image\Upload
19
21
*/
20
22
private $ controller ;
21
23
22
24
/**
23
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
25
+ * @var \Magento\Framework\ObjectManagerInterface
24
26
*/
25
27
private $ objectManager ;
26
28
@@ -39,9 +41,12 @@ class UploadTest extends \PHPUnit\Framework\TestCase
39
41
*/
40
42
private $ resultJsonFactory ;
41
43
44
+ /**
45
+ * @inheritdoc
46
+ */
42
47
protected function setUp ()
43
48
{
44
- $ this ->objectManager = new \Magento \Framework \ TestFramework \Unit \ Helper \ObjectManager ( $ this );
49
+ $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap:: getObjectManager ( );
45
50
46
51
$ this ->uploaderFactory = $ this ->createPartialMock (\Magento \Framework \File \UploaderFactory::class, ['create ' ]);
47
52
@@ -57,15 +62,26 @@ protected function setUp()
57
62
58
63
$ this ->resultJsonFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->resultJson );
59
64
60
- $ this ->controller = $ this ->objectManager ->getObject (Controller::class, [
65
+ $ this ->controller = $ this ->objectManager ->create (Controller::class, [
61
66
'resultJsonFactory ' => $ this ->resultJsonFactory ,
62
67
'uploaderFactory ' => $ this ->uploaderFactory
63
68
]);
64
69
}
65
70
71
+ /**
72
+ * @inheritdoc
73
+ */
74
+ protected function tearDown ()
75
+ {
76
+ $ _FILES = [];
77
+ }
78
+
79
+ /**
80
+ * Assert that file validation passes when uploaded file has correct extension and valid mime type
81
+ */
66
82
public function testFileValidationPassesWhenFileHasCorrectExtensionAndValidMimeType ()
67
83
{
68
- $ valid_file_pathname = realpath (dirname (__FILE__ ) . '/../../../../_files/a.png ' );
84
+ $ valid_file_pathname = realpath (dirname (__FILE__ ) . '/../../../../_files/uploader/ a.png ' );
69
85
70
86
$ _FILES = [
71
87
'background_image ' => [
@@ -77,9 +93,9 @@ public function testFileValidationPassesWhenFileHasCorrectExtensionAndValidMimeT
77
93
]
78
94
];
79
95
80
- $ uploader = $ this ->objectManager ->getObject (\Magento \Framework \File \Uploader::class, [
96
+ $ uploader = $ this ->objectManager ->create (\Magento \Framework \File \Uploader::class, [
81
97
'fileId ' => 'background_image ' ,
82
- 'fileMime ' => $ this ->objectManager ->getObject (Mime::class),
98
+ 'fileMime ' => $ this ->objectManager ->create (Mime::class),
83
99
]);
84
100
85
101
$ this ->uploaderFactory
@@ -97,9 +113,12 @@ public function testFileValidationPassesWhenFileHasCorrectExtensionAndValidMimeT
97
113
$ this ->controller ->execute ();
98
114
}
99
115
116
+ /**
117
+ * Assert that file validation fails when uploaded file has correct extension but invalid mime type
118
+ */
100
119
public function testFileValidationFailsWhenFileHasCorrectExtensionButInvalidMimeType ()
101
120
{
102
- $ invalid_file_pathname = realpath (dirname (__FILE__ ) . '/../../../../_files/not-a.png ' );
121
+ $ invalid_file_pathname = realpath (dirname (__FILE__ ) . '/../../../../_files/uploader/ not-a.png ' );
103
122
104
123
$ _FILES = [
105
124
'background_image ' => [
@@ -111,9 +130,9 @@ public function testFileValidationFailsWhenFileHasCorrectExtensionButInvalidMime
111
130
]
112
131
];
113
132
114
- $ uploader = $ this ->objectManager ->getObject (\Magento \Framework \File \Uploader::class, [
133
+ $ uploader = $ this ->objectManager ->create (\Magento \Framework \File \Uploader::class, [
115
134
'fileId ' => 'background_image ' ,
116
- 'fileMime ' => $ this ->objectManager ->getObject (Mime::class),
135
+ 'fileMime ' => $ this ->objectManager ->create (Mime::class),
117
136
]);
118
137
119
138
$ this ->uploaderFactory
0 commit comments