Skip to content

Commit 6622e64

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into BugFestW6
2 parents 554f437 + 7b34fe2 commit 6622e64

File tree

23 files changed

+466
-425
lines changed

23 files changed

+466
-425
lines changed

app/code/Magento/Braintree/Model/Checkout.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ private function ignoreAddressValidation()
119119
*/
120120
protected function importAddressData($address, $exportedAddress)
121121
{
122-
$address->setStreet([$exportedAddress['streetAddress'], $exportedAddress['extendedAddress']]);
122+
$extendedAddress = isset($exportedAddress['extendedAddress']) ? $exportedAddress['extendedAddress'] : null;
123+
$address->setStreet([$exportedAddress['streetAddress'], $extendedAddress]);
123124
$address->setCity($exportedAddress['locality']);
124125
$address->setRegionCode($exportedAddress['region']);
125126
$address->setCountryId($exportedAddress['countryCodeAlpha2']);

app/code/Magento/Braintree/Test/Unit/Model/CheckoutTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public function testInitializeQuoteForReview(
214214
$this->model->initializeQuoteForReview($paymentMethodNonce, $details);
215215
}
216216

217+
/**
218+
* @return array
219+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
220+
*/
217221
public function initializeQuoteForReviewDataProvider()
218222
{
219223
return [
@@ -311,6 +315,48 @@ public function initializeQuoteForReviewDataProvider()
311315
'payerLastName' => self::LASTNAME,
312316
]
313317
],
318+
'without_shipping_extended_address' => [
319+
'payment_method_nonce' => 'nonce',
320+
'details' => [
321+
'email' => self::EMAIL,
322+
'firstName' => self::FIRSTNAME,
323+
'lastName' => self::LASTNAME,
324+
'shippingAddress' => [
325+
'streetAddress' => self::SHIPPING_STREET_ADDRESS,
326+
'locality' => self::SHIPPING_LOCALITY,
327+
'region' => self::SHIPPING_REGION,
328+
'countryCodeAlpha2' => self::SHIPPING_COUNTRY_CODE,
329+
'postalCode' => self::SHIPPING_POSTAL_CODE,
330+
],
331+
],
332+
'expected_shipping' => [
333+
'setFirstname' => self::FIRSTNAME,
334+
'setLastname' => self::LASTNAME,
335+
'setEmail' => self::EMAIL,
336+
'setCollectShippingRates' => true,
337+
'setStreet' => [self::SHIPPING_STREET_ADDRESS, null],
338+
'setCity' => self::SHIPPING_LOCALITY,
339+
'setRegionCode' => self::SHIPPING_REGION,
340+
'setCountryId' => self::SHIPPING_COUNTRY_CODE,
341+
'setPostCode' => self::SHIPPING_POSTAL_CODE,
342+
],
343+
'expected_billing' => [
344+
'setFirstname' => self::FIRSTNAME,
345+
'setLastname' => self::LASTNAME,
346+
'setEmail' => self::EMAIL,
347+
'setStreet' => [self::SHIPPING_STREET_ADDRESS, null],
348+
'setCity' => self::SHIPPING_LOCALITY,
349+
'setRegionCode' => self::SHIPPING_REGION,
350+
'setCountryId' => self::SHIPPING_COUNTRY_CODE,
351+
'setPostCode' => self::SHIPPING_POSTAL_CODE,
352+
],
353+
'expected_payment_additional_info' => [
354+
'payment_method_nonce' => 'nonce',
355+
'payerEmail' => self::EMAIL,
356+
'payerFirstName' => self::FIRSTNAME,
357+
'payerLastName' => self::LASTNAME,
358+
]
359+
],
314360
];
315361
}
316362
}

app/code/Magento/Paypal/Controller/Hostedpro/Cancel.php

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,38 @@
66
*/
77
namespace Magento\Paypal\Controller\Hostedpro;
88

9+
use Magento\Framework\App\Action\Context;
10+
use Magento\Paypal\Helper\Checkout;
11+
912
class Cancel extends \Magento\Framework\App\Action\Action
1013
{
1114
/**
12-
* @var \Magento\Checkout\Model\Session
15+
* @var Checkout
1316
*/
14-
protected $_session;
17+
private $checkoutHelper;
1518

1619
/**
17-
* @param \Magento\Framework\App\Action\Context $context
18-
* @param \Magento\Checkout\Model\Session $session
20+
* @param Context $context
21+
* @param Checkout $checkoutHelper
1922
*/
2023
public function __construct(
21-
\Magento\Framework\App\Action\Context $context,
22-
\Magento\Checkout\Model\Session $session
24+
Context $context,
25+
Checkout $checkoutHelper
2326
) {
2427
parent::__construct($context);
25-
$this->_session = $session;
28+
$this->checkoutHelper = $checkoutHelper;
2629
}
2730

2831
/**
29-
* Cancel order, return quote to customer
30-
*
31-
* @param string $errorMsg
32-
* @return false|string
33-
*/
34-
protected function _cancelPayment($errorMsg = '')
35-
{
36-
$gotoSection = false;
37-
$helper = $this->_objectManager->get('Magento\Paypal\Helper\Checkout');
38-
$helper->cancelCurrentOrder($errorMsg);
39-
if ($this->_session->restoreQuote()) {
40-
$gotoSection = 'paymentMethod';
41-
}
42-
43-
return $gotoSection;
44-
}
45-
46-
/**
47-
* When a customer cancel payment from gateway.
32+
* Customer canceled payment on gateway side.
4833
*
4934
* @return void
5035
*/
5136
public function execute()
5237
{
53-
$this->_view->loadLayout(false);
54-
$gotoSection = $this->_cancelPayment();
55-
$redirectBlock = $this->_view->getLayout()->getBlock('hosted.pro.iframe');
56-
$redirectBlock->setGotoSection($gotoSection);
57-
//TODO: clarify return logic whether customer will be returned in iframe or in parent window
58-
$this->_view->renderLayout();
38+
$this->checkoutHelper->cancelCurrentOrder('');
39+
$this->checkoutHelper->restoreQuote();
40+
41+
$this->_redirect('checkout', ['_fragment' => 'payment']);
5942
}
6043
}

app/code/Magento/Paypal/Helper/Checkout.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
*/
66
namespace Magento\Paypal\Helper;
77

8+
use Magento\Sales\Model\Order;
9+
810
/**
911
* Checkout workflow helper
1012
*/
1113
class Checkout
1214
{
1315
/**
14-
* @var \Magento\Checkout\Model\SessionFactory
16+
* @var \Magento\Checkout\Model\Session
1517
*/
16-
protected $_session;
18+
protected $session;
1719

1820
/**
1921
* @param \Magento\Checkout\Model\Session $session
2022
*/
2123
public function __construct(
2224
\Magento\Checkout\Model\Session $session
2325
) {
24-
$this->_session = $session;
26+
$this->session = $session;
2527
}
2628

2729
/**
@@ -32,11 +34,21 @@ public function __construct(
3234
*/
3335
public function cancelCurrentOrder($comment)
3436
{
35-
$order = $this->_session->getLastRealOrder();
36-
if ($order->getId() && $order->getState() != \Magento\Sales\Model\Order::STATE_CANCELED) {
37+
$order = $this->session->getLastRealOrder();
38+
if ($order->getId() && $order->getState() != Order::STATE_CANCELED) {
3739
$order->registerCancellation($comment)->save();
3840
return true;
3941
}
4042
return false;
4143
}
44+
45+
/**
46+
* Restores quote
47+
*
48+
* @return bool
49+
*/
50+
public function restoreQuote()
51+
{
52+
return $this->session->restoreQuote();
53+
}
4254
}

app/code/Magento/Paypal/Test/Unit/Helper/CheckoutTest.php

Lines changed: 71 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,105 +9,95 @@
99
*/
1010
namespace Magento\Paypal\Test\Unit\Helper;
1111

12+
use Magento\Checkout\Model\Session;
13+
use Magento\Paypal\Helper\Checkout;
14+
use Magento\Sales\Model\Order;
15+
1216
class CheckoutTest extends \PHPUnit_Framework_TestCase
1317
{
1418
/**
15-
* @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject
19+
* @var Session|\PHPUnit_Framework_MockObject_MockObject
1620
*/
17-
protected $_session;
21+
private $session;
1822

1923
/**
20-
* @var \Magento\Quote\Model\QuoteFactory|\PHPUnit_Framework_MockObject_MockObject
24+
* @var Checkout
2125
*/
22-
protected $_quoteFactory;
26+
private $checkout;
2327

24-
/**
25-
* @var \Magento\Paypal\Helper\Checkout
26-
*/
27-
protected $_checkout;
28-
29-
/**
30-
* Sets up the fixture, for example, opens a network connection.
31-
* This method is called before a test is executed.
32-
*/
3328
protected function setUp()
3429
{
35-
$this->_session = $this->getMockBuilder(
36-
'Magento\Checkout\Model\Session'
37-
)->disableOriginalConstructor()->setMethods(
38-
['getLastRealOrder', 'replaceQuote', 'unsLastRealOrderId', '__wakeup']
39-
)->getMock();
40-
$this->_quoteFactory = $this->getMockBuilder(
41-
'Magento\Quote\Model\QuoteFactory'
42-
)->disableOriginalConstructor()->setMethods(
43-
['create', '__wakeup']
44-
)->getMock();
45-
46-
$this->_checkout = new \Magento\Paypal\Helper\Checkout($this->_session, $this->_quoteFactory);
30+
$this->session = $this->getMockBuilder(Session::class)
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$this->checkout = new Checkout($this->session);
4735
}
4836

49-
/**
50-
* Get order mock
51-
*
52-
* @param bool $hasOrderId
53-
* @param array $mockMethods
54-
* @return \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject
55-
*/
56-
protected function _getOrderMock($hasOrderId, $mockMethods = [])
37+
public function testCancelCurrentOrder()
5738
{
58-
$order = $this->getMockBuilder(
59-
'Magento\Sales\Model\Order'
60-
)->disableOriginalConstructor()->setMethods(
61-
array_merge(['getId', '__wakeup'], $mockMethods)
62-
)->getMock();
63-
$order->expects($this->once())->method('getId')->will($this->returnValue($hasOrderId ? 'order id' : null));
64-
return $order;
39+
$id = 1;
40+
$state = Order::STATE_PENDING_PAYMENT;
41+
$comment = 'Bla Bla';
42+
43+
$order = $this->getMockBuilder(Order::class)
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
$this->session->expects(static::once())
48+
->method('getLastRealOrder')
49+
->willReturn($order);
50+
$order->expects(static::once())
51+
->method('getId')
52+
->willReturn($id);
53+
$order->expects(static::once())
54+
->method('getState')
55+
->willReturn($state);
56+
$order->expects(static::once())
57+
->method('registerCancellation')
58+
->with($comment)
59+
->willReturnSelf();
60+
$order->expects(static::once())
61+
->method('save');
62+
63+
static::assertTrue($this->checkout->cancelCurrentOrder($comment));
6564
}
6665

67-
/**
68-
* @param bool $hasOrderId
69-
* @param bool $isOrderCancelled
70-
* @param bool $expectedResult
71-
* @dataProvider cancelCurrentOrderDataProvider
72-
*/
73-
public function testCancelCurrentOrder($hasOrderId, $isOrderCancelled, $expectedResult)
66+
public function testCancelCurrentOrderWhichIsCancelled()
7467
{
75-
$comment = 'Some test comment';
76-
$order = $this->_getOrderMock($hasOrderId, ['registerCancellation', 'save']);
77-
$order->setData(
78-
'state',
79-
$isOrderCancelled ? \Magento\Sales\Model\Order::STATE_CANCELED : 'some another state'
80-
);
81-
if ($expectedResult) {
82-
$order->expects(
83-
$this->once()
84-
)->method(
85-
'registerCancellation'
86-
)->with(
87-
$this->equalTo($comment)
88-
)->will(
89-
$this->returnSelf()
90-
);
91-
$order->expects($this->once())->method('save');
92-
} else {
93-
$order->expects($this->never())->method('registerCancellation');
94-
$order->expects($this->never())->method('save');
95-
}
96-
97-
$this->_session->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($order));
98-
$this->assertEquals($expectedResult, $this->_checkout->cancelCurrentOrder($comment));
68+
$id = 1;
69+
$state = Order::STATE_CANCELED;
70+
$comment = 'Bla Bla';
71+
72+
$order = $this->getMockBuilder(Order::class)
73+
->disableOriginalConstructor()
74+
->getMock();
75+
76+
$this->session->expects(static::once())
77+
->method('getLastRealOrder')
78+
->willReturn($order);
79+
$order->expects(static::once())
80+
->method('getId')
81+
->willReturn($id);
82+
$order->expects(static::once())
83+
->method('getState')
84+
->willReturn($state);
85+
$order->expects(static::never())
86+
->method('registerCancellation')
87+
->with($comment)
88+
->willReturnSelf();
89+
$order->expects(static::never())
90+
->method('save');
91+
92+
static::assertFalse($this->checkout->cancelCurrentOrder($comment));
9993
}
10094

101-
/**
102-
* @return array
103-
*/
104-
public function cancelCurrentOrderDataProvider()
95+
public function testRestoreQuote()
10596
{
106-
return [
107-
[true, false, true],
108-
[true, true, false],
109-
[false, true, false],
110-
[false, false, false]
111-
];
97+
$this->session->expects(static::once())
98+
->method('restoreQuote')
99+
->willReturn(true);
100+
101+
static::assertTrue($this->checkout->restoreQuote());
112102
}
113103
}

app/code/Magento/Paypal/view/frontend/layout/paypal_hostedpro_cancel.xml

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

0 commit comments

Comments
 (0)