Skip to content

Commit ad1059f

Browse files
Adding coverage test cases, fixing Order/Payment/Info that had the same problem.
1 parent 77390c1 commit ad1059f

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

app/code/Magento/Sales/Model/Order/Payment/Info.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public function getAdditionalInformation($key = null)
192192
*/
193193
public function unsAdditionalInformation($key = null)
194194
{
195+
$this->initAdditionalInformation();
195196
if ($key && isset($this->additionalInformation[$key])) {
196197
unset($this->additionalInformation[$key]);
197198
return $this->setData('additional_information', $this->additionalInformation);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Model;
7+
8+
use Magento\Sales\Model\Order;
9+
use Magento\Quote\Model\Quote;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\TestFramework\ObjectManager;
12+
13+
/**
14+
* @magentoAppArea adminhtml
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
17+
class PaymentInfoTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var ObjectManager
21+
*/
22+
protected $_objectManager;
23+
24+
/**
25+
* @var Order
26+
*/
27+
protected $_order;
28+
29+
/** @var Quote */
30+
protected $_quote;
31+
32+
protected function setUp()
33+
{
34+
$this->_objectManager = Bootstrap::getObjectManager();
35+
$this->_order = $this->_objectManager->create(
36+
Order::class
37+
);
38+
$this->_quote = $this->_objectManager->create(
39+
Quote::class
40+
);
41+
}
42+
43+
/**
44+
* @magentoDbIsolation enabled
45+
* @magentoAppIsolation enabled
46+
* @magentoDataFixture Magento/Payment/_files/payment_info.php
47+
*/
48+
public function testUnsetPaymentInformation()
49+
{
50+
$order = $this->_order->loadByIncrementId('100000001');
51+
/** @var \Magento\Sales\Model\Order\Payment $paymentOrder */
52+
$paymentOrder = $order->getPayment();
53+
$paymentOrder->unsAdditionalInformation('testing');
54+
55+
$quote = $this->_quote->load('reserved_order_id', 'reserved_order_id');
56+
/** @var \Magento\Quote\Model\Quote\Payment $paymentQuote */
57+
$paymentQuote = $quote->getPayment();
58+
$paymentQuote->unsAdditionalInformation('testing');
59+
60+
61+
$this->assertFalse($paymentOrder->hasAdditionalInformation('testing'));
62+
$this->assertFalse($paymentQuote->hasAdditionalInformation('testing'));
63+
}
64+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Quote\Api\CartRepositoryInterface;
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Sales\Model\Order\Address;
10+
use Magento\Sales\Model\Order\Payment;
11+
use Magento\Paypal\Model\Config;
12+
use Magento\Sales\Model\Order;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Quote\Model\Quote\Payment as PaymentQuote;
15+
16+
/** @var $objectManager \Magento\TestFramework\ObjectManager */
17+
$objectManager = Bootstrap::getObjectManager();
18+
19+
$addressData = [
20+
'firstname' => 'guest',
21+
'lastname' => 'guest',
22+
'email' => '[email protected]',
23+
'street' => 'street',
24+
'city' => 'Los Angeles',
25+
'region' => 'CA',
26+
'postcode' => '1',
27+
'country_id' => 'US',
28+
'telephone' => '1'
29+
];
30+
$billingAddress = $objectManager->create(
31+
Address::class,
32+
['data' => $addressData]
33+
);
34+
$billingAddress->setAddressType('billing');
35+
$shippingAddress = clone $billingAddress;
36+
$shippingAddress->setId(null)->setAddressType('shipping');
37+
38+
/** @var Payment $paymentOrder */
39+
$paymentOrder = $objectManager->create(
40+
Payment::class
41+
);
42+
43+
$paymentOrder->setMethod(Config::METHOD_WPP_EXPRESS);
44+
$paymentOrder->setAdditionalInformation('testing', 'testing additional data');
45+
46+
$amount = 100;
47+
48+
/** @var Order $order */
49+
$order = $objectManager->create(Order::class);
50+
$order->setCustomerEmail('[email protected]')
51+
->setIncrementId('100000001')
52+
->setSubtotal($amount)
53+
->setBaseSubtotal($amount)
54+
->setBaseGrandTotal($amount)
55+
->setGrandTotal($amount)
56+
->setBaseCurrencyCode('USD')
57+
->setCustomerIsGuest(true)
58+
->setStoreId(1)
59+
->setEmailSent(true)
60+
->setBillingAddress($billingAddress)
61+
->setShippingAddress($shippingAddress)
62+
->setPayment($paymentOrder);
63+
$order->save();
64+
65+
66+
67+
/** @var Quote $quote */
68+
$quote = $objectManager->create(Quote::class);
69+
$quote->setStoreId(1)
70+
->setIsActive(true)
71+
->setIsMultiShipping(false)
72+
->setReservedOrderId('reserved_order_id');
73+
74+
$quote->getPayment()
75+
->setMethod(Config::METHOD_WPP_EXPRESS)
76+
->setAdditionalInformation('testing', 'testing additional data');
77+
78+
$quote->collectTotals();
79+
80+
81+
/** @var CartRepositoryInterface $repository */
82+
$repository = $objectManager->get(CartRepositoryInterface::class);
83+
$repository->save($quote);

0 commit comments

Comments
 (0)