3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Catalog \Test \Unit \Model \Product \Attribute \Frontend ;
7
8
9
+ use Magento \Catalog \Model \Product ;
10
+ use Magento \Catalog \Model \Product \Attribute \Frontend \Image ;
11
+ use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
8
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
+ use Magento \Store \Model \Store ;
14
+ use Magento \Store \Model \StoreManagerInterface ;
15
+ use PHPUnit \Framework \TestCase ;
9
16
10
- class ImageTest extends \ PHPUnit \ Framework \ TestCase
17
+ class ImageTest extends TestCase
11
18
{
12
19
/**
13
- * @var \Magento\Catalog\Model\Product\Attribute\Frontend\ Image
20
+ * @var Image
14
21
*/
15
22
private $ model ;
16
23
17
- public function testGetUrl ()
24
+ /**
25
+ * @dataProvider getUrlDataProvider
26
+ * @param string $expectedImage
27
+ * @param string $productImage
28
+ */
29
+ public function testGetUrl (string $ expectedImage , string $ productImage )
30
+ {
31
+ $ this ->assertEquals ($ expectedImage , $ this ->model ->getUrl ($ this ->getMockedProduct ($ productImage )));
32
+ }
33
+
34
+ /**
35
+ * Data provider for testGetUrl
36
+ *
37
+ * @return array
38
+ */
39
+ public function getUrlDataProvider (): array
18
40
{
19
- $ this ->assertEquals ('catalog/product/img.jpg ' , $ this ->model ->getUrl ($ this ->getMockedProduct ()));
41
+ return [
42
+ ['catalog/product/img.jpg ' , 'img.jpg ' ],
43
+ ['catalog/product/img.jpg ' , '/img.jpg ' ],
44
+ ];
20
45
}
21
46
22
47
protected function setUp ()
23
48
{
24
49
$ helper = new ObjectManager ($ this );
25
50
$ this ->model = $ helper ->getObject (
26
- \ Magento \ Catalog \ Model \ Product \ Attribute \ Frontend \ Image::class,
51
+ Image::class,
27
52
['storeManager ' => $ this ->getMockedStoreManager ()]
28
53
);
29
54
$ this ->model ->setAttribute ($ this ->getMockedAttribute ());
30
55
}
31
56
32
57
/**
33
- * @return \Magento\Catalog\Model\Product
58
+ * @param string $productImage
59
+ * @return Product
34
60
*/
35
- private function getMockedProduct ()
61
+ private function getMockedProduct (string $ productImage ): Product
36
62
{
37
- $ mockBuilder = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Product::class);
63
+ $ mockBuilder = $ this ->getMockBuilder (Product::class);
38
64
$ mock = $ mockBuilder ->setMethods (['getData ' , 'getStore ' , '__wakeup ' ])
39
65
->disableOriginalConstructor ()
40
66
->getMock ();
41
67
42
68
$ mock ->expects ($ this ->any ())
43
69
->method ('getData ' )
44
- ->will ($ this ->returnValue (' img.jpg ' ));
70
+ ->will ($ this ->returnValue ($ productImage ));
45
71
46
72
$ mock ->expects ($ this ->any ())
47
73
->method ('getStore ' );
@@ -50,13 +76,13 @@ private function getMockedProduct()
50
76
}
51
77
52
78
/**
53
- * @return \Magento\Store\Model\ StoreManagerInterface
79
+ * @return StoreManagerInterface
54
80
*/
55
- private function getMockedStoreManager ()
81
+ private function getMockedStoreManager (): StoreManagerInterface
56
82
{
57
83
$ mockedStore = $ this ->getMockedStore ();
58
84
59
- $ mockBuilder = $ this ->getMockBuilder (\ Magento \ Store \ Model \ StoreManagerInterface::class);
85
+ $ mockBuilder = $ this ->getMockBuilder (StoreManagerInterface::class);
60
86
$ mock = $ mockBuilder ->setMethods (['getStore ' ])
61
87
->disableOriginalConstructor ()
62
88
->getMockForAbstractClass ();
@@ -69,11 +95,11 @@ private function getMockedStoreManager()
69
95
}
70
96
71
97
/**
72
- * @return \Magento\Store\Model\ Store
98
+ * @return Store
73
99
*/
74
- private function getMockedStore ()
100
+ private function getMockedStore (): Store
75
101
{
76
- $ mockBuilder = $ this ->getMockBuilder (\ Magento \ Store \ Model \ Store::class);
102
+ $ mockBuilder = $ this ->getMockBuilder (Store::class);
77
103
$ mock = $ mockBuilder ->setMethods (['getBaseUrl ' , '__wakeup ' ])
78
104
->disableOriginalConstructor ()
79
105
->getMockForAbstractClass ();
@@ -86,11 +112,11 @@ private function getMockedStore()
86
112
}
87
113
88
114
/**
89
- * @return \Magento\Eav\Model\Entity\Attribute\ AbstractAttribute
115
+ * @return AbstractAttribute
90
116
*/
91
- private function getMockedAttribute ()
117
+ private function getMockedAttribute (): AbstractAttribute
92
118
{
93
- $ mockBuilder = $ this ->getMockBuilder (\ Magento \ Eav \ Model \ Entity \ Attribute \ AbstractAttribute::class);
119
+ $ mockBuilder = $ this ->getMockBuilder (AbstractAttribute::class);
94
120
$ mockBuilder ->setMethods (['getAttributeCode ' , '__wakeup ' ]);
95
121
$ mockBuilder ->disableOriginalConstructor ();
96
122
$ mock = $ mockBuilder ->getMockForAbstractClass ();
0 commit comments