-
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 #554 from magento-south/BUGS
[SOUTH] Bugfixes
- Loading branch information
Showing
30 changed files
with
377 additions
and
49 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
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
40 changes: 40 additions & 0 deletions
40
app/code/Magento/Customer/Model/ResourceModel/Db/VersionControl/AddressSnapshot.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,40 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Model\ResourceModel\Db\VersionControl; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot; | ||
|
||
class AddressSnapshot extends Snapshot | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isModified(DataObject $entity) | ||
{ | ||
$result = parent::isModified($entity); | ||
|
||
if (!$result | ||
&& !$entity->getIsCustomerSaveTransaction() | ||
&& $this->isAddressDefault($entity) | ||
) { | ||
return true; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Checks if address has chosen as default and has had an id | ||
* | ||
* @param DataObject $entity | ||
* @return bool | ||
*/ | ||
private function isAddressDefault(DataObject $entity) | ||
{ | ||
return $entity->getId() && ($entity->getIsDefaultBilling() || $entity->getIsDefaultShipping()); | ||
} | ||
} |
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
129 changes: 129 additions & 0 deletions
129
.../Magento/Customer/Test/Unit/Model/ResourceModel/Db/VersionControl/AddressSnapshotTest.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,129 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Db\VersionControl; | ||
|
||
use Magento\Customer\Model\ResourceModel\Db\VersionControl\AddressSnapshot; | ||
|
||
class AddressSnapshotTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var AddressSnapshot | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \Magento\Framework\Model\ResourceModel\Db\VersionControl\Metadata|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $metadataMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->metadataMock = $this->getMockBuilder('Magento\Framework\Model\ResourceModel\Db\VersionControl\Metadata') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new AddressSnapshot( | ||
$this->metadataMock | ||
); | ||
} | ||
|
||
/** | ||
* @param bool $isCustomerSaveTransaction | ||
* @param int $isDefaultBilling | ||
* @param int $isDefaultShipping | ||
* @param bool $expected | ||
* @dataProvider dataProviderIsModified | ||
*/ | ||
public function testIsModified( | ||
$isCustomerSaveTransaction, | ||
$isDefaultBilling, | ||
$isDefaultShipping, | ||
$expected | ||
) { | ||
$entityId = 1; | ||
|
||
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject') | ||
->disableOriginalConstructor() | ||
->setMethods([ | ||
'getId', | ||
'getData', | ||
'getDataByKey', | ||
'getIsDefaultBilling', | ||
'getIsDefaultShipping', | ||
'getIsCustomerSaveTransaction', | ||
]) | ||
->getMock(); | ||
|
||
$dataObjectMock->expects($this->any()) | ||
->method('getId') | ||
->willReturn($entityId); | ||
$dataObjectMock->expects($this->once()) | ||
->method('getData') | ||
->willReturn(['is_billing_address' => 1]); | ||
$dataObjectMock->expects($this->once()) | ||
->method('getDataByKey') | ||
->with('is_billing_address') | ||
->willReturn(1); | ||
$dataObjectMock->expects($this->once()) | ||
->method('getIsCustomerSaveTransaction') | ||
->willReturn($isCustomerSaveTransaction); | ||
$dataObjectMock->expects($this->any()) | ||
->method('getIsDefaultBilling') | ||
->willReturn($isDefaultBilling); | ||
$dataObjectMock->expects($this->any()) | ||
->method('getIsDefaultShipping') | ||
->willReturn($isDefaultShipping); | ||
|
||
$this->metadataMock->expects($this->once()) | ||
->method('getFields') | ||
->with($dataObjectMock) | ||
->willReturn(['is_billing_address' => null]); | ||
|
||
$this->model->registerSnapshot($dataObjectMock); | ||
|
||
$this->assertEquals($expected, $this->model->isModified($dataObjectMock)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function dataProviderIsModified() | ||
{ | ||
return [ | ||
[false, 1, 1, true], | ||
[true, 0, 0, false], | ||
[false, 1, 0, true], | ||
[false, 0, 1, true], | ||
]; | ||
} | ||
|
||
public function testIsModifiedBypass() | ||
{ | ||
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject') | ||
->disableOriginalConstructor() | ||
->setMethods([ | ||
'getId', | ||
'getData', | ||
]) | ||
->getMock(); | ||
|
||
$dataObjectMock->expects($this->any()) | ||
->method('getId') | ||
->willReturn(null); | ||
$dataObjectMock->expects($this->once()) | ||
->method('getData') | ||
->willReturn(['is_billing_address' => 1]); | ||
|
||
$this->metadataMock->expects($this->once()) | ||
->method('getFields') | ||
->with($dataObjectMock) | ||
->willReturn(['is_billing_address' => null]); | ||
|
||
$this->model->registerSnapshot($dataObjectMock); | ||
|
||
$this->assertEquals(true, $this->model->isModified($dataObjectMock)); | ||
} | ||
} |
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
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
Oops, something went wrong.