Skip to content

Commit 101b0c8

Browse files
author
Olexandr Lysenko
committed
MAGETWO-31593: Sales Quote as Standalone Magento Module
1 parent d1d2614 commit 101b0c8

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

app/code/Magento/Quote/Model/Quote/Payment/ToOrderPayment.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ public function convert(Payment $object, $data = [])
5151
'to_order_payment',
5252
$object
5353
);
54-
return $this->orderPaymentBuilder
54+
$payment = $this->orderPaymentBuilder
5555
->populateWithArray(array_merge($paymentData, $data))
5656
->setAdditionalInformation(
57-
serialize([Substitution::INFO_KEY_TITLE => $object->getMethodInstance()->getTitle()])
57+
serialize(
58+
array_merge(
59+
$object->getAdditionalInformation(),
60+
[Substitution::INFO_KEY_TITLE => $object->getMethodInstance()->getTitle()]
61+
)
62+
)
5863
)
5964
->create();
65+
$payment->setCcNumber($object->getCcNumber());
66+
$payment->setCcCid($object->getCcCid());
67+
68+
return $payment;
6069
}
6170
}

dev/tests/unit/testsuite/Magento/Quote/Model/Quote/Payment/ToOrderPaymentTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ class ToOrderPaymentTest extends \PHPUnit_Framework_TestCase
3636

3737
public function setUp()
3838
{
39-
$this->paymentMock = $this->getMock('Magento\Quote\Model\Quote\Payment', [], [], '', false);
39+
$this->paymentMock = $this->getMock(
40+
'Magento\Quote\Model\Quote\Payment',
41+
['getCcNumber', 'getCcCid', 'getMethodInstance', 'getAdditionalInformation'],
42+
[],
43+
'',
44+
false
45+
);
4046
$this->objectCopyMock = $this->getMock('Magento\Framework\Object\Copy', [], [], '', false);
4147
$this->orderPaymentBuilderMock = $this->getMock(
4248
'Magento\Sales\Api\Data\OrderPaymentDataBuilder',
@@ -61,10 +67,19 @@ public function setUp()
6167
public function testConvert()
6268
{
6369
$methodInterface = $this->getMock('Magento\Payment\Model\MethodInterface', [], [], '', false);
64-
$orderPayment = $this->getMock('Magento\Sales\Api\Data\OrderPaymentInterface', [], [], '', false);
70+
$orderPayment = $this->getMockForAbstractClass(
71+
'Magento\Sales\Api\Data\OrderPaymentInterface',
72+
[],
73+
'',
74+
false,
75+
true,
76+
true,
77+
['setCcNumber', 'setCcCid']
78+
);
6579
$paymentData = ['test' => 'test2'];
6680
$data = ['some_id' => 1];
6781
$paymentMethodTitle = 'TestTitle';
82+
$additionalInfo = ['token' => 'TOKEN-123'];
6883
$this->paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInterface);
6984
$methodInterface->expects($this->once())->method('getTitle')->willReturn($paymentMethodTitle);
7085
$this->objectCopyMock->expects($this->once())->method('getDataFromFieldset')->with(
@@ -77,11 +92,31 @@ public function testConvert()
7792
->with(array_merge($paymentData, $data))
7893
->willReturnSelf();
7994

95+
$this->paymentMock->expects($this->once())
96+
->method('getAdditionalInformation')
97+
->willReturn($additionalInfo);
98+
$ccNumber = 123456798;
99+
$ccCid = 1234;
100+
$this->paymentMock->expects($this->once())
101+
->method('getCcNumber')
102+
->willReturn($ccNumber);
103+
$this->paymentMock->expects($this->once())
104+
->method('getCcCid')
105+
->willReturn($ccCid);
106+
80107
$this->orderPaymentBuilderMock->expects($this->once())
81108
->method('setAdditionalInformation')
82-
->with(serialize([Substitution::INFO_KEY_TITLE => $paymentMethodTitle]))
109+
->with(serialize(array_merge($additionalInfo, [Substitution::INFO_KEY_TITLE => $paymentMethodTitle])))
83110
->willReturnSelf();
84111
$this->orderPaymentBuilderMock->expects($this->once())->method('create')->willReturn($orderPayment);
112+
$orderPayment->expects($this->once())
113+
->method('setCcNumber')
114+
->with($ccNumber)
115+
->willReturnSelf();
116+
$orderPayment->expects($this->once())
117+
->method('setCcCid')
118+
->with($ccCid)
119+
->willReturnSelf();
85120
$this->assertSame($orderPayment, $this->converter->convert($this->paymentMock, $data));
86121
}
87122
}

0 commit comments

Comments
 (0)