Skip to content

Commit 4554901

Browse files
committed
MAGETWO-31363: [MPI] Unit and Integration tests coverage
1 parent 5257c5b commit 4554901

File tree

13 files changed

+135
-173
lines changed

13 files changed

+135
-173
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Form;
7+
8+
/**
9+
* Abstract class for Cash On Delivery and Bank Transfer payment method form
10+
*/
11+
abstract class AbstractInstruction extends \Magento\Payment\Block\Form
12+
{
13+
/**
14+
* Instructions text
15+
*
16+
* @var string
17+
*/
18+
protected $_instructions;
19+
20+
/**
21+
* Get instructions text from config
22+
*
23+
* @return string
24+
*/
25+
public function getInstructions()
26+
{
27+
if (is_null($this->_instructions)) {
28+
$this->_instructions = $this->getMethod()->getInstructions();
29+
}
30+
return $this->_instructions;
31+
}
32+
}

app/code/Magento/OfflinePayments/Block/Form/Banktransfer.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,12 @@
88
/**
99
* Block for Bank Transfer payment method form
1010
*/
11-
class Banktransfer extends \Magento\Payment\Block\Form
11+
class Banktransfer extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
1212
{
13-
/**
14-
* Instructions text
15-
*
16-
* @var string
17-
*/
18-
protected $_instructions;
19-
2013
/**
2114
* Bank transfer template
2215
*
2316
* @var string
2417
*/
2518
protected $_template = 'form/banktransfer.phtml';
26-
27-
/**
28-
* Get instructions text from config
29-
*
30-
* @return string
31-
*/
32-
public function getInstructions()
33-
{
34-
if (is_null($this->_instructions)) {
35-
$this->_instructions = $this->getMethod()->getInstructions();
36-
}
37-
return $this->_instructions;
38-
}
3919
}

app/code/Magento/OfflinePayments/Block/Form/Cashondelivery.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,12 @@
88
/**
99
* Block for Cash On Delivery payment method form
1010
*/
11-
class Cashondelivery extends \Magento\Payment\Block\Form
11+
class Cashondelivery extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
1212
{
13-
/**
14-
* Instructions text
15-
*
16-
* @var string
17-
*/
18-
protected $_instructions;
19-
2013
/**
2114
* Cash on delivery template
2215
*
2316
* @var string
2417
*/
2518
protected $_template = 'form/cashondelivery.phtml';
26-
27-
/**
28-
* Get instructions text from config
29-
*
30-
* @return string
31-
*/
32-
public function getInstructions()
33-
{
34-
if (is_null($this->_instructions)) {
35-
$this->_instructions = $this->getMethod()->getInstructions();
36-
}
37-
return $this->_instructions;
38-
}
3919
}

app/code/Magento/OfflinePayments/Model/Banktransfer.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,4 @@ class Banktransfer extends \Magento\Payment\Model\Method\AbstractMethod
3939
* @var bool
4040
*/
4141
protected $_isOffline = true;
42-
43-
/**
44-
* Get instructions text from config
45-
*
46-
* @return string
47-
*/
48-
public function getInstructions()
49-
{
50-
return trim($this->getConfigData('instructions'));
51-
}
5242
}

app/code/Magento/OfflinePayments/Model/Observer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ public function beforeOrderPaymentSave(\Magento\Framework\Event\Observer $observ
2121
{
2222
/** @var \Magento\Sales\Model\Order\Payment $payment */
2323
$payment = $observer->getEvent()->getPayment();
24-
$banktransfer = \Magento\OfflinePayments\Model\Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE;
25-
if ($payment->getMethod() === $banktransfer) {
26-
$payment->setAdditionalInformation('instructions', $payment->getMethodInstance()->getInstructions());
24+
if ($payment->getMethod() ===
25+
\Magento\OfflinePayments\Model\Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE
26+
) {
27+
$payment->setAdditionalInformation(
28+
'instructions',
29+
$payment->getMethodInstance()->getConfigData('instructions')
30+
);
2731
}
2832
}
2933
}

app/code/Magento/Payment/Block/Info/Instructions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getInstructions()
3333
if (is_null($this->_instructions)) {
3434
$this->_instructions = $this->getInfo()->getAdditionalInformation(
3535
'instructions'
36-
) ?: $this->getMethod()->getInstructions();
36+
) ?: $this->getMethod()->getConfigData('instructions');
3737
}
3838
return $this->_instructions;
3939
}

dev/tests/unit/testsuite/Magento/OfflinePayments/Block/Form/BanktransferTest.php renamed to dev/tests/unit/testsuite/Magento/OfflinePayments/Block/Form/AbstractInstructionTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
*/
66
namespace Magento\OfflinePayments\Block\Form;
77

8-
class BanktransferTest extends \PHPUnit_Framework_TestCase
8+
class AbstractInstructionTest extends \PHPUnit_Framework_TestCase
99
{
1010
/**
11-
* @var \Magento\OfflinePayments\Block\Form\Banktransfer
11+
* @var \Magento\OfflinePayments\Block\Form\AbstractInstruction
1212
*/
13-
protected $_object;
13+
protected $_model;
1414

1515
protected function setUp()
1616
{
17-
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
18-
$this->_object = $objectManagerHelper->getObject('Magento\OfflinePayments\Block\Form\Banktransfer');
17+
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
18+
$this->_model = $this->getMockForAbstractClass(
19+
'Magento\OfflinePayments\Block\Form\AbstractInstruction',
20+
['context' => $context]
21+
);
1922
}
2023

2124
public function testGetInstructions()
@@ -30,8 +33,8 @@ public function testGetInstructions()
3033
$method->expects($this->once())
3134
->method('getInstructions')
3235
->willReturn('instructions');
33-
$this->_object->setData('method', $method);
36+
$this->_model->setData('method', $method);
3437

35-
$this->assertEquals('instructions', $this->_object->getInstructions());
38+
$this->assertEquals('instructions', $this->_model->getInstructions());
3639
}
3740
}

dev/tests/unit/testsuite/Magento/OfflinePayments/Block/Form/Cashondelivery.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

dev/tests/unit/testsuite/Magento/OfflinePayments/Block/Info/CheckmoTest.php

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,12 @@ class CheckmoTest extends \PHPUnit_Framework_TestCase
1010
/**
1111
* @var \Magento\OfflinePayments\Block\Info\Checkmo
1212
*/
13-
protected $_object;
14-
15-
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
17-
*/
18-
protected $_scopeConfig;
13+
protected $_model;
1914

2015
protected function setUp()
2116
{
22-
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
23-
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
24-
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
25-
$this->_scopeConfig = $this->getMock(
26-
'Magento\Framework\App\Config\ScopeConfigInterface',
27-
['getValue', 'isSetFlag'],
28-
[],
29-
'',
30-
false
31-
);
32-
$this->_object = $objectManagerHelper->getObject(
33-
'Magento\OfflinePayments\Block\Info\Checkmo',
34-
[
35-
'eventManager' => $eventManager,
36-
'paymentData' => $paymentDataMock,
37-
'scopeConfig' => $this->_scopeConfig,
38-
]
39-
);
17+
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
18+
$this->_model = new \Magento\OfflinePayments\Block\Info\Checkmo($context);
4019
}
4120

4221
/**
@@ -48,9 +27,9 @@ public function testGetPayableTo($details, $expected)
4827
$info->expects($this->once())
4928
->method('getAdditionalData')
5029
->willReturn(serialize($details));
51-
$this->_object->setData('info', $info);
30+
$this->_model->setData('info', $info);
5231

53-
$this->assertEquals($expected, $this->_object->getPayableTo());
32+
$this->assertEquals($expected, $this->_model->getPayableTo());
5433
}
5534

5635
/**
@@ -73,9 +52,9 @@ public function testGetMailingAddress($details, $expected)
7352
$info->expects($this->once())
7453
->method('getAdditionalData')
7554
->willReturn(serialize($details));
76-
$this->_object->setData('info', $info);
55+
$this->_model->setData('info', $info);
7756

78-
$this->assertEquals($expected, $this->_object->getMailingAddress());
57+
$this->assertEquals($expected, $this->_model->getMailingAddress());
7958
}
8059

8160
/**
@@ -88,4 +67,19 @@ public function getMailingAddressDataProvider()
8867
['', '']
8968
];
9069
}
70+
71+
public function testConvertAdditionalDataIsNeverCalled()
72+
{
73+
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
74+
$info->expects($this->once())
75+
->method('getAdditionalData')
76+
->willReturn(serialize(['mailing_address' => 'blah@blah.com']));
77+
$this->_model->setData('info', $info);
78+
79+
// First we set the property $this->_mailingAddress
80+
$this->_model->getMailingAddress();
81+
82+
// And now we get already setted property $this->_mailingAddress
83+
$this->assertEquals('blah@blah.com', $this->_model->getMailingAddress());
84+
}
9185
}

dev/tests/unit/testsuite/Magento/OfflinePayments/Model/BanktransferTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,4 @@ public function testGetInfoBlockType()
3737
{
3838
$this->assertEquals('Magento\Payment\Block\Info\Instructions', $this->_object->getInfoBlockType());
3939
}
40-
41-
public function testGetInstructions()
42-
{
43-
$this->_object->setStore(1);
44-
$this->_scopeConfig->expects($this->once())
45-
->method('getValue')
46-
->with('payment/banktransfer/instructions', 'store', 1)
47-
->willReturn('payment configuration');
48-
$this->assertEquals('payment configuration', $this->_object->getInstructions());
49-
}
5040
}

0 commit comments

Comments
 (0)