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,6 +65,12 @@ 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 (
@@ -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 ' ))
@@ -188,7 +219,19 @@ public function testRenderMsrpDisabled()
188
219
189
220
public function testRenderMsrpEnabled ()
190
221
{
191
- $ priceType = $ this ->getMock ('Magento\Msrp\Pricing\Price\MsrpPrice ' , [], [], '' , false );
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 );
233
+
234
+
192
235
$ this ->priceInfo ->expects ($ this ->once ())
193
236
->method ('getPrice ' )
194
237
->with ($ this ->equalTo ('msrp_price ' ))
@@ -231,6 +274,16 @@ public function testRenderMsrpEnabled()
231
274
232
275
public function testRenderMsrpNotRegisteredException ()
233
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
+
234
287
$ this ->logger ->expects ($ this ->once ())
235
288
->method ('critical ' );
236
289
@@ -388,4 +441,34 @@ public function testGetCacheKeyInfo()
388
441
{
389
442
$ this ->assertArrayHasKey ('display_minimal_price ' , $ this ->object ->getCacheKeyInfo ());
390
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
+ }
391
474
}
0 commit comments