12
12
use Magento \Framework \View \Element \UiComponent \ContextInterface ;
13
13
use Magento \Framework \View \Element \UiComponent \Processor ;
14
14
use Magento \Sales \Ui \Component \Listing \Column \Price ;
15
+ use Magento \Store \Model \Store ;
16
+ use Magento \Store \Model \StoreManagerInterface ;
15
17
use PHPUnit \Framework \MockObject \MockObject ;
16
18
use PHPUnit \Framework \TestCase ;
17
19
@@ -27,6 +29,11 @@ class PriceTest extends TestCase
27
29
*/
28
30
protected $ currencyMock ;
29
31
32
+ /**
33
+ * @var StoreManagerInterface|MockObject
34
+ */
35
+ private $ storeManagerMock ;
36
+
30
37
protected function setUp (): void
31
38
{
32
39
$ objectManager = new ObjectManager ($ this );
@@ -40,31 +47,45 @@ protected function setUp(): void
40
47
->setMethods (['load ' , 'format ' ])
41
48
->disableOriginalConstructor ()
42
49
->getMock ();
50
+ $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)
51
+ ->disableOriginalConstructor ()
52
+ ->getMock ();
43
53
$ this ->model = $ objectManager ->getObject (
44
54
Price::class,
45
- ['currency ' => $ this ->currencyMock , 'context ' => $ contextMock ]
55
+ ['currency ' => $ this ->currencyMock , 'context ' => $ contextMock, ' storeManager ' => $ this -> storeManagerMock ]
46
56
);
47
57
}
48
58
49
- public function testPrepareDataSource ()
59
+ /**
60
+ * @param $hasCurrency
61
+ * @param $dataSource
62
+ * @param $currencyCode
63
+ * @dataProvider testPrepareDataSourceDataProvider
64
+ */
65
+ public function testPrepareDataSource ($ hasCurrency , $ dataSource , $ currencyCode )
50
66
{
51
67
$ itemName = 'itemName ' ;
52
68
$ oldItemValue = 'oldItemValue ' ;
53
69
$ newItemValue = 'newItemValue ' ;
54
- $ dataSource = [
55
- 'data ' => [
56
- 'items ' => [
57
- [
58
- $ itemName => $ oldItemValue ,
59
- 'base_currency_code ' => 'US '
60
- ]
61
- ]
62
- ]
63
- ];
70
+
71
+ $ store = $ this ->getMockBuilder (Store::class)
72
+ ->disableOriginalConstructor ()
73
+ ->getMock ();
74
+ $ currencyMock = $ this ->getMockBuilder (Currency::class)
75
+ ->disableOriginalConstructor ()
76
+ ->getMock ();
77
+ $ currencyMock ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
78
+ ->method ('getCurrencyCode ' )
79
+ ->willReturn ($ currencyCode );
80
+ $ this ->storeManagerMock ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
81
+ ->method ('getStore ' )
82
+ ->willReturn ($ store );
83
+ $ store ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
84
+ ->method ('getBaseCurrency ' )
85
+ ->willReturn ($ currencyMock );
64
86
65
87
$ this ->currencyMock ->expects ($ this ->once ())
66
88
->method ('load ' )
67
- ->with ($ dataSource ['data ' ]['items ' ][0 ]['base_currency_code ' ])
68
89
->willReturnSelf ();
69
90
70
91
$ this ->currencyMock ->expects ($ this ->once ())
@@ -76,4 +97,31 @@ public function testPrepareDataSource()
76
97
$ dataSource = $ this ->model ->prepareDataSource ($ dataSource );
77
98
$ this ->assertEquals ($ newItemValue , $ dataSource ['data ' ]['items ' ][0 ][$ itemName ]);
78
99
}
100
+
101
+ public function testPrepareDataSourceDataProvider ()
102
+ {
103
+ $ dataSource1 = [
104
+ 'data ' => [
105
+ 'items ' => [
106
+ [
107
+ 'itemName ' => 'oldItemValue ' ,
108
+ 'base_currency_code ' => 'US '
109
+ ]
110
+ ]
111
+ ]
112
+ ];
113
+ $ dataSource2 = [
114
+ 'data ' => [
115
+ 'items ' => [
116
+ [
117
+ 'itemName ' => 'oldItemValue '
118
+ ]
119
+ ]
120
+ ]
121
+ ];
122
+ return [
123
+ [true , $ dataSource1 , 'US ' ],
124
+ [false , $ dataSource2 , 'SAR ' ],
125
+ ];
126
+ }
79
127
}
0 commit comments