-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #618 from magento-south/BUGS
[South+MPI] Bugfixes
- Loading branch information
Showing
32 changed files
with
881 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\CustomerData\Plugin; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\App\Response\Http; | ||
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; | ||
use Magento\Framework\Stdlib\Cookie\PhpCookieManager; | ||
|
||
class SessionChecker | ||
{ | ||
/** | ||
* @var PhpCookieManager | ||
*/ | ||
private $cookieManager; | ||
|
||
/** | ||
* @var CookieMetadataFactory | ||
*/ | ||
private $cookieMetadataFactory; | ||
|
||
/** | ||
* @var Session | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param PhpCookieManager $cookieManager | ||
* @param CookieMetadataFactory $cookieMetadataFactory | ||
* @param Session $session | ||
*/ | ||
public function __construct( | ||
PhpCookieManager $cookieManager, | ||
CookieMetadataFactory $cookieMetadataFactory, | ||
Session $session | ||
) { | ||
$this->cookieManager = $cookieManager; | ||
$this->cookieMetadataFactory = $cookieMetadataFactory; | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Delete frontend session cookie if customer session is expired | ||
* | ||
* @param Http $response | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* @return void | ||
*/ | ||
public function beforeSendVary(Http $response) | ||
{ | ||
if (!$this->session->isLoggedIn()) { | ||
$metadata = $this->cookieMetadataFactory->createCookieMetadata(); | ||
$metadata->setPath('/'); | ||
$this->cookieManager->deleteCookie('mage-cache-sessid', $metadata); | ||
} | ||
} | ||
} |
197 changes: 197 additions & 0 deletions
197
app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Controller\Address; | ||
|
||
use Magento\Customer\Controller\Address\Delete; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class DeleteTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var Delete */ | ||
protected $model; | ||
|
||
/** @var \Magento\Framework\App\Action\Context */ | ||
protected $context; | ||
|
||
/** @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $sessionMock; | ||
|
||
/** @var \Magento\Framework\Data\Form\FormKey\Validator|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $validatorMock; | ||
|
||
/** @var \Magento\Customer\Api\AddressRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $addressRepositoryMock; | ||
|
||
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $request; | ||
|
||
/** @var \Magento\Customer\Api\Data\AddressInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $address; | ||
|
||
/** @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $messageManager; | ||
|
||
/** @var \Magento\Framework\Controller\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $resultRedirectFactory; | ||
|
||
/** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $resultRedirect; | ||
|
||
protected function setUp() | ||
{ | ||
$this->sessionMock = $this->getMockBuilder('Magento\Customer\Model\Session') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->validatorMock = $this->getMockBuilder('Magento\Framework\Data\Form\FormKey\Validator') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$formFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->addressRepositoryMock = $this->getMockBuilder('Magento\Customer\Api\AddressRepositoryInterface') | ||
->getMockForAbstractClass(); | ||
$addressInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterfaceFactory') | ||
->disableOriginalConstructor() | ||
->setMethods(['create']) | ||
->getMock(); | ||
$regionInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\RegionInterfaceFactory') | ||
->disableOriginalConstructor() | ||
->setMethods(['create']) | ||
->getMock(); | ||
$dataObjectProcessorMock = $this->getMockBuilder('Magento\Framework\Reflection\DataObjectProcessor') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$dataObjectHelperMock = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$forwardFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\ForwardFactory') | ||
->disableOriginalConstructor() | ||
->setMethods(['create']) | ||
->getMock(); | ||
$pageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface') | ||
->getMockForAbstractClass(); | ||
$this->address = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface') | ||
->getMockForAbstractClass(); | ||
$this->messageManager = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface') | ||
->getMockForAbstractClass(); | ||
$this->resultRedirectFactory = $this->getMockBuilder('Magento\Framework\Controller\Result\RedirectFactory') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->resultRedirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$objectManager = new ObjectManagerHelper($this); | ||
$this->context = $objectManager->getObject( | ||
'Magento\Framework\App\Action\Context', | ||
[ | ||
'request' => $this->request, | ||
'messageManager' => $this->messageManager, | ||
'resultRedirectFactory' => $this->resultRedirectFactory, | ||
] | ||
); | ||
|
||
$this->model = new Delete( | ||
$this->context, | ||
$this->sessionMock, | ||
$this->validatorMock, | ||
$formFactoryMock, | ||
$this->addressRepositoryMock, | ||
$addressInterfaceFactoryMock, | ||
$regionInterfaceFactoryMock, | ||
$dataObjectProcessorMock, | ||
$dataObjectHelperMock, | ||
$forwardFactoryMock, | ||
$pageFactoryMock | ||
); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$addressId = 1; | ||
$customerId = 2; | ||
|
||
$this->resultRedirectFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($this->resultRedirect); | ||
$this->request->expects($this->once()) | ||
->method('getParam') | ||
->with('id', false) | ||
->willReturn($addressId); | ||
$this->validatorMock->expects($this->once()) | ||
->method('validate') | ||
->with($this->request) | ||
->willReturn(true); | ||
$this->addressRepositoryMock->expects($this->once()) | ||
->method('getById') | ||
->with($addressId) | ||
->willReturn($this->address); | ||
$this->sessionMock->expects($this->once()) | ||
->method('getCustomerId') | ||
->willReturn($customerId); | ||
$this->address->expects($this->once()) | ||
->method('getCustomerId') | ||
->willReturn($customerId); | ||
$this->addressRepositoryMock->expects($this->once()) | ||
->method('deleteById') | ||
->with($addressId); | ||
$this->messageManager->expects($this->once()) | ||
->method('addSuccess') | ||
->with(__('You deleted the address.')); | ||
$this->resultRedirect->expects($this->once()) | ||
->method('setPath') | ||
->with('*/*/index') | ||
->willReturnSelf(); | ||
$this->assertSame($this->resultRedirect, $this->model->execute()); | ||
} | ||
|
||
public function testExecuteWithException() | ||
{ | ||
$addressId = 1; | ||
$customerId = 2; | ||
|
||
$this->resultRedirectFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($this->resultRedirect); | ||
$this->request->expects($this->once()) | ||
->method('getParam') | ||
->with('id', false) | ||
->willReturn($addressId); | ||
$this->validatorMock->expects($this->once()) | ||
->method('validate') | ||
->with($this->request) | ||
->willReturn(true); | ||
$this->addressRepositoryMock->expects($this->once()) | ||
->method('getById') | ||
->with($addressId) | ||
->willReturn($this->address); | ||
$this->sessionMock->expects($this->once()) | ||
->method('getCustomerId') | ||
->willReturn($customerId); | ||
$this->address->expects($this->once()) | ||
->method('getCustomerId') | ||
->willReturn(34); | ||
$exception = new \Exception('Exception'); | ||
$this->messageManager->expects($this->once()) | ||
->method('addError') | ||
->with(__('We can\'t delete the address right now.')) | ||
->willThrowException($exception); | ||
$this->messageManager->expects($this->once()) | ||
->method('addException') | ||
->with($exception, __('We can\'t delete the address right now.')); | ||
$this->resultRedirect->expects($this->once()) | ||
->method('setPath') | ||
->with('*/*/index') | ||
->willReturnSelf(); | ||
$this->assertSame($this->resultRedirect, $this->model->execute()); | ||
} | ||
} |
Oops, something went wrong.