@@ -47,44 +47,49 @@ class CurrencyTest extends \PHPUnit_Framework_TestCase
47
47
*/
48
48
protected $ _row ;
49
49
50
+ /*
51
+ * @var \PHPUnit_Framework_MockObject_MockObject
52
+ */
53
+ protected $ numberFactoryMock ;
54
+
50
55
protected function setUp ()
51
56
{
52
- $ this ->_storeManagerMock = $ this ->getMock (' Magento\Store\Model\StoreManagerInterface ' );
53
- $ this ->_localeMock = $ this ->getMock (' Magento\Framework\Locale\CurrencyInterface ' );
54
- $ this ->_requestMock = $ this ->getMock (' Magento\Framework\App\RequestInterface ' );
57
+ $ this ->_storeManagerMock = $ this ->getMock (\ Magento \Store \Model \StoreManagerInterface::class );
58
+ $ this ->_localeMock = $ this ->getMock (\ Magento \Framework \Locale \CurrencyInterface::class );
59
+ $ this ->_requestMock = $ this ->getMock (\ Magento \Framework \App \RequestInterface::class );
55
60
56
61
$ this ->_curLocatorMock = $ this ->getMock (
57
- ' Magento\Directory\Model\Currency\DefaultLocator ' ,
62
+ \ Magento \Directory \Model \Currency \DefaultLocator::class ,
58
63
[],
59
64
[],
60
65
'' ,
61
66
false
62
67
);
63
68
$ this ->_columnMock = $ this ->getMock (
64
- ' Magento\Backend\Block\Widget\Grid\Column ' ,
69
+ \ Magento \Backend \Block \Widget \Grid \Column::class ,
65
70
['getIndex ' ],
66
71
[],
67
72
'' ,
68
73
false
69
74
);
70
75
$ this ->_columnMock ->expects ($ this ->any ())->method ('getIndex ' )->will ($ this ->returnValue ('columnIndex ' ));
71
76
72
- $ this ->_currencyMock = $ this ->getMock (' Magento\Directory\Model\Currency ' , [], [], '' , false );
77
+ $ this ->_currencyMock = $ this ->getMock (\ Magento \Directory \Model \Currency::class , [], [], '' , false );
73
78
$ this ->_currencyMock ->expects ($ this ->any ())->method ('load ' )->will ($ this ->returnSelf ());
74
79
$ currencyFactoryMock = $ this ->getMock (
75
- ' Magento\Directory\Model\CurrencyFactory ' ,
80
+ \ Magento \Directory \Model \CurrencyFactory::class ,
76
81
['create ' ],
77
82
[],
78
83
'' ,
79
84
false
80
85
);
81
86
$ currencyFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ this ->_currencyMock ));
82
87
83
- $ this ->_row = new \Magento \Framework \DataObject (['columnIndex ' => '10 ' ]);
88
+ $ this ->_row = new \Magento \Framework \DataObject (['columnIndex ' => '$10.00 ' ]);
84
89
85
90
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
86
91
$ this ->_blockCurrency = $ helper ->getObject (
87
- ' Magento\Backend\Block\Widget\Grid\Column\Renderer\Currency ' ,
92
+ \ Magento \Backend \Block \Widget \Grid \Column \Renderer \Currency::class ,
88
93
[
89
94
'storeManager ' => $ this ->_storeManagerMock ,
90
95
'localeCurrency ' => $ this ->_localeMock ,
@@ -95,6 +100,19 @@ protected function setUp()
95
100
);
96
101
97
102
$ this ->_blockCurrency ->setColumn ($ this ->_columnMock );
103
+
104
+ $ this ->numberFormatterFactoryMock = $ this ->getMock (
105
+ \Magento \Framework \Intl::class,
106
+ ['create ' ],
107
+ [],
108
+ '' ,
109
+ false
110
+ );
111
+ $ helper ->setBackwardCompatibleProperty (
112
+ $ this ->_blockCurrency ,
113
+ 'numberFormatterFactory ' ,
114
+ $ this ->numberFormatterFactoryMock
115
+ );
98
116
}
99
117
100
118
protected function tearDown ()
@@ -113,46 +131,40 @@ protected function tearDown()
113
131
*/
114
132
public function testRenderWithDefaultCurrency ()
115
133
{
116
- $ this ->_currencyMock ->expects (
117
- $ this ->once ()
118
- )->method (
119
- 'getRate '
120
- )->with (
121
- 'defaultCurrency '
122
- )->will (
123
- $ this ->returnValue (1.5 )
124
- );
125
-
126
- $ this ->_curLocatorMock ->expects (
127
- $ this ->any ()
128
- )->method (
129
- 'getDefaultCurrency '
130
- )->with (
131
- $ this ->_requestMock
132
- )->will (
133
- $ this ->returnValue ('defaultCurrency ' )
134
- );
135
-
136
- $ currLocaleMock = $ this ->getMock ('Zend_Currency ' , [], [], '' , false );
137
- $ currLocaleMock ->expects (
138
- $ this ->once ()
139
- )->method (
140
- 'toCurrency '
141
- )->with (
142
- 15.0000
143
- )->will (
144
- $ this ->returnValue ('15USD ' )
145
- );
146
- $ this ->_localeMock ->expects (
147
- $ this ->once ()
148
- )->method (
149
- 'getCurrency '
150
- )->with (
151
- 'defaultCurrency '
152
- )->will (
153
- $ this ->returnValue ($ currLocaleMock )
154
- );
155
-
156
- $ this ->assertEquals ('15USD ' , $ this ->_blockCurrency ->render ($ this ->_row ));
134
+ $ this ->_currencyMock ->expects ($ this ->once ())
135
+ ->method ('getRate ' )
136
+ ->with ('USD ' )
137
+ ->willReturn (1.5 );
138
+ $ currLocaleMock = $ this ->getMock (\Magento \Framework \Currency::class, ['getLocale ' ,'toCurrency ' ], [], '' , false );
139
+ $ currLocaleMock ->expects ($ this ->once ())
140
+ ->method ('getLocale ' )
141
+ ->willReturn ('en_US ' );
142
+ $ this ->_localeMock ->expects ($ this ->once ())
143
+ ->method ('getCurrency ' )
144
+ ->with ('USD ' )
145
+ ->will ($ this ->returnValue ($ currLocaleMock ));
146
+
147
+ $ numberFormatterMock = $ this ->getMock (\NumberFormatter::class, ['parseCurrency ' ], [], '' , false );
148
+ $ this ->numberFormatterFactoryMock ->expects ($ this ->once ())
149
+ ->method ('create ' )
150
+ ->with ('en_US ' , \NumberFormatter::CURRENCY )
151
+ ->will ($ this ->returnValue ($ numberFormatterMock ));
152
+
153
+ $ numberFormatterMock ->expects ($ this ->once ())
154
+ ->method ('parseCurrency ' )
155
+ ->with ('$10.00 ' , 'USD ' )
156
+ ->willReturn (10 );
157
+
158
+ $ this ->_curLocatorMock ->expects ($ this ->any ())
159
+ ->method ('getDefaultCurrency ' )
160
+ ->with ($ this ->_requestMock )
161
+ ->willReturn ('USD ' );
162
+
163
+ $ currLocaleMock ->expects ($ this ->once ())
164
+ ->method ('toCurrency ' )
165
+ ->with (15.0000 )
166
+ ->willReturn ('$15.00 ' );
167
+
168
+ $ this ->assertEquals ('$15.00 ' , $ this ->_blockCurrency ->render ($ this ->_row ));
157
169
}
158
170
}
0 commit comments