10
10
use Magento \CatalogImportExport \Model \Import \Product \Validator \Media ;
11
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
12
12
use Magento \ImportExport \Model \Import ;
13
+ use Magento \Framework \Url \Validator ;
14
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
13
15
14
16
class MediaTest extends \PHPUnit_Framework_TestCase
15
17
{
@@ -19,14 +21,22 @@ class MediaTest extends \PHPUnit_Framework_TestCase
19
21
/** @var ObjectManagerHelper */
20
22
protected $ objectManagerHelper ;
21
23
24
+ /**
25
+ * @var Validator|MockObject
26
+ */
27
+ private $ validatorMock ;
28
+
22
29
protected function setUp ()
23
30
{
24
-
31
+ $ this ->validatorMock = $ this ->getMockBuilder (Validator::class)
32
+ ->disableOriginalConstructor ()
33
+ ->getMock ();
34
+
25
35
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
26
36
$ this ->media = $ this ->objectManagerHelper ->getObject (
27
37
Media::class,
28
38
[
29
-
39
+ ' validator ' => $ this -> validatorMock
30
40
]
31
41
);
32
42
}
@@ -40,10 +50,15 @@ public function testInit()
40
50
/**
41
51
* @param array $data
42
52
* @param array $expected
53
+ * @param \Closure|null $validatorCallback
43
54
* @dataProvider isMediaValidDataProvider
44
55
*/
45
- public function testIsValid ($ data , $ expected )
56
+ public function testIsValid ($ data , $ expected, \ Closure $ validatorCallback = null )
46
57
{
58
+ if ($ validatorCallback !== null ) {
59
+ $ validatorCallback ($ this ->validatorMock );
60
+ }
61
+
47
62
$ contextMock = $ this ->getMockBuilder (Product::class)
48
63
->disableOriginalConstructor ()
49
64
->getMock ();
@@ -101,7 +116,27 @@ public function isMediaValidDataProvider()
101
116
'additional_images_fail ' => [
102
117
['additional_images ' => 'image1.png|image2.jpg|image3.gif ' ],
103
118
['result ' => false , 'messages ' => [0 => 'additional_images ' ]]
104
- ]
119
+ ],
120
+ 'additional_images_wrong_domain ' => [
121
+ ['additional_images ' => 'https://example/images/some-name.jpg ' ],
122
+ ['result ' => false , 'messages ' => [0 => 'additional_images ' ]],
123
+ function ($ validatorMock ) {
124
+ $ validatorMock ->expects ($ this ->once ())
125
+ ->method ('isValid ' )
126
+ ->with ('https://example/images/some-name.jpg ' )
127
+ ->willReturn (false );
128
+ }
129
+ ],
130
+ 'additional_images_url_multiple_underscores ' => [
131
+ ['additional_images ' => 'https://example.com/images/some-name__with___multiple____underscores.jpg ' ],
132
+ ['result ' => true , 'messages ' => []],
133
+ function ($ validatorMock ) {
134
+ $ validatorMock ->expects ($ this ->once ())
135
+ ->method ('isValid ' )
136
+ ->with ('https://example.com/images/some-name__with___multiple____underscores.jpg ' )
137
+ ->willReturn (true );
138
+ }
139
+ ],
105
140
];
106
141
}
107
142
}
0 commit comments