8
8
9
9
namespace Magento \Checkout \Test \Unit \Helper ;
10
10
11
- use \Magento \Checkout \Helper \Data ;
12
-
11
+ use Magento \Checkout \Helper \Data ;
13
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14
- use Magento \Store \Model \ScopeInterface ;
15
13
14
+ /**
15
+ * Test for Magento\Checkout\Helper\Data.
16
+ */
16
17
class DataTest extends \PHPUnit_Framework_TestCase
17
18
{
18
19
/**
@@ -38,27 +39,25 @@ class DataTest extends \PHPUnit_Framework_TestCase
38
39
/**
39
40
* @var \PHPUnit_Framework_MockObject_MockObject
40
41
*/
41
- protected $ _checkoutSession ;
42
+ private $ _checkoutSession ;
42
43
43
44
/**
44
45
* @var \PHPUnit_Framework_MockObject_MockObject
45
46
*/
46
- protected $ _scopeConfig ;
47
+ private $ _scopeConfig ;
47
48
48
49
/**
49
50
* @var \PHPUnit_Framework_MockObject_MockObject
50
51
*/
51
- protected $ _collectionFactory ;
52
+ private $ _eventManager ;
52
53
53
54
/**
54
- * @var \PHPUnit_Framework_MockObject_MockObject
55
+ * @inheritdoc
55
56
*/
56
- protected $ _eventManager ;
57
-
58
57
protected function setUp ()
59
58
{
60
59
$ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
61
- $ className = ' Magento\Checkout\Helper\Data ' ;
60
+ $ className = \ Magento \Checkout \Helper \Data::class ;
62
61
$ arguments = $ objectManagerHelper ->getConstructArguments ($ className );
63
62
/** @var \Magento\Framework\App\Helper\Context $context */
64
63
$ context = $ arguments ['context ' ];
@@ -74,50 +73,50 @@ protected function setUp()
74
73
'checkout/payment_failed/template ' ,
75
74
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
76
75
8 ,
77
- 'fixture_email_template_payment_failed '
76
+ 'fixture_email_template_payment_failed ' ,
78
77
],
79
78
[
80
79
'checkout/payment_failed/receiver ' ,
81
80
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
82
81
8 ,
83
- 'sysadmin '
82
+ 'sysadmin ' ,
84
83
],
85
84
[
86
85
'trans_email/ident_sysadmin/email ' ,
87
86
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
88
87
8 ,
89
- 'sysadmin@example.com '
88
+ 'sysadmin@example.com ' ,
90
89
],
91
90
[
92
91
'trans_email/ident_sysadmin/name ' ,
93
92
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
94
93
8 ,
95
- 'System Administrator '
94
+ 'System Administrator ' ,
96
95
],
97
96
[
98
97
'checkout/payment_failed/identity ' ,
99
98
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
100
99
8 ,
101
- 'noreply@example.com '
100
+ 'noreply@example.com ' ,
102
101
],
103
102
[
104
103
'carriers/ground/title ' ,
105
104
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
106
105
null ,
107
- 'Ground Shipping '
106
+ 'Ground Shipping ' ,
108
107
],
109
108
[
110
109
'payment/fixture-payment-method/title ' ,
111
110
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
112
111
null ,
113
- 'Check Money Order '
112
+ 'Check Money Order ' ,
114
113
],
115
114
[
116
115
'checkout/options/onepage_checkout_enabled ' ,
117
116
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
118
117
null ,
119
- 'One Page Checkout '
120
- ]
118
+ 'One Page Checkout ' ,
119
+ ],
121
120
]
122
121
)
123
122
);
@@ -166,6 +165,16 @@ public function testSendPaymentFailedEmail()
166
165
$ this ->returnSelf ()
167
166
);
168
167
168
+ $ this ->_transportBuilder ->expects (
169
+ $ this ->once ()
170
+ )->method (
171
+ 'setScopeId '
172
+ )->with (
173
+ 8
174
+ )->will (
175
+ $ this ->returnSelf ()
176
+ );
177
+
169
178
$ this ->_transportBuilder ->expects (
170
179
$ this ->once ()
171
180
)->method (
@@ -203,7 +212,7 @@ public function testSendPaymentFailedEmail()
203
212
'shippingMethod ' => 'Ground Shipping ' ,
204
213
'paymentMethod ' => 'Check Money Order ' ,
205
214
'items ' => "Product One x 2 USD 10<br /> \nProduct Two x 3 USD 60<br /> \n" ,
206
- 'total ' => 'USD 70 '
215
+ 'total ' => 'USD 70 ' ,
207
216
]
208
217
)->will (
209
218
$ this ->returnSelf ()
@@ -215,17 +224,17 @@ public function testSendPaymentFailedEmail()
215
224
)->method (
216
225
'getTransport '
217
226
)->will (
218
- $ this ->returnValue ($ this ->getMock (' Magento\Framework\Mail\TransportInterface ' ))
227
+ $ this ->returnValue ($ this ->getMock (\ Magento \Framework \Mail \TransportInterface::class ))
219
228
);
220
229
221
230
$ this ->_translator ->expects ($ this ->at (1 ))->method ('suspend ' );
222
231
$ this ->_translator ->expects ($ this ->at (1 ))->method ('resume ' );
223
232
224
- $ productOne = $ this ->getMock (' \Magento\Catalog\Model\Product ' , [], [], '' , false );
233
+ $ productOne = $ this ->getMock (\Magento \Catalog \Model \Product::class , [], [], '' , false );
225
234
$ productOne ->expects ($ this ->once ())->method ('getName ' )->will ($ this ->returnValue ('Product One ' ));
226
235
$ productOne ->expects ($ this ->once ())->method ('getFinalPrice ' )->with (2 )->will ($ this ->returnValue (10 ));
227
236
228
- $ productTwo = $ this ->getMock (' \Magento\Catalog\Model\Product ' , [], [], '' , false );
237
+ $ productTwo = $ this ->getMock (\Magento \Catalog \Model \Product::class , [], [], '' , false );
229
238
$ productTwo ->expects ($ this ->once ())->method ('getName ' )->will ($ this ->returnValue ('Product Two ' ));
230
239
$ productTwo ->expects ($ this ->once ())->method ('getFinalPrice ' )->with (3 )->will ($ this ->returnValue (60 ));
231
240
@@ -242,8 +251,8 @@ public function testSendPaymentFailedEmail()
242
251
'payment ' => new \Magento \Framework \DataObject (['method ' => 'fixture-payment-method ' ]),
243
252
'all_visible_items ' => [
244
253
new \Magento \Framework \DataObject (['product ' => $ productOne , 'qty ' => 2 ]),
245
- new \Magento \Framework \DataObject (['product ' => $ productTwo , 'qty ' => 3 ])
246
- ]
254
+ new \Magento \Framework \DataObject (['product ' => $ productTwo , 'qty ' => 3 ]),
255
+ ],
247
256
]
248
257
);
249
258
$ this ->assertSame ($ this ->_helper , $ this ->_helper ->sendPaymentFailedEmail ($ quote , 'test message ' ));
@@ -259,17 +268,17 @@ public function testGetCheckout()
259
268
260
269
public function testGetQuote ()
261
270
{
262
- $ quoteMock = $ this ->getMock (' \Magento\Quote\Model\Quote ' , [], [], '' , false );
271
+ $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class , [], [], '' , false );
263
272
$ this ->_checkoutSession ->expects ($ this ->once ())->method ('getQuote ' )->will ($ this ->returnValue ($ quoteMock ));
264
273
$ this ->assertEquals ($ quoteMock , $ this ->_helper ->getQuote ());
265
274
}
266
275
267
276
public function testFormatPrice ()
268
277
{
269
278
$ price = 5.5 ;
270
- $ quoteMock = $ this ->getMock (' \Magento\Quote\Model\Quote ' , [], [], '' , false );
279
+ $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class , [], [], '' , false );
271
280
$ storeMock = $ this ->getMock (
272
- ' Magento\Store\Model\Store ' ,
281
+ \ Magento \Store \Model \Store::class ,
273
282
['formatPrice ' , '__wakeup ' ],
274
283
[],
275
284
'' ,
@@ -300,11 +309,9 @@ public function testCanOnepageCheckout()
300
309
public function testIsContextCheckout ()
301
310
{
302
311
$ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
303
- $ context = $ objectManagerHelper ->getObject (
304
- 'Magento\Framework\App\Helper\Context '
305
- );
312
+ $ context = $ objectManagerHelper ->getObject (\Magento \Framework \App \Helper \Context::class);
306
313
$ helper = $ objectManagerHelper ->getObject (
307
- ' Magento\Checkout\Helper\Data ' ,
314
+ \ Magento \Checkout \Helper \Data::class ,
308
315
['context ' => $ context ]
309
316
);
310
317
$ context ->getRequest ()->expects ($ this ->once ())->method ('getParam ' )->with ('context ' )->will (
@@ -324,7 +331,7 @@ public function testIsCustomerMustBeLogged()
324
331
325
332
public function testGetPriceInclTax ()
326
333
{
327
- $ itemMock = $ this ->getMock (' Magento\Framework\DataObject ' , ['getPriceInclTax ' ], [], '' , false );
334
+ $ itemMock = $ this ->getMock (\ Magento \Framework \DataObject::class , ['getPriceInclTax ' ], [], '' , false );
328
335
$ itemMock ->expects ($ this ->exactly (2 ))->method ('getPriceInclTax ' )->will ($ this ->returnValue (5.5 ));
329
336
$ this ->assertEquals (5.5 , $ this ->_helper ->getPriceInclTax ($ itemMock ));
330
337
}
@@ -337,17 +344,17 @@ public function testGetPriceInclTaxWithoutTax()
337
344
$ rowTotal = 15 ;
338
345
$ roundPrice = 17 ;
339
346
$ expected = 17 ;
340
- $ storeManager = $ this ->getMock (' \Magento\Store\Model\StoreManagerInterface ' , [], [], '' , false );
347
+ $ storeManager = $ this ->getMock (\Magento \Store \Model \StoreManagerInterface::class , [], [], '' , false );
341
348
$ objectManagerHelper = new ObjectManager ($ this );
342
349
$ helper = $ objectManagerHelper ->getObject (
343
- ' \Magento\Checkout\Helper\Data ' ,
350
+ \Magento \Checkout \Helper \Data::class ,
344
351
[
345
352
'storeManager ' => $ storeManager ,
346
353
'priceCurrency ' => $ this ->priceCurrency ,
347
354
]
348
355
);
349
356
$ itemMock = $ this ->getMock (
350
- ' Magento\Framework\DataObject ' ,
357
+ \ Magento \Framework \DataObject::class ,
351
358
['getPriceInclTax ' , 'getQty ' , 'getTaxAmount ' , 'getDiscountTaxCompensation ' , 'getRowTotal ' ],
352
359
[],
353
360
'' ,
@@ -368,7 +375,7 @@ public function testGetSubtotalInclTax()
368
375
{
369
376
$ rowTotalInclTax = 5.5 ;
370
377
$ expected = 5.5 ;
371
- $ itemMock = $ this ->getMock (' Magento\Framework\DataObject ' , ['getRowTotalInclTax ' ], [], '' , false );
378
+ $ itemMock = $ this ->getMock (\ Magento \Framework \DataObject::class , ['getRowTotalInclTax ' ], [], '' , false );
372
379
$ itemMock ->expects ($ this ->exactly (2 ))->method ('getRowTotalInclTax ' )->will ($ this ->returnValue ($ rowTotalInclTax ));
373
380
$ this ->assertEquals ($ expected , $ this ->_helper ->getSubtotalInclTax ($ itemMock ));
374
381
}
@@ -380,7 +387,7 @@ public function testGetSubtotalInclTaxNegative()
380
387
$ rowTotal = 15 ;
381
388
$ expected = 17 ;
382
389
$ itemMock = $ this ->getMock (
383
- ' Magento\Framework\DataObject ' ,
390
+ \ Magento \Framework \DataObject::class ,
384
391
['getRowTotalInclTax ' , 'getTaxAmount ' , 'getDiscountTaxCompensation ' , 'getRowTotal ' ],
385
392
[],
386
393
'' ,
@@ -396,33 +403,33 @@ public function testGetSubtotalInclTaxNegative()
396
403
397
404
public function testGetBasePriceInclTaxWithoutQty ()
398
405
{
399
- $ storeManager = $ this ->getMock (' \Magento\Store\Model\StoreManagerInterface ' , [], [], '' , false );
406
+ $ storeManager = $ this ->getMock (\Magento \Store \Model \StoreManagerInterface::class , [], [], '' , false );
400
407
$ objectManagerHelper = new ObjectManager ($ this );
401
408
$ helper = $ objectManagerHelper ->getObject (
402
- ' \Magento\Checkout\Helper\Data ' ,
409
+ \Magento \Checkout \Helper \Data::class ,
403
410
[
404
411
'storeManager ' => $ storeManager ,
405
412
'priceCurrency ' => $ this ->priceCurrency ,
406
413
]
407
414
);
408
- $ itemMock = $ this ->getMock (' Magento\Framework\DataObject ' , ['getQty ' ], [], '' , false );
415
+ $ itemMock = $ this ->getMock (\ Magento \Framework \DataObject::class , ['getQty ' ], [], '' , false );
409
416
$ itemMock ->expects ($ this ->once ())->method ('getQty ' );
410
417
$ this ->priceCurrency ->expects ($ this ->once ())->method ('round ' );
411
418
$ helper ->getPriceInclTax ($ itemMock );
412
419
}
413
420
414
421
public function testGetBasePriceInclTax ()
415
422
{
416
- $ storeManager = $ this ->getMock (' \Magento\Store\Model\StoreManagerInterface ' , [], [], '' , false );
423
+ $ storeManager = $ this ->getMock (\Magento \Store \Model \StoreManagerInterface::class , [], [], '' , false );
417
424
$ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
418
425
$ helper = $ objectManagerHelper ->getObject (
419
- ' \Magento\Checkout\Helper\Data ' ,
426
+ \Magento \Checkout \Helper \Data::class ,
420
427
[
421
428
'storeManager ' => $ storeManager ,
422
429
'priceCurrency ' => $ this ->priceCurrency ,
423
430
]
424
431
);
425
- $ itemMock = $ this ->getMock (' Magento\Framework\DataObject ' , ['getQty ' , 'getQtyOrdered ' ], [], '' , false );
432
+ $ itemMock = $ this ->getMock (\ Magento \Framework \DataObject::class , ['getQty ' , 'getQtyOrdered ' ], [], '' , false );
426
433
$ itemMock ->expects ($ this ->once ())->method ('getQty ' )->will ($ this ->returnValue (false ));
427
434
$ itemMock ->expects ($ this ->exactly (2 ))->method ('getQtyOrdered ' )->will ($ this ->returnValue (5.5 ));
428
435
$ this ->priceCurrency ->expects ($ this ->once ())->method ('round ' );
@@ -432,7 +439,7 @@ public function testGetBasePriceInclTax()
432
439
public function testGetBaseSubtotalInclTax ()
433
440
{
434
441
$ itemMock = $ this ->getMock (
435
- ' Magento\Framework\DataObject ' ,
442
+ \ Magento \Framework \DataObject::class ,
436
443
['getBaseTaxAmount ' , 'getBaseDiscountTaxCompensation ' , 'getBaseRowTotal ' ],
437
444
[],
438
445
'' ,
@@ -446,7 +453,7 @@ public function testGetBaseSubtotalInclTax()
446
453
447
454
public function testIsAllowedGuestCheckoutWithoutStore ()
448
455
{
449
- $ quoteMock = $ this ->getMock (' \Magento\Quote\Model\Quote ' , [], [], '' , false );
456
+ $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class , [], [], '' , false );
450
457
$ store = null ;
451
458
$ quoteMock ->expects ($ this ->once ())->method ('getStoreId ' )->will ($ this ->returnValue (1 ));
452
459
$ this ->_scopeConfig ->expects ($ this ->once ())
0 commit comments