From 938fcfa8e14731d3177e72dd066e86fba138e907 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 22 Apr 2016 14:38:12 +0300 Subject: [PATCH 01/15] MAGETWO-52216: [Github] Shipping Tracking Number can't be deleted via API - Fixed incorrect action for entity delete method --- .../Code/Generator/Persistor.php | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Persistor.php b/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Persistor.php index 5c7e80e7b3467..14825ffd0f5a0 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Persistor.php +++ b/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Persistor.php @@ -282,11 +282,11 @@ protected function _getLoadEntityMethod() */ protected function _getRegisterDeletedMethod() { - $body = "\$hash = spl_object_hash(\$entity);" - . "array_push(\$this->stack, \$hash);" - . "\$this->entitiesPool[\$hash] = [" - . " 'entity' => \$entity," - . " 'action' => 'removed'" + $body = "\$hash = spl_object_hash(\$entity);\n" + . "array_push(\$this->stack, \$hash);\n" + . "\$this->entitiesPool[\$hash] = [\n" + . " 'entity' => \$entity,\n" + . " 'action' => 'removed'\n" . "];"; return [ 'name' => 'registerDeleted', @@ -321,12 +321,13 @@ protected function _getDoPersistMethod() . " \$hash = array_pop(\$this->stack);\n" . " if (isset(\$this->entitiesPool[\$hash])) {\n" . " \$data = \$this->entitiesPool[\$hash];\n" + . " \$entity = \$data['entity'];\n" . " if (\$data['action'] == 'created') {\n" - . " \$this->{$this->_getSourceResourcePropertyName()}->save(\$data['entity']);\n" - . " \$ids[] = \$data['entity']->getId();\n" + . " \$this->{$this->_getSourceResourcePropertyName()}->save(\$entity);\n" + . " \$ids[] = \$entity->getId();\n" . " } else {\n" - . " \$ids[] = \$data['entity']->getId();\n" - . " \$this->{$this->_getSourceResourcePropertyName()}->delete(\$data['removed']);\n" + . " \$ids[] = \$entity->getId();\n" + . " \$this->{$this->_getSourceResourcePropertyName()}->delete(\$entity);\n" . " }\n" . " }\n" . " unset(\$this->entitiesPool[\$hash]);\n" @@ -372,14 +373,16 @@ protected function _getDoPersistMethod() protected function _getDoPersistEntityMethod() { $body = "\$hash = spl_object_hash(\$entity);\n" + . "\$action = 'created';\n" . "if (isset(\$this->entitiesPool[\$hash])) {\n" - . "\$tempStack = \$this->stack;\n" - . "array_flip(\$tempStack);\n" - . "unset(\$tempStack[\$hash]);\n" - . "\$this->stack = array_flip(\$tempStack);\n" - . "unset(\$this->entitiesPool[\$hash]);\n" + . " \$action = \$this->entitiesPool[\$hash]['action'];\n" + . " \$tempStack = \$this->stack;\n" + . " array_flip(\$tempStack);\n" + . " unset(\$tempStack[\$hash]);\n" + . " \$this->stack = array_flip(\$tempStack);\n" + . " unset(\$this->entitiesPool[\$hash]);\n" . "}\n" - . "\$this->registerNew(\$entity);\n" + . "\$action == 'created' ? \$this->registerNew(\$entity) : \$this->registerDeleted(\$entity);\n" . "return \$this->doPersist(1);"; return [ 'name' => 'doPersistEntity', @@ -401,6 +404,7 @@ protected function _getDoPersistEntityMethod() ] ]; } + /** * Returns registerDelete() method * @@ -445,8 +449,8 @@ protected function _getRegisterNewMethod() { $body = "\$hash = spl_object_hash(\$entity);\n" . "\$data = [\n" - . "'entity' => \$entity,\n" - . "'action' => 'created'\n" + . " 'entity' => \$entity,\n" + . " 'action' => 'created'\n" . "];\n" . "array_push(\$this->stack, \$hash);\n" . "\$this->entitiesPool[\$hash] = \$data;"; From 8989b9312be1e62df1a4e4f9ce31a3889d79fd5f Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Thu, 28 Apr 2016 10:37:55 +0300 Subject: [PATCH 02/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order - Remove wrong caching quote behavior --- app/code/Magento/Quote/Model/QuoteRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/QuoteRepository.php b/app/code/Magento/Quote/Model/QuoteRepository.php index b395bcea40e1f..5396412cdd425 100644 --- a/app/code/Magento/Quote/Model/QuoteRepository.php +++ b/app/code/Magento/Quote/Model/QuoteRepository.php @@ -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]; } From 7166566ad8212d1d4d4a166a6109e6088327b032 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Thu, 28 Apr 2016 18:41:52 +0300 Subject: [PATCH 03/15] MAGETWO-52381: [GITHUB] Shipment comments can't be obtained via REST API request - Added collection instead simple reader from entity properties --- .../Magento/Sales/Model/Order/Shipment.php | 22 ++- .../Test/Unit/Model/Order/ShipmentTest.php | 127 +++++++++++++++++- 2 files changed, 138 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Shipment.php b/app/code/Magento/Sales/Model/Order/Shipment.php index f3f5647f431d8..f64dc02a205f8 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment.php +++ b/app/code/Magento/Sales/Model/Order/Shipment.php @@ -438,16 +438,11 @@ public function addComment($comment, $notify = false, $visibleOnFront = false) public function getCommentsCollection($reload = false) { if (!$this->hasData(ShipmentInterface::COMMENTS) || $reload) { - $comments = $this->_commentCollectionFactory->create()->setShipmentFilter($this->getId()) + $comments = $this->_commentCollectionFactory->create() + ->setShipmentFilter($this->getId()) ->setCreatedAtOrder(); $this->setComments($comments); - /** - * When shipment created with adding comment, - * comments collection must be loaded before we added this comment. - */ - $this->getComments()->load(); - if ($this->getId()) { foreach ($this->getComments() as $comment) { $comment->setShipment($this); @@ -714,6 +709,19 @@ public function getUpdatedAt() */ public function getComments() { + if (!$this->getId()) { + return $this->getData(ShipmentInterface::COMMENTS); + } + + if ($this->getData(ShipmentInterface::COMMENTS) == null) { + $collection = $this->_commentCollectionFactory->create() + ->setShipmentFilter($this->getId()); + + foreach ($collection as $item) { + $item->setShipment($this); + } + $this->setData(ShipmentInterface::COMMENTS, $collection->getItems()); + } return $this->getData(ShipmentInterface::COMMENTS); } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentTest.php index 40c216436fa23..19d0c89d3b27f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentTest.php @@ -5,18 +5,39 @@ */ namespace Magento\Sales\Test\Unit\Model\Order; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Sales\Model\Order\Shipment; +use Magento\Sales\Model\Order\Shipment\Item as ShipmentItem; +use Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\Collection; +use Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + class ShipmentTest extends \PHPUnit_Framework_TestCase { + /** + * @var CollectionFactory|MockObject + */ + private $commentCollectionFactory; + + /** + * @var Collection|MockObject + */ + private $commentCollection; + /** * @var \Magento\Sales\Model\Order\shipment */ - protected $shipmentModel; + private $shipmentModel; protected function setUp() { - $helperManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $arguments = []; - $this->shipmentModel = $helperManager->getObject('Magento\Sales\Model\Order\Shipment', $arguments); + $helperManager = new ObjectManager($this); + + $this->initCommentsCollectionFactoryMock(); + + $this->shipmentModel = $helperManager->getObject(Shipment::class, [ + 'commentCollectionFactory' => $this->commentCollectionFactory + ]); } public function testGetIncrementId() @@ -24,4 +45,102 @@ public function testGetIncrementId() $this->shipmentModel->setIncrementId('test_increment_id'); $this->assertEquals('test_increment_id', $this->shipmentModel->getIncrementId()); } + + /** + * @covers \Magento\Sales\Model\Order\Shipment::getCommentsCollection + */ + public function testGetCommentsCollection() + { + $shipmentId = 1; + $this->shipmentModel->setId($shipmentId); + + $shipmentItem = $this->getMockBuilder(ShipmentItem::class) + ->disableOriginalConstructor() + ->setMethods(['setShipment']) + ->getMock(); + $shipmentItem->expects(static::once()) + ->method('setShipment') + ->with($this->shipmentModel); + $collection = [$shipmentItem]; + + $this->commentCollection->expects(static::once()) + ->method('setShipmentFilter') + ->with($shipmentId) + ->willReturnSelf(); + $this->commentCollection->expects(static::once()) + ->method('setCreatedAtOrder') + ->willReturnSelf(); + + $this->commentCollection->expects(static::once()) + ->method('load') + ->willReturnSelf(); + + $reflection = new \ReflectionClass(Collection::class); + $reflectionProperty = $reflection->getProperty('_items'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->commentCollection, $collection); + + $expected = $this->shipmentModel->getCommentsCollection(); + + static::assertEquals($expected, $this->commentCollection); + } + + /** + * @covers \Magento\Sales\Model\Order\Shipment::getComments + */ + public function testGetComments() + { + $shipmentId = 1; + $this->shipmentModel->setId($shipmentId); + + $shipmentItem = $this->getMockBuilder(ShipmentItem::class) + ->disableOriginalConstructor() + ->setMethods(['setShipment']) + ->getMock(); + $shipmentItem->expects(static::once()) + ->method('setShipment') + ->with($this->shipmentModel); + $collection = [$shipmentItem]; + + $this->commentCollection->expects(static::once()) + ->method('setShipmentFilter') + ->with($shipmentId) + ->willReturnSelf(); + + $this->commentCollection->expects(static::once()) + ->method('load') + ->willReturnSelf(); + + $reflection = new \ReflectionClass(Collection::class); + $reflectionProperty = $reflection->getProperty('_items'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->commentCollection, $collection); + + $this->commentCollection->expects(static::once()) + ->method('getItems') + ->willReturn($collection); + + static::assertEquals($this->shipmentModel->getComments(), $collection); + } + + /** + * Creates mock for comments collection factory + * @return void + */ + private function initCommentsCollectionFactoryMock() + { + $this->commentCollection = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->setMethods(['setShipmentFilter', 'setCreatedAtOrder', 'getItems', 'load', '__wakeup']) + ->getMock(); + + $this->commentCollectionFactory = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->commentCollectionFactory->expects(static::any()) + ->method('create') + ->willReturn($this->commentCollection); + } } From 57ee7a0a1b788d53f89396d6c07597c8629415d8 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 29 Apr 2016 10:54:48 +0300 Subject: [PATCH 04/15] MAGETWO-52381: [GITHUB] Shipment comments can't be obtained via REST API request - Fixed failed static test --- app/code/Magento/Sales/Model/Order/Shipment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Sales/Model/Order/Shipment.php b/app/code/Magento/Sales/Model/Order/Shipment.php index f64dc02a205f8..fd5e2ae535514 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment.php +++ b/app/code/Magento/Sales/Model/Order/Shipment.php @@ -573,6 +573,7 @@ public function getTracks() } //@codeCoverageIgnoreStart + /** * Returns tracks * From 64197cbf33908c45d95741075af4fee0ccec25e1 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 29 Apr 2016 14:51:40 +0300 Subject: [PATCH 05/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order --- .../ShippingAssignmentProcessor.php | 3 +- .../ShippingAssignmentProcessorTest.php | 111 ++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php diff --git a/app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php b/app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php index 209e8785a4c53..7643160e4489b 100644 --- a/app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php +++ b/app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php @@ -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); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php new file mode 100644 index 0000000000000..14a47cfc9c724 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php @@ -0,0 +1,111 @@ +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 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 + ); + } +} From 3ce0de1e5e83a1c72790bcc69be91334db247912 Mon Sep 17 00:00:00 2001 From: "Shmyheliuk, Oleksandr" Date: Wed, 4 May 2016 14:02:30 +0300 Subject: [PATCH 06/15] MAGETWO-51172: Wrong information on return items frontend grid --- app/code/Magento/Eav/Model/Entity/AbstractEntity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index 2a847b0019c4d..7af0ab6952642 100644 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -35,7 +35,7 @@ abstract class AbstractEntity extends AbstractResource implements EntityInterfac /** * @var \Magento\Eav\Model\Entity\AttributeLoaderInterface */ - private $attributeLoader; + protected $attributeLoader; /** * Connection name @@ -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); From 122c1884db85a4d23e3fea65af65443ad9bbd868 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 13 May 2016 12:02:50 +0300 Subject: [PATCH 07/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order - Fix removing set of items from shopping cart --- app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php | 1 + app/code/Magento/Sales/Model/AdminOrder/Create.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php index 1fb983e3228ba..3c0fb3273981f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php @@ -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(); } /** diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 51bb09e7e9a78..79f52b0fa0127 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -902,6 +902,7 @@ public function applySidebarData($data) $this->removeItem($itemId, 'cart'); } } + $this->recollectCart(); } if (isset($data['add_wishlist_item'])) { foreach ($data['add_wishlist_item'] as $itemId => $qty) { @@ -925,6 +926,7 @@ public function applySidebarData($data) foreach ($data['remove'] as $itemId => $from) { $this->removeItem($itemId, $from); } + $this->recollectCart(); } if (isset($data['empty_customer_cart']) && (int)$data['empty_customer_cart'] == 1) { $this->getCustomerCart()->removeAllItems()->collectTotals(); @@ -951,8 +953,7 @@ public function removeItem($itemId, $from) $cart = $this->getCustomerCart(); if ($cart) { $cart->removeItem($itemId); - $cart->collectTotals(); - $this->quoteRepository->save($cart); + $this->_needCollectCart = true; } break; case 'wishlist': From 86618d086b40b0d74df768107502892f2b964d01 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 13 May 2016 12:20:18 +0300 Subject: [PATCH 08/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order - Fix static --- .../ShippingAssignment/ShippingAssignmentProcessorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php index 14a47cfc9c724..52c0a48bfd208 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/ShippingAssignment/ShippingAssignmentProcessorTest.php @@ -63,7 +63,7 @@ protected function setUp() /** * Test saving shipping assignments with deleted cart items * - * @covers ShippingAssignmentProcessor::save + * @covers \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::save */ public function testSaveWithDeletedCartItems() { From 9ef56a9d223ef4caabc30c44110d83d10c6dfe67 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 13 May 2016 12:47:39 +0300 Subject: [PATCH 09/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order - Move recollectCart() method at the end of applySidebarData() method --- app/code/Magento/Sales/Model/AdminOrder/Create.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 79f52b0fa0127..d8f65c0a28c37 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -902,7 +902,6 @@ public function applySidebarData($data) $this->removeItem($itemId, 'cart'); } } - $this->recollectCart(); } if (isset($data['add_wishlist_item'])) { foreach ($data['add_wishlist_item'] as $itemId => $qty) { @@ -926,13 +925,14 @@ public function applySidebarData($data) foreach ($data['remove'] as $itemId => $from) { $this->removeItem($itemId, $from); } - $this->recollectCart(); } if (isset($data['empty_customer_cart']) && (int)$data['empty_customer_cart'] == 1) { $this->getCustomerCart()->removeAllItems()->collectTotals(); $this->quoteRepository->save($this->getCustomerCart()); } + $this->recollectCart(); + return $this; } From 7d71288dd521125229d61a52961253ffdb6b7d0f Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 13 May 2016 14:18:31 +0300 Subject: [PATCH 10/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order - Add unit test on call getForCustomer() method after get() --- .../Test/Unit/Model/QuoteRepositoryTest.php | 103 +++++++++++++++--- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php index db0e186a50329..64e2da67f7783 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php @@ -11,6 +11,7 @@ use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; +use Magento\Quote\Model\QuoteRepository\LoadHandler; class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase { @@ -54,6 +55,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); @@ -107,6 +113,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); } /** @@ -132,23 +144,74 @@ 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); $this->assertEquals($this->quoteMock, $this->model->get($cartId)); $this->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->getForCustomer($customerId)); + } + public function testGetWithSharedStoreIds() { $this->markTestSkipped('MAGETWO-48531'); @@ -174,19 +237,31 @@ 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)); From fea2329d1a45a5b603a7b958017018df3ef26460 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 13 May 2016 15:29:02 +0300 Subject: [PATCH 11/15] MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order - Fix static tests --- .../Test/Unit/Model/QuoteRepositoryTest.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php index 64e2da67f7783..70c6489326ad5 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php @@ -7,12 +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 { /** @@ -170,8 +171,8 @@ public function testGet() ->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->get($cartId)); } public function testGetForCustomerAfterGet() @@ -208,8 +209,8 @@ public function testGetForCustomerAfterGet() ->method('load') ->with($this->quoteMock); - $this->assertEquals($this->quoteMock, $this->model->get($cartId)); - $this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId)); + static::assertEquals($this->quoteMock, $this->model->get($cartId)); + static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId)); } public function testGetWithSharedStoreIds() @@ -263,8 +264,8 @@ public function testGetForCustomer() ->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)); } /** From c757226dd724ee7130aab0f526d601582e5b749e Mon Sep 17 00:00:00 2001 From: "Shmyheliuk, Oleksandr" Date: Mon, 16 May 2016 17:04:24 +0300 Subject: [PATCH 12/15] MAGETWO-52786: Validation error message is not shown if Luhn validation is not passed --- .../web/js/view/payment/method-renderer/hosted-fields.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js index 7caeb85190a37..c6e884ce72dc3 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js @@ -115,12 +115,12 @@ define([ if (event.target.fieldKey === 'number' && event.card) { if (event.isValid) { self.cardNumber = event.card; + self.selectedCardType( + validator.getMageCardType(event.card.type, self.getCcAvailableTypes()) + ); } else { self.cardNumber = null; } - self.selectedCardType( - validator.getMageCardType(event.card.type, self.getCcAvailableTypes()) - ); } }; From 368ad63e3d1b9e8682395e47e38be0a3c81cb5de Mon Sep 17 00:00:00 2001 From: "Shmyheliuk, Oleksandr" Date: Mon, 16 May 2016 18:03:38 +0300 Subject: [PATCH 13/15] MAGETWO-52786: Validation error message is not shown if Luhn validation is not passed --- .../payment/method-renderer/hosted-fields.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js index c6e884ce72dc3..bb7697b22da12 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js @@ -24,7 +24,8 @@ define([ * {String} */ id: 'co-transparent-form-braintree' - } + }, + isValidCardNumber: false }, /** @@ -113,14 +114,10 @@ define([ } if (event.target.fieldKey === 'number' && event.card) { - if (event.isValid) { - self.cardNumber = event.card; - self.selectedCardType( - validator.getMageCardType(event.card.type, self.getCcAvailableTypes()) - ); - } else { - self.cardNumber = null; - } + self.isValidCardNumber = event.isValid; + self.selectedCardType( + validator.getMageCardType(event.card.type, self.getCcAvailableTypes()) + ); } }; @@ -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; From 5e1c0838b96c5424aae6e660f19ee6e260c6f7b8 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Mon, 16 May 2016 18:56:09 +0300 Subject: [PATCH 14/15] MAGETWO-52829: [Github] Sales Order Totals Base grandtotal #4323 --- app/code/Magento/Sales/Block/Order/Totals.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Block/Order/Totals.php b/app/code/Magento/Sales/Block/Order/Totals.php index 06a04048ff3f6..6f267f51275a0 100644 --- a/app/code/Magento/Sales/Block/Order/Totals.php +++ b/app/code/Magento/Sales/Block/Order/Totals.php @@ -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, ] From cc1ebe9dd56cc0b347c1e0057045f4a338b5c0c2 Mon Sep 17 00:00:00 2001 From: Alexander Makeev Date: Tue, 17 May 2016 11:31:00 +0000 Subject: [PATCH 15/15] MAGETWO-51768: Checkout agreement is not a link on PayPal Order Review page - fixed bug MAGETWO-52283 Notification required message of Terms and Conditions is absent on Multi-Checkout success page --- .../frontend/web/js/model/agreement-validator.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js b/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js index 13673326605a4..793978cb8e474 100644 --- a/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js +++ b/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js @@ -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'); } } }