Skip to content

Commit

Permalink
Merge pull request #632 from magento-mpi/MPI-BUGFIXES
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Voskoboinikov, Dmytro(dvoskoboinikov) committed May 18, 2016
2 parents 901637a + 15876ad commit 3207334
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 65 deletions.
Expand Up @@ -24,7 +24,8 @@ define([
* {String}
*/
id: 'co-transparent-form-braintree'
}
},
isValidCardNumber: false
},

/**
Expand Down Expand Up @@ -113,11 +114,7 @@ define([
}

if (event.target.fieldKey === 'number' && event.card) {
if (event.isValid) {
self.cardNumber = event.card;
} else {
self.cardNumber = null;
}
self.isValidCardNumber = event.isValid;
self.selectedCardType(
validator.getMageCardType(event.card.type, self.getCcAvailableTypes())
);
Expand All @@ -137,7 +134,7 @@ define([

$selector.removeClass(invalidClass);

if (this.selectedCardType() === null) {
if (this.selectedCardType() === null || !this.isValidCardNumber) {
$(this.getSelector('cc_number')).addClass(invalidClass);

return false;
Expand Down
Expand Up @@ -25,9 +25,18 @@ define(
return true;
}

var form = $('.payment-method._active form[data-role=checkout-agreements]');
form.validation();
return form.validation('isValid');
return $('#co-payment-form').validate({
errorClass: 'mage-error',
errorElement: 'div',
meta: 'validate',
errorPlacement: function (error, element) {
var errorPlacement = element;
if (element.is(':checkbox') || element.is(':radio')) {
errorPlacement = element.siblings('label').last();
}
errorPlacement.after(error);
}
}).element('.payment-method._active div.checkout-agreements input');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Eav/Model/Entity/AbstractEntity.php
Expand Up @@ -35,7 +35,7 @@ abstract class AbstractEntity extends AbstractResource implements EntityInterfac
/**
* @var \Magento\Eav\Model\Entity\AttributeLoaderInterface
*/
private $attributeLoader;
protected $attributeLoader;

/**
* Connection name
Expand Down Expand Up @@ -1859,7 +1859,7 @@ protected function _isAttributeValueEmpty(AbstractAttribute $attribute, $value)
*
* @deprecated
*/
private function getAttributeLoader()
protected function getAttributeLoader()
{
if ($this->attributeLoader === null) {
$this->attributeLoader= ObjectManager::getInstance()->get(AttributeLoaderInterface::class);
Expand Down
Expand Up @@ -68,7 +68,8 @@ public function save(CartInterface $quote, ShippingAssignmentInterface $shipping
{
/** @var \Magento\Quote\Model\Quote $quote */
foreach ($shippingAssignment->getItems() as $item) {
if (!$quote->getItemById($item->getItemId())) {
/** @var \Magento\Quote\Model\Quote\Item $item */
if (!$quote->getItemById($item->getItemId()) && !$item->isDeleted()) {
$this->cartItemPersister->save($quote, $item);
}
}
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Quote/Model/QuoteRepository.php
Expand Up @@ -101,7 +101,6 @@ public function get($cartId, array $sharedStoreIds = [])
$quote = $this->loadQuote('load', 'cartId', $cartId, $sharedStoreIds);
$this->getLoadHandler()->load($quote);
$this->quotesById[$cartId] = $quote;
$this->quotesByCustomerId[$quote->getCustomerId()] = $quote;
}
return $this->quotesById[$cartId];
}
Expand Down
@@ -0,0 +1,111 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Test\Unit\Model\Quote\ShippingAssignment;

use Magento\Quote\Api\Data\ShippingAssignmentInterface;
use Magento\Quote\Api\Data\ShippingInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\ShippingAssignmentFactory;
use Magento\Quote\Model\Quote\Item\CartItemPersister;
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor;
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class ShippingAssignmentProcessorTest
*/
class ShippingAssignmentProcessorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ShippingAssignmentFactory|MockObject
*/
private $shippingAssignmentFactory;

/**
* @var ShippingProcessor|MockObject
*/
private $shippingProcessor;

/**
* @var CartItemPersister|MockObject
*/
private $cartItemPersister;

/**
* @var ShippingAssignmentProcessor
*/
private $shippingAssignmentProcessor;

protected function setUp()
{
$this->shippingAssignmentFactory = $this->getMockBuilder(ShippingAssignmentFactory::class)
->disableOriginalConstructor()
->getMock();

$this->shippingProcessor = $this->getMockBuilder(ShippingProcessor::class)
->disableOriginalConstructor()
->getMock();

$this->cartItemPersister = $this->getMockBuilder(CartItemPersister::class)
->disableOriginalConstructor()
->getMock();

$this->shippingAssignmentProcessor = new ShippingAssignmentProcessor(
$this->shippingAssignmentFactory,
$this->shippingProcessor,
$this->cartItemPersister
);
}

/**
* Test saving shipping assignments with deleted cart items
*
* @covers \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::save
*/
public function testSaveWithDeletedCartItems()
{
$shippingAssignment = $this->getMockForAbstractClass(ShippingAssignmentInterface::class);
$shipping = $this->getMockForAbstractClass(ShippingInterface::class);
$quoteId = 1;

$quote = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->getMock();
$quoteItem = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)
->disableOriginalConstructor()
->getMock();
$quoteItem->expects(static::once())
->method('isDeleted')
->willReturn(true);
$quoteItem->expects(static::once())
->method('getItemId')
->willReturn($quoteId);

$quote->expects(static::once())
->method('getItemById')
->with($quoteId)
->willReturn(null);

$shippingAssignment->expects(static::once())
->method('getItems')
->willReturn([$quoteItem]);
$shippingAssignment->expects(static::once())
->method('getShipping')
->willReturn($shipping);

$this->cartItemPersister->expects(static::never())
->method('save');

$this->shippingProcessor->expects(static::once())
->method('save')
->with($shipping, $quote);

$this->shippingAssignmentProcessor->save(
$quote,
$shippingAssignment
);
}
}
116 changes: 96 additions & 20 deletions app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php
Expand Up @@ -7,11 +7,13 @@

namespace Magento\Quote\Test\Unit\Model;

use Magento\Quote\Api\CartRepositoryInterface;

use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Quote\Model\QuoteRepository\LoadHandler;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
{
/**
Expand Down Expand Up @@ -54,6 +56,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
*/
private $extensionAttributesJoinProcessorMock;

/**
* @var LoadHandler|\PHPUnit_Framework_MockObject_MockObject
*/
private $loadHandlerMock;

protected function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
Expand Down Expand Up @@ -107,6 +114,12 @@ protected function setUp()
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock
]
);

$this->loadHandlerMock = $this->getMock(LoadHandler::class, [], [], '', false);
$reflection = new \ReflectionClass(get_class($this->model));
$reflectionProperty = $reflection->getProperty('loadHandler');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->model, $this->loadHandlerMock);
}

/**
Expand All @@ -132,21 +145,72 @@ public function testGetWithExceptionById()

public function testGet()
{
$this->markTestSkipped('MAGETWO-48531');
$cartId = 15;

$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
$this->storeMock->expects($this->once())->method('getId')->willReturn(1);
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
$this->quoteMock->expects($this->once())
$this->quoteFactoryMock->expects(static::once())
->method('create')
->willReturn($this->quoteMock);
$this->storeManagerMock->expects(static::once())
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects(static::once())
->method('getId')
->willReturn(1);
$this->quoteMock->expects(static::never())
->method('setSharedStoreIds');
$this->quoteMock->expects(static::once())
->method('load')
->with($cartId)
->willReturn($this->storeMock);
$this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
$this->quoteMock->expects(static::once())
->method('getId')
->willReturn($cartId);
$this->quoteMock->expects(static::never())
->method('getCustomerId');
$this->loadHandlerMock->expects(static::once())
->method('load')
->with($this->quoteMock);

static::assertEquals($this->quoteMock, $this->model->get($cartId));
static::assertEquals($this->quoteMock, $this->model->get($cartId));
}

public function testGetForCustomerAfterGet()
{
$cartId = 15;
$customerId = 23;

$this->quoteFactoryMock->expects(static::exactly(2))
->method('create')
->willReturn($this->quoteMock);
$this->storeManagerMock->expects(static::exactly(2))
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects(static::exactly(2))
->method('getId')
->willReturn(1);
$this->quoteMock->expects(static::never())
->method('setSharedStoreIds');
$this->quoteMock->expects(static::once())
->method('load')
->with($cartId)
->willReturn($this->storeMock);
$this->quoteMock->expects(static::once())
->method('loadByCustomer')
->with($customerId)
->willReturn($this->storeMock);
$this->quoteMock->expects(static::exactly(3))
->method('getId')
->willReturn($cartId);
$this->quoteMock->expects(static::any())
->method('getCustomerId')
->willReturn($customerId);
$this->loadHandlerMock->expects(static::exactly(2))
->method('load')
->with($this->quoteMock);

$this->assertEquals($this->quoteMock, $this->model->get($cartId));
$this->assertEquals($this->quoteMock, $this->model->get($cartId));
static::assertEquals($this->quoteMock, $this->model->get($cartId));
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
}

public function testGetWithSharedStoreIds()
Expand Down Expand Up @@ -174,22 +238,34 @@ public function testGetWithSharedStoreIds()

public function testGetForCustomer()
{
$this->markTestSkipped('MAGETWO-48531');
$cartId = 17;
$customerId = 23;

$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
$this->storeMock->expects($this->once())->method('getId')->willReturn(1);
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
$this->quoteMock->expects($this->once())
$this->quoteFactoryMock->expects(static::once())
->method('create')
->willReturn($this->quoteMock);
$this->storeManagerMock->expects(static::once())
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects(static::once())
->method('getId')
->willReturn(1);
$this->quoteMock->expects(static::never())
->method('setSharedStoreIds');
$this->quoteMock->expects(static::once())
->method('loadByCustomer')
->with($customerId)
->willReturn($this->storeMock);
$this->quoteMock->expects($this->exactly(2))->method('getId')->willReturn($cartId);
$this->quoteMock->expects(static::exactly(2))
->method('getId')
->willReturn($cartId);

$this->loadHandlerMock->expects(static::once())
->method('load')
->with($this->quoteMock);

$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/Block/Order/Totals.php
Expand Up @@ -164,7 +164,7 @@ protected function _initTotals()
$this->_totals['base_grandtotal'] = new \Magento\Framework\DataObject(
[
'code' => 'base_grandtotal',
'value' => $this->getOrder()->formatPrice($source->getGrandTotal()),
'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
'label' => __('Grand Total to be Charged'),
'is_formated' => true,
]
Expand Down
Expand Up @@ -243,6 +243,7 @@ protected function _processActionData($action = null)
$removeFrom = (string)$this->getRequest()->getPost('from');
if ($removeItemId && $removeFrom) {
$this->_getOrderCreateModel()->removeItem($removeItemId, $removeFrom);
$this->_getOrderCreateModel()->recollectCart();
}

/**
Expand Down

0 comments on commit 3207334

Please sign in to comment.