Skip to content

Commit fe3bf09

Browse files
committed
Merge pull request #618 from magento-south/BUGS
[South+MPI] Bugfixes
2 parents e1bd045 + 42c8bab commit fe3bf09

File tree

32 files changed

+881
-191
lines changed

32 files changed

+881
-191
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@ define(
2525
serviceUrl = resourceUrlManager.getUrlForEstimationShippingMethodsForNewAddress(quote),
2626
payload = JSON.stringify({
2727
address: {
28-
country_id: address.countryId,
29-
region_id: address.regionId,
30-
region: address.region,
31-
postcode: address.postcode
28+
'street': address.street,
29+
'city': address.city,
30+
'region_id': address.regionId,
31+
'region': address.region,
32+
'country_id': address.countryId,
33+
'postcode': address.postcode,
34+
'email': address.email,
35+
'customer_id': address.customerId,
36+
'firstname': address.firstname,
37+
'lastname': address.lastname,
38+
'middlename': address.middlename,
39+
'prefix': address.prefix,
40+
'suffix': address.suffix,
41+
'vat_id': address.vatId,
42+
'company': address.company,
43+
'telephone': address.telephone,
44+
'fax': address.fax,
45+
'custom_attributes': address.customAttributes,
46+
'save_in_address_book': address.saveInAddressBook
3247
}
3348
}
3449
);

app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ public function setType(\Magento\Framework\DataObject $type)
9191
}
9292

9393
/**
94-
* @param AbstractAddress|null $address
94+
* @param AddressModelInterface|null $address
9595
* @return string
9696
* All new code should use renderArray based on Metadata service
9797
*/
98-
public function getFormat(AbstractAddress $address = null)
98+
public function getFormat(AddressModelInterface $address = null)
9999
{
100100
$countryFormat = $address === null
101101
? false : $address->getCountryModel()->getFormat(

app/code/Magento/Customer/Controller/Address/Delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function execute()
1515
{
1616
$addressId = $this->getRequest()->getParam('id', false);
1717

18-
if ($addressId) {
18+
if ($addressId && $this->_formKeyValidator->validate($this->getRequest())) {
1919
try {
2020
$address = $this->_addressRepository->getById($addressId);
2121
if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\CustomerData\Plugin;
7+
8+
use Magento\Customer\Model\Session;
9+
use Magento\Framework\App\Response\Http;
10+
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
11+
use Magento\Framework\Stdlib\Cookie\PhpCookieManager;
12+
13+
class SessionChecker
14+
{
15+
/**
16+
* @var PhpCookieManager
17+
*/
18+
private $cookieManager;
19+
20+
/**
21+
* @var CookieMetadataFactory
22+
*/
23+
private $cookieMetadataFactory;
24+
25+
/**
26+
* @var Session
27+
*/
28+
private $session;
29+
30+
/**
31+
* @param PhpCookieManager $cookieManager
32+
* @param CookieMetadataFactory $cookieMetadataFactory
33+
* @param Session $session
34+
*/
35+
public function __construct(
36+
PhpCookieManager $cookieManager,
37+
CookieMetadataFactory $cookieMetadataFactory,
38+
Session $session
39+
) {
40+
$this->cookieManager = $cookieManager;
41+
$this->cookieMetadataFactory = $cookieMetadataFactory;
42+
$this->session = $session;
43+
}
44+
45+
/**
46+
* Delete frontend session cookie if customer session is expired
47+
*
48+
* @param Http $response
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
50+
* @return void
51+
*/
52+
public function beforeSendVary(Http $response)
53+
{
54+
if (!$this->session->isLoggedIn()) {
55+
$metadata = $this->cookieMetadataFactory->createCookieMetadata();
56+
$metadata->setPath('/');
57+
$this->cookieManager->deleteCookie('mage-cache-sessid', $metadata);
58+
}
59+
}
60+
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Controller\Address;
7+
8+
use Magento\Customer\Controller\Address\Delete;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
/**
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
14+
class DeleteTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/** @var Delete */
17+
protected $model;
18+
19+
/** @var \Magento\Framework\App\Action\Context */
20+
protected $context;
21+
22+
/** @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
23+
protected $sessionMock;
24+
25+
/** @var \Magento\Framework\Data\Form\FormKey\Validator|\PHPUnit_Framework_MockObject_MockObject */
26+
protected $validatorMock;
27+
28+
/** @var \Magento\Customer\Api\AddressRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
29+
protected $addressRepositoryMock;
30+
31+
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
32+
protected $request;
33+
34+
/** @var \Magento\Customer\Api\Data\AddressInterface|\PHPUnit_Framework_MockObject_MockObject */
35+
protected $address;
36+
37+
/** @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
38+
protected $messageManager;
39+
40+
/** @var \Magento\Framework\Controller\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */
41+
protected $resultRedirectFactory;
42+
43+
/** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */
44+
protected $resultRedirect;
45+
46+
protected function setUp()
47+
{
48+
$this->sessionMock = $this->getMockBuilder('Magento\Customer\Model\Session')
49+
->disableOriginalConstructor()
50+
->getMock();
51+
$this->validatorMock = $this->getMockBuilder('Magento\Framework\Data\Form\FormKey\Validator')
52+
->disableOriginalConstructor()
53+
->getMock();
54+
$formFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory')
55+
->disableOriginalConstructor()
56+
->getMock();
57+
$this->addressRepositoryMock = $this->getMockBuilder('Magento\Customer\Api\AddressRepositoryInterface')
58+
->getMockForAbstractClass();
59+
$addressInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterfaceFactory')
60+
->disableOriginalConstructor()
61+
->setMethods(['create'])
62+
->getMock();
63+
$regionInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\RegionInterfaceFactory')
64+
->disableOriginalConstructor()
65+
->setMethods(['create'])
66+
->getMock();
67+
$dataObjectProcessorMock = $this->getMockBuilder('Magento\Framework\Reflection\DataObjectProcessor')
68+
->disableOriginalConstructor()
69+
->getMock();
70+
$dataObjectHelperMock = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper')
71+
->disableOriginalConstructor()
72+
->getMock();
73+
$forwardFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\ForwardFactory')
74+
->disableOriginalConstructor()
75+
->setMethods(['create'])
76+
->getMock();
77+
$pageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
78+
->disableOriginalConstructor()
79+
->getMock();
80+
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
81+
->getMockForAbstractClass();
82+
$this->address = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface')
83+
->getMockForAbstractClass();
84+
$this->messageManager = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface')
85+
->getMockForAbstractClass();
86+
$this->resultRedirectFactory = $this->getMockBuilder('Magento\Framework\Controller\Result\RedirectFactory')
87+
->disableOriginalConstructor()
88+
->getMock();
89+
$this->resultRedirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect')
90+
->disableOriginalConstructor()
91+
->getMock();
92+
93+
$objectManager = new ObjectManagerHelper($this);
94+
$this->context = $objectManager->getObject(
95+
'Magento\Framework\App\Action\Context',
96+
[
97+
'request' => $this->request,
98+
'messageManager' => $this->messageManager,
99+
'resultRedirectFactory' => $this->resultRedirectFactory,
100+
]
101+
);
102+
103+
$this->model = new Delete(
104+
$this->context,
105+
$this->sessionMock,
106+
$this->validatorMock,
107+
$formFactoryMock,
108+
$this->addressRepositoryMock,
109+
$addressInterfaceFactoryMock,
110+
$regionInterfaceFactoryMock,
111+
$dataObjectProcessorMock,
112+
$dataObjectHelperMock,
113+
$forwardFactoryMock,
114+
$pageFactoryMock
115+
);
116+
}
117+
118+
public function testExecute()
119+
{
120+
$addressId = 1;
121+
$customerId = 2;
122+
123+
$this->resultRedirectFactory->expects($this->once())
124+
->method('create')
125+
->willReturn($this->resultRedirect);
126+
$this->request->expects($this->once())
127+
->method('getParam')
128+
->with('id', false)
129+
->willReturn($addressId);
130+
$this->validatorMock->expects($this->once())
131+
->method('validate')
132+
->with($this->request)
133+
->willReturn(true);
134+
$this->addressRepositoryMock->expects($this->once())
135+
->method('getById')
136+
->with($addressId)
137+
->willReturn($this->address);
138+
$this->sessionMock->expects($this->once())
139+
->method('getCustomerId')
140+
->willReturn($customerId);
141+
$this->address->expects($this->once())
142+
->method('getCustomerId')
143+
->willReturn($customerId);
144+
$this->addressRepositoryMock->expects($this->once())
145+
->method('deleteById')
146+
->with($addressId);
147+
$this->messageManager->expects($this->once())
148+
->method('addSuccess')
149+
->with(__('You deleted the address.'));
150+
$this->resultRedirect->expects($this->once())
151+
->method('setPath')
152+
->with('*/*/index')
153+
->willReturnSelf();
154+
$this->assertSame($this->resultRedirect, $this->model->execute());
155+
}
156+
157+
public function testExecuteWithException()
158+
{
159+
$addressId = 1;
160+
$customerId = 2;
161+
162+
$this->resultRedirectFactory->expects($this->once())
163+
->method('create')
164+
->willReturn($this->resultRedirect);
165+
$this->request->expects($this->once())
166+
->method('getParam')
167+
->with('id', false)
168+
->willReturn($addressId);
169+
$this->validatorMock->expects($this->once())
170+
->method('validate')
171+
->with($this->request)
172+
->willReturn(true);
173+
$this->addressRepositoryMock->expects($this->once())
174+
->method('getById')
175+
->with($addressId)
176+
->willReturn($this->address);
177+
$this->sessionMock->expects($this->once())
178+
->method('getCustomerId')
179+
->willReturn($customerId);
180+
$this->address->expects($this->once())
181+
->method('getCustomerId')
182+
->willReturn(34);
183+
$exception = new \Exception('Exception');
184+
$this->messageManager->expects($this->once())
185+
->method('addError')
186+
->with(__('We can\'t delete the address right now.'))
187+
->willThrowException($exception);
188+
$this->messageManager->expects($this->once())
189+
->method('addException')
190+
->with($exception, __('We can\'t delete the address right now.'));
191+
$this->resultRedirect->expects($this->once())
192+
->method('setPath')
193+
->with('*/*/index')
194+
->willReturnSelf();
195+
$this->assertSame($this->resultRedirect, $this->model->execute());
196+
}
197+
}

0 commit comments

Comments
 (0)