7
7
namespace Magento \Catalog \Test \Unit \Pricing \Render ;
8
8
9
9
use Magento \Catalog \Model \Product \Pricing \Renderer \SalableResolverInterface ;
10
+ use Magento \Framework \Module \Manager ;
11
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
12
11
13
/**
12
14
* Class FinalPriceBoxTest
@@ -63,11 +65,17 @@ class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
63
65
*/
64
66
private $ salableResolverMock ;
65
67
68
+ /** @var ObjectManager */
69
+ private $ objectManager ;
70
+
71
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
72
+ private $ moduleManager ;
73
+
66
74
protected function setUp ()
67
75
{
68
76
$ this ->product = $ this ->getMock (
69
77
\Magento \Catalog \Model \Product::class,
70
- ['getPriceInfo ' , '__wakeup ' , 'getCanShowPrice ' , ' isSalable ' ],
78
+ ['getPriceInfo ' , '__wakeup ' , 'getCanShowPrice ' ],
71
79
[],
72
80
'' ,
73
81
false
@@ -138,21 +146,22 @@ protected function setUp()
138
146
->method ('getUrlBuilder ' )
139
147
->will ($ this ->returnValue ($ urlBuilder ));
140
148
141
- $ this ->rendererPool = $ this ->getMockBuilder (' Magento\Framework\Pricing\Render\RendererPool ' )
149
+ $ this ->rendererPool = $ this ->getMockBuilder (\ Magento \Framework \Pricing \Render \RendererPool::class )
142
150
->disableOriginalConstructor ()
143
151
->getMock ();
144
152
145
- $ this ->price = $ this ->getMock (' Magento\Framework\Pricing\Price\PriceInterface ' );
153
+ $ this ->price = $ this ->getMock (\ Magento \Framework \Pricing \Price \PriceInterface::class );
146
154
$ this ->price ->expects ($ this ->any ())
147
155
->method ('getPriceCode ' )
148
156
->will ($ this ->returnValue (\Magento \Catalog \Pricing \Price \FinalPrice::PRICE_CODE ));
149
157
150
- $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
158
+ $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
159
+
151
160
$ this ->salableResolverMock = $ this ->getMockBuilder (SalableResolverInterface::class)
152
161
->disableOriginalConstructor ()
153
162
->getMockForAbstractClass ();
154
163
155
- $ this ->object = $ objectManager ->getObject (
164
+ $ this ->object = $ this -> objectManager ->getObject (
156
165
'Magento\Catalog\Pricing\Render\FinalPriceBox ' ,
157
166
[
158
167
'context ' => $ context ,
@@ -163,11 +172,33 @@ protected function setUp()
163
172
'salableResolver ' => $ this ->salableResolverMock
164
173
]
165
174
);
175
+
176
+ $ this ->moduleManager = $ this ->getMockBuilder (Manager::class)
177
+ ->setMethods (['isEnabled ' , 'isOutputEnabled ' ])
178
+ ->disableOriginalConstructor ()
179
+ ->getMock ();
180
+
181
+ $ this ->objectManager ->setBackwardCompatibleProperty (
182
+ $ this ->object ,
183
+ 'moduleManager ' ,
184
+ $ this ->moduleManager
185
+ );
166
186
}
167
187
168
188
public function testRenderMsrpDisabled ()
169
189
{
170
- $ priceType = $ this ->getMock ('Magento\Msrp\Pricing\Price\MsrpPrice ' , [], [], '' , false );
190
+ $ priceType = $ this ->getMock (\Magento \Msrp \Pricing \Price \MsrpPrice::class, [], [], '' , false );
191
+
192
+ $ this ->moduleManager ->expects (self ::once ())
193
+ ->method ('isEnabled ' )
194
+ ->with ('Magento_Msrp ' )
195
+ ->willReturn (true );
196
+
197
+ $ this ->moduleManager ->expects (self ::once ())
198
+ ->method ('isOutputEnabled ' )
199
+ ->with ('Magento_Msrp ' )
200
+ ->willReturn (true );
201
+
171
202
$ this ->priceInfo ->expects ($ this ->once ())
172
203
->method ('getPrice ' )
173
204
->with ($ this ->equalTo ('msrp_price ' ))
@@ -178,8 +209,6 @@ public function testRenderMsrpDisabled()
178
209
->with ($ this ->equalTo ($ this ->product ))
179
210
->will ($ this ->returnValue (false ));
180
211
181
- $ this ->salableResolverMock ->expects ($ this ->once ())->method ('isSalable ' )->with ($ this ->product )->willReturn (true );
182
-
183
212
$ result = $ this ->object ->toHtml ();
184
213
185
214
//assert price wrapper
@@ -188,21 +217,21 @@ public function testRenderMsrpDisabled()
188
217
$ this ->assertRegExp ('/[final_price]/ ' , $ result );
189
218
}
190
219
191
- public function testNotSalableItem ()
220
+ public function testRenderMsrpEnabled ()
192
221
{
193
- $ this ->salableResolverMock
194
- ->expects ($ this ->once ())
195
- ->method ('isSalable ' )
196
- ->with ($ this ->product )
197
- ->willReturn (false );
198
- $ result = $ this ->object ->toHtml ();
222
+ $ priceType = $ this ->getMock (\Magento \Msrp \Pricing \Price \MsrpPrice::class, [], [], '' , false );
223
+
224
+ $ this ->moduleManager ->expects (self ::once ())
225
+ ->method ('isEnabled ' )
226
+ ->with ('Magento_Msrp ' )
227
+ ->willReturn (true );
228
+
229
+ $ this ->moduleManager ->expects (self ::once ())
230
+ ->method ('isOutputEnabled ' )
231
+ ->with ('Magento_Msrp ' )
232
+ ->willReturn (true );
199
233
200
- $ this ->assertEmpty ($ result );
201
- }
202
234
203
- public function testRenderMsrpEnabled ()
204
- {
205
- $ priceType = $ this ->getMock ('Magento\Msrp\Pricing\Price\MsrpPrice ' , [], [], '' , false );
206
235
$ this ->priceInfo ->expects ($ this ->once ())
207
236
->method ('getPrice ' )
208
237
->with ($ this ->equalTo ('msrp_price ' ))
@@ -234,8 +263,6 @@ public function testRenderMsrpEnabled()
234
263
->with ('msrp_price ' , $ this ->product , $ arguments )
235
264
->will ($ this ->returnValue ($ priceBoxRender ));
236
265
237
- $ this ->salableResolverMock ->expects ($ this ->once ())->method ('isSalable ' )->with ($ this ->product )->willReturn (true );
238
-
239
266
$ result = $ this ->object ->toHtml ();
240
267
241
268
//assert price wrapper
@@ -247,6 +274,16 @@ public function testRenderMsrpEnabled()
247
274
248
275
public function testRenderMsrpNotRegisteredException ()
249
276
{
277
+ $ this ->moduleManager ->expects (self ::once ())
278
+ ->method ('isEnabled ' )
279
+ ->with ('Magento_Msrp ' )
280
+ ->willReturn (true );
281
+
282
+ $ this ->moduleManager ->expects (self ::once ())
283
+ ->method ('isOutputEnabled ' )
284
+ ->with ('Magento_Msrp ' )
285
+ ->willReturn (true );
286
+
250
287
$ this ->logger ->expects ($ this ->once ())
251
288
->method ('critical ' );
252
289
@@ -255,8 +292,6 @@ public function testRenderMsrpNotRegisteredException()
255
292
->with ($ this ->equalTo ('msrp_price ' ))
256
293
->will ($ this ->throwException (new \InvalidArgumentException ()));
257
294
258
- $ this ->salableResolverMock ->expects ($ this ->once ())->method ('isSalable ' )->with ($ this ->product )->willReturn (true );
259
-
260
295
$ result = $ this ->object ->toHtml ();
261
296
262
297
//assert price wrapper
@@ -406,4 +441,34 @@ public function testGetCacheKeyInfo()
406
441
{
407
442
$ this ->assertArrayHasKey ('display_minimal_price ' , $ this ->object ->getCacheKeyInfo ());
408
443
}
444
+
445
+ public function testRenderMsrpModuleDisabled ()
446
+ {
447
+ $ this ->moduleManager ->expects (self ::exactly (2 ))
448
+ ->method ('isEnabled ' )
449
+ ->with ('Magento_Msrp ' )
450
+ ->will ($ this ->onConsecutiveCalls (false , true ));
451
+
452
+ $ this ->priceInfo ->expects ($ this ->never ())
453
+ ->method ('getPrice ' );
454
+
455
+ $ result = $ this ->object ->toHtml ();
456
+
457
+ //assert price wrapper
458
+ $ this ->assertStringStartsWith ('<div ' , $ result );
459
+ //assert css_selector
460
+ $ this ->assertRegExp ('/[final_price]/ ' , $ result );
461
+
462
+ $ this ->moduleManager ->expects (self ::once ())
463
+ ->method ('isOutputEnabled ' )
464
+ ->with ('Magento_Msrp ' )
465
+ ->willReturn (false );
466
+
467
+ $ result = $ this ->object ->toHtml ();
468
+
469
+ //assert price wrapper
470
+ $ this ->assertStringStartsWith ('<div ' , $ result );
471
+ //assert css_selector
472
+ $ this ->assertRegExp ('/[final_price]/ ' , $ result );
473
+ }
409
474
}
0 commit comments