From 363e8325d8c747562ea7c5aa6eabe809e59764d4 Mon Sep 17 00:00:00 2001 From: Anton Ohorodnyk Date: Fri, 3 Jun 2016 16:07:15 +0300 Subject: [PATCH 01/29] MAGETWO-53041: 'Yes/No' attribute shown in Advanced Search result even it not used in filtration --- app/code/Magento/CatalogSearch/Model/Advanced.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogSearch/Model/Advanced.php b/app/code/Magento/CatalogSearch/Model/Advanced.php index ef332a675e8a8..f469820b3bb2d 100644 --- a/app/code/Magento/CatalogSearch/Model/Advanced.php +++ b/app/code/Magento/CatalogSearch/Model/Advanced.php @@ -368,9 +368,11 @@ protected function getPreparedSearchCriteria($attribute, $value) $value = $value['label']; } } elseif ($attribute->getFrontendInput() == 'boolean') { - $value = $value == 1 - ? __('Yes') - : __('No'); + if (is_numeric($value)) { + $value = $value == 1 ? __('Yes') : __('No'); + } else { + $value = false; + } } return $value; From 851a5c1183291215795537e66db2884776c9f42b Mon Sep 17 00:00:00 2001 From: Anton Ohorodnyk Date: Mon, 6 Jun 2016 14:10:26 +0300 Subject: [PATCH 02/29] MAGETWO-53041: 'Yes/No' attribute shown in Advanced Search result even it not used in filtration - Fixed unit test --- app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php index 4bf4df410fde8..cf70778432b92 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php @@ -162,7 +162,7 @@ public function addFiltersDataProvider() 'static' ) ], - 'values' => ['is_active' => false], + 'values' => ['is_active' => 0], 'currentCurrencyCode' => 'GBP', 'baseCurrencyCode' => 'USD' ], From dec472ddd5478b5aa00ab2a3db8494e48641c28c Mon Sep 17 00:00:00 2001 From: Olga Nakonechna Date: Mon, 5 Sep 2016 11:25:01 +0300 Subject: [PATCH 03/29] MAGETWO-57924: Unable to add "Customer Group Price" --- .../view/adminhtml/web/js/form/element/price-input.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js b/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js index 0939619809a46..135470f430e29 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js @@ -10,6 +10,14 @@ define([ return Abstract.extend({ defaults: { elementTmpl: 'Magento_Catalog/form/element/price-input' - } + }, + + /** + * Callback that fires when 'input' event is performed + * + * @param {Object} data + * @param {Object} event + */ + onInput: function (data, event) { } }); }); From 22557ca9bf675142031ac6dc5ba461390ab1bfe2 Mon Sep 17 00:00:00 2001 From: Olga Nakonechna Date: Mon, 5 Sep 2016 17:47:25 +0300 Subject: [PATCH 04/29] MAGETWO-57933: Product quantity is not updated on 'cart/configure' page second time --- .../Checkout/CustomerData/DefaultItem.php | 1 + .../layout/checkout_cart_configure.xml | 3 + .../view/configure/product-customer-data.js | 59 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js diff --git a/app/code/Magento/Checkout/CustomerData/DefaultItem.php b/app/code/Magento/Checkout/CustomerData/DefaultItem.php index 4cdc4c59b9726..9c35265d03ff1 100644 --- a/app/code/Magento/Checkout/CustomerData/DefaultItem.php +++ b/app/code/Magento/Checkout/CustomerData/DefaultItem.php @@ -70,6 +70,7 @@ protected function doGetItemData() 'item_id' => $this->item->getId(), 'configure_url' => $this->getConfigureUrl(), 'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(), + 'product_id' => $this->item->getProduct()->getId(), 'product_name' => $this->item->getProduct()->getName(), 'product_sku' => $this->item->getProduct()->getSku(), 'product_url' => $this->getProductUrl(), diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml index 403e07c64d3ed..151b079220de7 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml @@ -6,6 +6,9 @@ */ --> + + + diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js b/app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js new file mode 100644 index 0000000000000..a612b5e2dc6b7 --- /dev/null +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js @@ -0,0 +1,59 @@ +require([ + 'jquery', + 'Magento_Customer/js/customer-data' +], function ($, customerData) { + 'use strict'; + + var selectors = { + qtySelector: '#product_addtocart_form [name="qty"]', + productIdSelector: '#product_addtocart_form [name="product"]' + }, + cartData = customerData.get('cart'), + productId = $(selectors.productIdSelector).val(), + productQty, + productQtyInput, + + /** + * Updates product's qty input value according to actual data + */ + updateQty = function () { + + if (productQty || productQty === 0) { + productQtyInput = productQtyInput || $(selectors.qtySelector); + + if (productQtyInput && productQty.toString() !== productQtyInput.val()) { + productQtyInput.val(productQty); + } + } + }, + + /** + * Sets productQty according to cart data from customer-data + * + * @param {Object} data - cart data from customer-data + */ + setProductQty = function (data) { + var product; + + if (!(data && data.items && data.items.length && productId)) { + return; + } + product = data.items.find(function (item) { + return item['product_id'] === productId || + item['item_id'] === productId; + }); + + if (!product) { + return; + } + productQty = product.qty; + }; + + cartData.subscribe(function (updateCartData) { + setProductQty(updateCartData); + updateQty(); + }); + + setProductQty(cartData()); + updateQty(); +}); From a67d3eaf8ad30cc07c5fd7cc3c97f43ccfb39bb5 Mon Sep 17 00:00:00 2001 From: vnayda Date: Wed, 7 Sep 2016 13:13:53 +0300 Subject: [PATCH 05/29] MAGETWO-55341: Request to ESI doesn't return any data --- app/code/Magento/Ui/view/base/layout/default.xml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Ui/view/base/layout/default.xml b/app/code/Magento/Ui/view/base/layout/default.xml index 7f2efbd855872..dc60120c34645 100644 --- a/app/code/Magento/Ui/view/base/layout/default.xml +++ b/app/code/Magento/Ui/view/base/layout/default.xml @@ -5,10 +5,8 @@ * See COPYING.txt for license details. */ --> - - - - - - - + + + + + From 99bb170a805f3e9d0ab5c9b9bb801f739ac161c1 Mon Sep 17 00:00:00 2001 From: vnayda Date: Wed, 7 Sep 2016 16:48:56 +0300 Subject: [PATCH 06/29] MAGETWO-55341: Request to ESI doesn't return any data --- app/code/Magento/Ui/view/base/layout/default.xml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Ui/view/base/layout/default.xml b/app/code/Magento/Ui/view/base/layout/default.xml index dc60120c34645..64d5f1483a2f3 100644 --- a/app/code/Magento/Ui/view/base/layout/default.xml +++ b/app/code/Magento/Ui/view/base/layout/default.xml @@ -5,8 +5,10 @@ * See COPYING.txt for license details. */ --> - - - - - + + + + + + + From 024737e65254cc65f579b04afd47957b5025f6de Mon Sep 17 00:00:00 2001 From: Maksym Iakusha Date: Tue, 6 Sep 2016 12:32:40 +0300 Subject: [PATCH 07/29] MAGETWO-56150: Order comments history shows time of comment twice --- .../Adminhtml/Order/View/Tab/History.php | 2 +- .../Adminhtml/Order/View/Tab/HistoryTest.php | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php index 8a6674aa154b0..e496283d89a3c 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php @@ -161,7 +161,7 @@ public function getItemCreatedAt(array $item, $dateType = 'date', $format = \Int ? $item['created_at'] : new \DateTime($item['created_at']); if ('date' === $dateType) { - return $this->_localeDate->formatDateTime($date, $format, $format); + return $this->_localeDate->formatDate($date, $format); } return $this->_localeDate->formatDateTime($date, \IntlDateFormatter::NONE, $format); } diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php index 6445fd36dd146..d1bdfa80c4ea7 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php @@ -30,6 +30,17 @@ class HistoryTest extends \PHPUnit_Framework_TestCase */ protected $coreRegistryMock; + /** + * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeDateMock; + + /** + * @var \Magento\Backend\Block\Template\Context|\PHPUnit_Framework_MockObject_MockObject + */ + protected $contextMock; + + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -37,11 +48,25 @@ protected function setUp() $this->coreRegistryMock = $this->getMock(\Magento\Framework\Registry::class, [], [], '', false); $this->adminHelperMock = $this->getMock(\Magento\Sales\Helper\Admin::class, [], [], '', false); + $this->contextMock = $this->getMockBuilder(\Magento\Backend\Block\Template\Context::class) + ->disableOriginalConstructor() + ->setMethods(['getLocaleDate']) + ->getMock(); + + $this->localeDateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class) + ->getMock(); + + $this->contextMock->expects($this->any())->method('getLocaleDate')->will( + $this->returnValue($this->localeDateMock) + ); + $this->commentsHistory = $this->objectManager->getObject( \Magento\Sales\Block\Adminhtml\Order\View\Tab\History::class, [ 'adminHelper' => $this->adminHelperMock, - 'registry' => $this->coreRegistryMock + 'registry' => $this->coreRegistryMock, + 'context' => $this->contextMock, + 'localeDate' => $this->localeDateMock ] ); } @@ -63,4 +88,17 @@ public function testGetItemCommentIsNotSet() $this->adminHelperMock->expects($this->never())->method('escapeHtmlWithLinks'); $this->assertEquals('', $this->commentsHistory->getItemComment($item)); } + + public function testGetItemCreatedAt() + { + $date = new \DateTime; + $item = ['created_at' => $date ]; + + $this->localeDateMock->expects($this->once()) + ->method('formatDate') + ->with($date, \IntlDateFormatter::MEDIUM) + ->willReturn('date'); + + $this->assertEquals('date', $this->commentsHistory->getItemCreatedAt($item)); + } } From 5175e2dae7ac8036d462a6698482ea78c135ac49 Mon Sep 17 00:00:00 2001 From: Maksym Iakusha Date: Wed, 7 Sep 2016 10:18:05 +0300 Subject: [PATCH 08/29] MAGETWO-56150: Order comments history shows time of comment twice --- .../Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php index d1bdfa80c4ea7..b60a4a39469c2 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php @@ -40,7 +40,6 @@ class HistoryTest extends \PHPUnit_Framework_TestCase */ protected $contextMock; - protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); From 404b8b99d077a944e469013262ea59c83477097d Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Thu, 8 Sep 2016 12:06:23 +0300 Subject: [PATCH 09/29] MAGETWO-56150: Order comments history shows time of comment twice --- .../Adminhtml/Order/View/Tab/History.php | 7 ++--- .../Adminhtml/Order/View/Tab/HistoryTest.php | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php index e496283d89a3c..a68c543acf731 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php @@ -157,13 +157,10 @@ public function getItemCreatedAt(array $item, $dateType = 'date', $format = \Int if (!isset($item['created_at'])) { return ''; } - $date = $item['created_at'] instanceof \DateTimeInterface - ? $item['created_at'] - : new \DateTime($item['created_at']); if ('date' === $dateType) { - return $this->_localeDate->formatDate($date, $format); + return $this->formatDate($item['created_at'], $format); } - return $this->_localeDate->formatDateTime($date, \IntlDateFormatter::NONE, $format); + return $this->formatTime($item['created_at'], $format); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php index b60a4a39469c2..0edeac7170929 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php @@ -88,16 +88,38 @@ public function testGetItemCommentIsNotSet() $this->assertEquals('', $this->commentsHistory->getItemComment($item)); } - public function testGetItemCreatedAt() + public function testGetItemCreatedAtDate() { $date = new \DateTime; $item = ['created_at' => $date ]; $this->localeDateMock->expects($this->once()) - ->method('formatDate') - ->with($date, \IntlDateFormatter::MEDIUM) + ->method('formatDateTime') + ->with($date, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE) ->willReturn('date'); $this->assertEquals('date', $this->commentsHistory->getItemCreatedAt($item)); } + + public function testGetItemCreatedAtTime() + { + $date = new \DateTime; + $item = ['created_at' => $date ]; + + $this->localeDateMock->expects($this->once()) + ->method('formatDateTime') + ->with($date, \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM) + ->willReturn('time'); + + $this->assertEquals('time', $this->commentsHistory->getItemCreatedAt($item, 'time')); + } + + public function testGetItemCreatedAtEmpty() + { + $item = ['title' => "Test" ]; + + $this->localeDateMock->expects($this->never())->method('formatDateTime'); + $this->assertEquals('', $this->commentsHistory->getItemCreatedAt($item)); + $this->assertEquals('', $this->commentsHistory->getItemCreatedAt($item, 'time')); + } } From bd8bfd20ecbe98220ba02778d3bed6882a20245d Mon Sep 17 00:00:00 2001 From: Olga Nakonechna Date: Fri, 9 Sep 2016 10:10:38 +0300 Subject: [PATCH 10/29] MAGETWO-57924: Unable to add "Customer Group Price" --- .../Product/Form/Modifier/AdvancedPricing.php | 1 - .../web/js/form/element/price-input.js | 23 ------------------- .../template/form/element/price-input.html | 22 ------------------ 3 files changed, 46 deletions(-) delete mode 100644 app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js delete mode 100644 app/code/Magento/Catalog/view/adminhtml/web/template/form/element/price-input.html diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php index 33c8cea3262a4..53360de08b434 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php @@ -493,7 +493,6 @@ private function getTierPriceStructure($tierPricePath) 'data' => [ 'config' => [ 'componentType' => Field::NAME, - 'component' => 'Magento_Catalog/js/form/element/price-input', 'formElement' => Input::NAME, 'dataType' => Price::NAME, 'label' => __('Price'), diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js b/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js deleted file mode 100644 index 135470f430e29..0000000000000 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -define([ - 'Magento_Ui/js/form/element/abstract' -], function (Abstract) { - 'use strict'; - - return Abstract.extend({ - defaults: { - elementTmpl: 'Magento_Catalog/form/element/price-input' - }, - - /** - * Callback that fires when 'input' event is performed - * - * @param {Object} data - * @param {Object} event - */ - onInput: function (data, event) { } - }); -}); diff --git a/app/code/Magento/Catalog/view/adminhtml/web/template/form/element/price-input.html b/app/code/Magento/Catalog/view/adminhtml/web/template/form/element/price-input.html deleted file mode 100644 index ce8ae751e6702..0000000000000 --- a/app/code/Magento/Catalog/view/adminhtml/web/template/form/element/price-input.html +++ /dev/null @@ -1,22 +0,0 @@ - - From b708cdba1698e26c68c9e6f72c5eb7fd00697a2c Mon Sep 17 00:00:00 2001 From: Olga Nakonechna Date: Fri, 9 Sep 2016 10:46:59 +0300 Subject: [PATCH 11/29] MAGETWO-57933: Product quantity is not updated on 'cart/configure' page second time --- .../Checkout/view/frontend/layout/checkout_cart_configure.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml index 151b079220de7..c255f17cd3697 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml @@ -7,8 +7,8 @@ --> - - + + From 237af8f109c1466b606f57023d636f6a54471bcc Mon Sep 17 00:00:00 2001 From: Olga Nakonechna Date: Fri, 9 Sep 2016 17:43:34 +0300 Subject: [PATCH 12/29] MAGETWO-57933: Product quantity is not updated on 'cart/configure' page second time --- .../frontend/templates/cart/item/configure/updatecart.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml index fe39e9c44ada8..0f221a393f5eb 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml @@ -17,7 +17,7 @@
- +
From 17515b9ca2e59379771d180fad3d258a98eeea6e Mon Sep 17 00:00:00 2001 From: Illia Grybkov Date: Tue, 13 Sep 2016 18:02:46 +0300 Subject: [PATCH 13/29] MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline --- .../Magento/CatalogSearch/Block/Advanced/Result.php | 11 +++++++++++ .../CatalogSearch/Model/Search/RequestGenerator.php | 6 ++++-- .../Test/Unit/Model/Search/RequestGeneratorTest.php | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogSearch/Block/Advanced/Result.php b/app/code/Magento/CatalogSearch/Block/Advanced/Result.php index 7b720c8c7c87a..17c94781c9001 100644 --- a/app/code/Magento/CatalogSearch/Block/Advanced/Result.php +++ b/app/code/Magento/CatalogSearch/Block/Advanced/Result.php @@ -64,6 +64,7 @@ public function __construct( */ protected function _prepareLayout() { + $this->pageConfig->getTitle()->set($this->getPageTitle()); $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); if ($breadcrumbs) { $breadcrumbs->addCrumb( @@ -84,6 +85,16 @@ protected function _prepareLayout() return parent::_prepareLayout(); } + /* + * Get search query text + * + * @return \Magento\Framework\Phrase + */ + public function getPageTitle() + { + return __('Advanced Search Results'); + } + /** * Set order options * diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php index 2ca347aae83c2..aa3f277c31fce 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php @@ -62,7 +62,7 @@ private function generateRequest($attributeType, $container, $useFulltext) $request = []; foreach ($this->getSearchableAttributes() as $attribute) { if ($attribute->getData($attributeType)) { - if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'])) { + if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'], true)) { $queryName = $attribute->getAttributeCode() . '_query'; $request['queries'][$container]['queryReference'][] = [ @@ -114,7 +114,9 @@ private function generateRequest($attributeType, $container, $useFulltext) //same fields have special semantics continue; } - if ($useFulltext) { + + // Match search by custom price attribute isn't supported + if ($useFulltext && !in_array($attribute->getFrontendInput(), ['price'], true)) { $request['queries']['search']['match'][] = [ 'field' => $attribute->getAttributeCode(), 'boost' => $attribute->getSearchWeight() ?: 1, diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php index f66bacfad306a..1aa8da94bfecb 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php @@ -87,6 +87,14 @@ public function attributesProvider() ], ['attr_int', 'int', 0, 1, 0] ], + [ + [ + 'quick_search_container' => ['queries' => 2, 'filters' => 1, 'aggregations' => 1], + 'advanced_search_container' => ['queries' => 0, 'filters' => 0, 'aggregations' => 0], + 'catalog_view_container' => ['queries' => 0, 'filters' => 0, 'aggregations' => 0], + ], + ['custom_price_attr', 'price', 0, 1, 0], + ], ]; } From 15be1acde62057b69439731fa563e61d1644c4cb Mon Sep 17 00:00:00 2001 From: Illia Grybkov Date: Wed, 14 Sep 2016 08:33:04 +0300 Subject: [PATCH 14/29] MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline - Change visibility of the method to private --- app/code/Magento/CatalogSearch/Block/Advanced/Result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogSearch/Block/Advanced/Result.php b/app/code/Magento/CatalogSearch/Block/Advanced/Result.php index 17c94781c9001..9f2ef479a9f8c 100644 --- a/app/code/Magento/CatalogSearch/Block/Advanced/Result.php +++ b/app/code/Magento/CatalogSearch/Block/Advanced/Result.php @@ -90,7 +90,7 @@ protected function _prepareLayout() * * @return \Magento\Framework\Phrase */ - public function getPageTitle() + private function getPageTitle() { return __('Advanced Search Results'); } From b5c6614b7d74c6782597b4618dfb41fb7c409cb7 Mon Sep 17 00:00:00 2001 From: Illia Grybkov Date: Wed, 14 Sep 2016 12:15:43 +0300 Subject: [PATCH 15/29] MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline - Refactor to eliminate Cyclomatic Complexity warning - Update PHPDocs on the Advanced Search Result block --- .../CatalogSearch/Block/Advanced/Result.php | 10 +-- .../Model/Search/RequestGenerator.php | 59 +++++++--------- .../Model/Search/RequestGenerator/Decimal.php | 49 ++++++++++++++ .../Model/Search/RequestGenerator/General.php | 48 +++++++++++++ .../RequestGenerator/GeneratorCollection.php | 40 +++++++++++ .../RequestGenerator/GeneratorInterface.php | 29 ++++++++ .../Search/RequestGenerator/DecimalTest.php | 67 +++++++++++++++++++ .../Search/RequestGenerator/GeneralTest.php | 65 ++++++++++++++++++ .../GeneratorCollectionTest.php | 63 +++++++++++++++++ .../Model/Search/RequestGeneratorTest.php | 43 +++++++++--- app/code/Magento/CatalogSearch/etc/di.xml | 8 +++ 11 files changed, 431 insertions(+), 50 deletions(-) create mode 100644 app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php create mode 100644 app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php create mode 100644 app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php create mode 100644 app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php create mode 100644 app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/DecimalTest.php create mode 100644 app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php create mode 100644 app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php diff --git a/app/code/Magento/CatalogSearch/Block/Advanced/Result.php b/app/code/Magento/CatalogSearch/Block/Advanced/Result.php index 9f2ef479a9f8c..4351b134e4a11 100644 --- a/app/code/Magento/CatalogSearch/Block/Advanced/Result.php +++ b/app/code/Magento/CatalogSearch/Block/Advanced/Result.php @@ -85,11 +85,11 @@ protected function _prepareLayout() return parent::_prepareLayout(); } - /* - * Get search query text - * - * @return \Magento\Framework\Phrase - */ + /** + * Get page title + * + * @return \Magento\Framework\Phrase + */ private function getPageTitle() { return __('Advanced Search Results'); diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php index aa3f277c31fce..dcfe40f248a6a 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php @@ -8,7 +8,8 @@ use Magento\Catalog\Api\Data\EavAttributeInterface; use Magento\Catalog\Model\Entity\Attribute; use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; -use Magento\Framework\Search\Request\BucketInterface; +use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorCollection; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Search\Request\FilterInterface; use Magento\Framework\Search\Request\QueryInterface; @@ -25,12 +26,24 @@ class RequestGenerator */ private $productAttributeCollectionFactory; + /** + * @var GeneratorCollection + */ + private $generatorCollection; + /** * @param CollectionFactory $productAttributeCollectionFactory + * @param GeneratorCollection $generatorCollection */ - public function __construct(CollectionFactory $productAttributeCollectionFactory) - { + public function __construct( + CollectionFactory $productAttributeCollectionFactory, + GeneratorCollection $generatorCollection = null + ) { $this->productAttributeCollectionFactory = $productAttributeCollectionFactory; + $this->generatorCollection = $generatorCollection + ?: ObjectManager::getInstance()->get( + GeneratorCollection::class + ); } /** @@ -76,53 +89,26 @@ private function generateRequest($attributeType, $container, $useFulltext) 'filterReference' => [['ref' => $filterName]], ]; $bucketName = $attribute->getAttributeCode() . self::BUCKET_SUFFIX; - if ($attribute->getBackendType() == 'decimal') { - $request['filters'][$filterName] = [ - 'type' => FilterInterface::TYPE_RANGE, - 'name' => $filterName, - 'field' => $attribute->getAttributeCode(), - 'from' => '$' . $attribute->getAttributeCode() . '.from$', - 'to' => '$' . $attribute->getAttributeCode() . '.to$', - ]; - $request['aggregations'][$bucketName] = [ - 'type' => BucketInterface::TYPE_DYNAMIC, - 'name' => $bucketName, - 'field' => $attribute->getAttributeCode(), - 'method' => 'manual', - 'metric' => [["type" => "count"]], - ]; - } else { - $request['filters'][$filterName] = [ - 'type' => FilterInterface::TYPE_TERM, - 'name' => $filterName, - 'field' => $attribute->getAttributeCode(), - 'value' => '$' . $attribute->getAttributeCode() . '$', - ]; - $request['aggregations'][$bucketName] = [ - 'type' => BucketInterface::TYPE_TERM, - 'name' => $bucketName, - 'field' => $attribute->getAttributeCode(), - 'metric' => [["type" => "count"]], - ]; - } + $generator = $this->generatorCollection->getGeneratorForType($attribute->getBackendType()); + $request['filters'][$filterName] = $generator->getFilterData($attribute, $filterName); + $request['aggregations'][$bucketName] = $generator->getAggregationData($attribute, $bucketName); } } /** @var $attribute Attribute */ - if (in_array($attribute->getAttributeCode(), ['price', 'sku']) - || !$attribute->getIsSearchable() - ) { + if (!$attribute->getIsSearchable() || in_array($attribute->getAttributeCode(), ['price', 'sku'], true)) { //same fields have special semantics continue; } // Match search by custom price attribute isn't supported - if ($useFulltext && !in_array($attribute->getFrontendInput(), ['price'], true)) { + if ($useFulltext && $attribute->getFrontendInput() !== 'price') { $request['queries']['search']['match'][] = [ 'field' => $attribute->getAttributeCode(), 'boost' => $attribute->getSearchWeight() ?: 1, ]; } } + return $request; } @@ -233,6 +219,7 @@ private function generateAdvancedSearchRequest() ]; } } + return $request; } } diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php new file mode 100644 index 0000000000000..5b83d1d61d9b4 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php @@ -0,0 +1,49 @@ + FilterInterface::TYPE_RANGE, + 'name' => $filterName, + 'field' => $attribute->getAttributeCode(), + 'from' => '$' . $attribute->getAttributeCode() . '.from$', + 'to' => '$' . $attribute->getAttributeCode() . '.to$', + ]; + } + + /** + * Generate aggregations data for specific attribute + * @param Attribute $attribute + * @param string $bucketName + * @return array + */ + public function getAggregationData(Attribute $attribute, $bucketName) + { + return [ + 'type' => BucketInterface::TYPE_DYNAMIC, + 'name' => $bucketName, + 'field' => $attribute->getAttributeCode(), + 'method' => 'manual', + 'metric' => [['type' => 'count']], + ]; + } +} diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php new file mode 100644 index 0000000000000..410c97e3f37d3 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php @@ -0,0 +1,48 @@ + FilterInterface::TYPE_TERM, + 'name' => $filterName, + 'field' => $attribute->getAttributeCode(), + 'value' => '$' . $attribute->getAttributeCode() . '$', + ]; + } + + /** + * Generate aggregations data for specific attribute + * @param Attribute $attribute + * @param string $bucketName + * @return array + */ + public function getAggregationData(Attribute $attribute, $bucketName) + { + return [ + 'type' => BucketInterface::TYPE_TERM, + 'name' => $bucketName, + 'field' => $attribute->getAttributeCode(), + 'metric' => [['type' => 'count']], + ]; + } +} diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php new file mode 100644 index 0000000000000..6c9d03dd047e5 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php @@ -0,0 +1,40 @@ +defaultGenerator = $defaultGenerator; + $this->generators = $generators; + } + + /** + * @param $type + * @return GeneratorInterface + */ + public function getGeneratorForType($type) + { + return isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator; + } +} diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php new file mode 100644 index 0000000000000..981273894ccf0 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php @@ -0,0 +1,29 @@ +attribute = $this->getMockBuilder(Attribute::class) + ->disableOriginalConstructor() + ->setMethods(['getAttributeCode']) + ->getMockForAbstractClass(); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->decimal = $objectManager->getObject(Decimal::class); + } + + public function testGetFilterData() + { + $filterName = 'test_filter_name'; + $attributeCode = 'test_attribute_code'; + $expected = [ + 'type' => FilterInterface::TYPE_RANGE, + 'name' => $filterName, + 'field' => $attributeCode, + 'from' => '$' . $attributeCode . '.from$', + 'to' => '$' . $attributeCode . '.to$', + ]; + $this->attribute->expects($this->atLeastOnce()) + ->method('getAttributeCode') + ->willReturn($attributeCode); + $actual = $this->decimal->getFilterData($this->attribute, $filterName); + $this->assertEquals($expected, $actual); + } + + public function testGetAggregationData() + { + $bucketName = 'test_bucket_name'; + $attributeCode = 'test_attribute_code'; + $expected = [ + 'type' => BucketInterface::TYPE_DYNAMIC, + 'name' => $bucketName, + 'field' => $attributeCode, + 'method' => 'manual', + 'metric' => [['type' => 'count']], + ]; + $this->attribute->expects($this->atLeastOnce()) + ->method('getAttributeCode') + ->willReturn($attributeCode); + $actual = $this->decimal->getAggregationData($this->attribute, $bucketName); + $this->assertEquals($expected, $actual); + } +} diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php new file mode 100644 index 0000000000000..f1cff3fcad073 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php @@ -0,0 +1,65 @@ +attribute = $this->getMockBuilder(Attribute::class) + ->disableOriginalConstructor() + ->setMethods(['getAttributeCode']) + ->getMockForAbstractClass(); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->general = $objectManager->getObject(General::class); + } + + public function testGetFilterData() + { + $filterName = 'test_general_filter_name'; + $attributeCode = 'test_general_attribute_code'; + $expected = [ + 'type' => FilterInterface::TYPE_TERM, + 'name' => $filterName, + 'field' => $attributeCode, + 'value' => '$' . $attributeCode . '$', + ]; + $this->attribute->expects($this->atLeastOnce()) + ->method('getAttributeCode') + ->willReturn($attributeCode); + $actual = $this->general->getFilterData($this->attribute, $filterName); + $this->assertEquals($expected, $actual); + } + + public function testGetAggregationData() + { + $bucketName = 'test_bucket_name'; + $attributeCode = 'test_attribute_code'; + $expected = [ + 'type' => BucketInterface::TYPE_TERM, + 'name' => $bucketName, + 'field' => $attributeCode, + 'metric' => [['type' => 'count']], + ]; + $this->attribute->expects($this->atLeastOnce()) + ->method('getAttributeCode') + ->willReturn($attributeCode); + $actual = $this->general->getAggregationData($this->attribute, $bucketName); + $this->assertEquals($expected, $actual); + } +} diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php new file mode 100644 index 0000000000000..670592c44cec5 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php @@ -0,0 +1,63 @@ +defaultGenerator = $this->getMockBuilder(GeneratorInterface::class) + ->setMethods([]) + ->getMockForAbstractClass(); + + $this->datetimeGenerator = $this->getMockBuilder(GeneratorInterface::class) + ->setMethods([]) + ->getMockForAbstractClass(); + + $this->rangeGenerator = $this->getMockBuilder(GeneratorInterface::class) + ->setMethods([]) + ->getMockForAbstractClass(); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->collection = $objectManager->getObject( + GeneratorCollection::class, + [ + 'defaultGenerator' => $this->defaultGenerator, + 'generators' => [ + 'datetime' => $this->datetimeGenerator, + 'range' => $this->datetimeGenerator, + ], + ] + ); + } + + public function testGetSpecificGenerator() + { + $this->assertEquals($this->rangeGenerator, $this->collection->getGeneratorForType('range')); + $this->assertEquals($this->datetimeGenerator, $this->collection->getGeneratorForType('datetime')); + } + + public function testGetFallbackGenerator() + { + $this->assertEquals($this->defaultGenerator, $this->collection->getGeneratorForType('unknown_type')); + } +} diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php index 1aa8da94bfecb..509a08f978095 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php @@ -6,6 +6,8 @@ namespace Magento\CatalogSearch\Test\Unit\Model\Search; use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; +use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorCollection; +use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorInterface; class RequestGeneratorTest extends \PHPUnit_Framework_TestCase { @@ -25,11 +27,29 @@ protected function setUp() ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); + $generatorCollection = $this->getMockBuilder(GeneratorCollection::class) + ->disableOriginalConstructor() + ->setMethods(['getGeneratorForType']) + ->getMock(); + $generator = $this->getMockBuilder(GeneratorInterface::class) + ->setMethods(['getFilterData', 'getAggregationData']) + ->getMockForAbstractClass(); + $generator->expects($this->any()) + ->method('getFilterData') + ->willReturn(['some filter data goes here']); + $generator->expects($this->any()) + ->method('getAggregationData') + ->willReturn(['some aggregation data goes here']); + $generatorCollection->method('getGeneratorForType') + ->willReturn($generator); $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->object = $this->objectManagerHelper->getObject( \Magento\CatalogSearch\Model\Search\RequestGenerator::class, - ['productAttributeCollectionFactory' => $this->productAttributeCollectionFactory] + [ + 'productAttributeCollectionFactory' => $this->productAttributeCollectionFactory, + 'generatorCollection' => $generatorCollection + ] ); } @@ -132,19 +152,23 @@ public function testGenerate($countResult, $attributeOptions) $this->assertEquals( $countResult['quick_search_container']['queries'], - $this->countVal($result['quick_search_container']['queries']) + $this->countVal($result['quick_search_container']['queries']), + 'Queries count for "quick_search_container" doesn\'t match' ); $this->assertEquals( $countResult['advanced_search_container']['queries'], - $this->countVal($result['advanced_search_container']['queries']) + $this->countVal($result['advanced_search_container']['queries']), + 'Queries count for "advanced_search_container" doesn\'t match' ); $this->assertEquals( $countResult['advanced_search_container']['filters'], - $this->countVal($result['advanced_search_container']['filters']) + $this->countVal($result['advanced_search_container']['filters']), + 'Filters count for "advanced_search_container" doesn\'t match' ); $this->assertEquals( $countResult['catalog_view_container']['queries'], - $this->countVal($result['catalog_view_container']['queries']) + $this->countVal($result['catalog_view_container']['queries']), + 'Queries count for "catalog_view_container" doesn\'t match' ); } @@ -152,11 +176,12 @@ public function testGenerate($countResult, $attributeOptions) * Create attribute mock * * @param $attributeOptions - * @return \PHPUnit_Framework_MockObject_MockObject + * @return \Magento\Catalog\Model\Entity\Attribute|\PHPUnit_Framework_MockObject_MockObject */ private function createAttributeMock($attributeOptions) { - $attribute = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Attribute::class) + /** @var \Magento\Catalog\Model\Entity\Attribute|\PHPUnit_Framework_MockObject_MockObject $attribute */ + $attribute = $this->getMockBuilder(\Magento\Catalog\Model\Entity\Attribute::class) ->disableOriginalConstructor() ->setMethods( [ @@ -192,8 +217,8 @@ private function createAttributeMock($attributeOptions) ->method('getData') ->willReturnMap( [ - ['is_filterable', $attributeOptions[2]], - ['is_filterable_in_search', $attributeOptions[3]] + ['is_filterable', null, $attributeOptions[2]], + ['is_filterable_in_search', null, $attributeOptions[3]], ] ); diff --git a/app/code/Magento/CatalogSearch/etc/di.xml b/app/code/Magento/CatalogSearch/etc/di.xml index e715b5fea7cd0..1be1ff438dde0 100644 --- a/app/code/Magento/CatalogSearch/etc/di.xml +++ b/app/code/Magento/CatalogSearch/etc/di.xml @@ -237,4 +237,12 @@ + + + \Magento\CatalogSearch\Model\Search\RequestGenerator\General + + Magento\CatalogSearch\Model\Search\RequestGenerator\Decimal + + + From f7a57c28b248cc504b21ff57db773ea701baa607 Mon Sep 17 00:00:00 2001 From: Illia Grybkov Date: Wed, 14 Sep 2016 13:06:19 +0300 Subject: [PATCH 16/29] MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline - Update type hinting to use Magento\Catalog\Model\ResourceModel\Eav\Attribute (which is actually used) instead of Magento\Catalog\Model\Entity\Attribute --- .../Magento/CatalogSearch/Model/Search/RequestGenerator.php | 6 ++---- .../CatalogSearch/Model/Search/RequestGenerator/Decimal.php | 2 +- .../CatalogSearch/Model/Search/RequestGenerator/General.php | 2 +- .../Model/Search/RequestGenerator/GeneratorCollection.php | 4 ++-- .../Model/Search/RequestGenerator/GeneratorInterface.php | 2 +- .../Test/Unit/Model/Search/RequestGenerator/DecimalTest.php | 2 +- .../Test/Unit/Model/Search/RequestGenerator/GeneralTest.php | 2 +- .../Test/Unit/Model/Search/RequestGeneratorTest.php | 2 +- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php index dcfe40f248a6a..7ca34d7075ead 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php @@ -41,9 +41,7 @@ public function __construct( ) { $this->productAttributeCollectionFactory = $productAttributeCollectionFactory; $this->generatorCollection = $generatorCollection - ?: ObjectManager::getInstance()->get( - GeneratorCollection::class - ); + ?: ObjectManager::getInstance()->get(GeneratorCollection::class); } /** @@ -115,7 +113,7 @@ private function generateRequest($attributeType, $container, $useFulltext) /** * Retrieve searchable attributes * - * @return \Magento\Catalog\Model\Entity\Attribute[] + * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */ protected function getSearchableAttributes() { diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php index 5b83d1d61d9b4..5d029ab3b5c0e 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php @@ -7,7 +7,7 @@ namespace Magento\CatalogSearch\Model\Search\RequestGenerator; -use Magento\Catalog\Model\Entity\Attribute; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; use Magento\Framework\Search\Request\BucketInterface; use Magento\Framework\Search\Request\FilterInterface; diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php index 410c97e3f37d3..c9353dace2226 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php @@ -7,7 +7,7 @@ namespace Magento\CatalogSearch\Model\Search\RequestGenerator; -use Magento\Catalog\Model\Entity\Attribute; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; use Magento\Framework\Search\Request\BucketInterface; use Magento\Framework\Search\Request\FilterInterface; diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php index 6c9d03dd047e5..1149cb6cc6704 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php @@ -20,7 +20,7 @@ class GeneratorCollection /** * GeneratorCollection constructor. - * @param General $defaultGenerator + * @param GeneratorInterface $defaultGenerator * @param GeneratorInterface[] $generators */ public function __construct(GeneratorInterface $defaultGenerator, array $generators) @@ -30,7 +30,7 @@ public function __construct(GeneratorInterface $defaultGenerator, array $generat } /** - * @param $type + * @param string $type * @return GeneratorInterface */ public function getGeneratorForType($type) diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php index 981273894ccf0..fcab75c1ab9b4 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php @@ -7,7 +7,7 @@ namespace Magento\CatalogSearch\Model\Search\RequestGenerator; -use Magento\Catalog\Model\Entity\Attribute; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; interface GeneratorInterface { diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/DecimalTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/DecimalTest.php index 1220656cbd23e..67a991f518565 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/DecimalTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/DecimalTest.php @@ -6,7 +6,7 @@ namespace Magento\CatalogSearch\Test\Unit\Model\Search\RequestGenerator; -use Magento\Catalog\Model\Entity\Attribute; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; use Magento\CatalogSearch\Model\Search\RequestGenerator\Decimal; use Magento\Framework\Search\Request\BucketInterface; use Magento\Framework\Search\Request\FilterInterface; diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php index f1cff3fcad073..d40829e6e53de 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneralTest.php @@ -6,7 +6,7 @@ namespace Magento\CatalogSearch\Test\Unit\Model\Search\RequestGenerator; -use Magento\Catalog\Model\Entity\Attribute; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; use Magento\CatalogSearch\Model\Search\RequestGenerator\General; use Magento\Framework\Search\Request\BucketInterface; use Magento\Framework\Search\Request\FilterInterface; diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php index 509a08f978095..0ee31f0e40b8c 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php @@ -181,7 +181,7 @@ public function testGenerate($countResult, $attributeOptions) private function createAttributeMock($attributeOptions) { /** @var \Magento\Catalog\Model\Entity\Attribute|\PHPUnit_Framework_MockObject_MockObject $attribute */ - $attribute = $this->getMockBuilder(\Magento\Catalog\Model\Entity\Attribute::class) + $attribute = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class) ->disableOriginalConstructor() ->setMethods( [ From f73eb51eb2029a3c74fd57e162002e616a61a5e3 Mon Sep 17 00:00:00 2001 From: Illia Grybkov Date: Wed, 14 Sep 2016 17:02:01 +0300 Subject: [PATCH 17/29] MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline - Fixes after code review --- .../Model/Search/RequestGenerator.php | 18 +++++++++--------- .../Model/Search/RequestGenerator/Decimal.php | 11 +++-------- .../Model/Search/RequestGenerator/General.php | 10 ++-------- .../RequestGenerator/GeneratorInterface.php | 4 ++-- ...torCollection.php => GeneratorResolver.php} | 7 +++---- ...ctionTest.php => GeneratorResolverTest.php} | 18 +++++++++--------- .../Unit/Model/Search/RequestGeneratorTest.php | 8 ++++---- app/code/Magento/CatalogSearch/etc/di.xml | 2 +- 8 files changed, 33 insertions(+), 45 deletions(-) rename app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/{GeneratorCollection.php => GeneratorResolver.php} (86%) rename app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/{GeneratorCollectionTest.php => GeneratorResolverTest.php} (74%) diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php index 7ca34d7075ead..1dc33743d76c1 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php @@ -8,7 +8,7 @@ use Magento\Catalog\Api\Data\EavAttributeInterface; use Magento\Catalog\Model\Entity\Attribute; use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; -use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorCollection; +use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorResolver; use Magento\Framework\App\ObjectManager; use Magento\Framework\Search\Request\FilterInterface; use Magento\Framework\Search\Request\QueryInterface; @@ -27,21 +27,21 @@ class RequestGenerator private $productAttributeCollectionFactory; /** - * @var GeneratorCollection + * @var GeneratorResolver */ - private $generatorCollection; + private $generatorResolver; /** * @param CollectionFactory $productAttributeCollectionFactory - * @param GeneratorCollection $generatorCollection + * @param GeneratorResolver $generatorResolver */ public function __construct( CollectionFactory $productAttributeCollectionFactory, - GeneratorCollection $generatorCollection = null + GeneratorResolver $generatorResolver = null ) { $this->productAttributeCollectionFactory = $productAttributeCollectionFactory; - $this->generatorCollection = $generatorCollection - ?: ObjectManager::getInstance()->get(GeneratorCollection::class); + $this->generatorResolver = $generatorResolver + ?: ObjectManager::getInstance()->get(GeneratorResolver::class); } /** @@ -87,14 +87,14 @@ private function generateRequest($attributeType, $container, $useFulltext) 'filterReference' => [['ref' => $filterName]], ]; $bucketName = $attribute->getAttributeCode() . self::BUCKET_SUFFIX; - $generator = $this->generatorCollection->getGeneratorForType($attribute->getBackendType()); + $generator = $this->generatorResolver->getGeneratorForType($attribute->getBackendType()); $request['filters'][$filterName] = $generator->getFilterData($attribute, $filterName); $request['aggregations'][$bucketName] = $generator->getAggregationData($attribute, $bucketName); } } /** @var $attribute Attribute */ if (!$attribute->getIsSearchable() || in_array($attribute->getAttributeCode(), ['price', 'sku'], true)) { - //same fields have special semantics + // Some fields have their own specific handlers continue; } diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php index 5d029ab3b5c0e..52cab1c6ff942 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/Decimal.php @@ -13,11 +13,9 @@ class Decimal implements GeneratorInterface { + /** - * Generate filter data for specific attribute - * @param Attribute $attribute - * @param string $filterName - * @return array + * {@inheritdoc} */ public function getFilterData(Attribute $attribute, $filterName) { @@ -31,10 +29,7 @@ public function getFilterData(Attribute $attribute, $filterName) } /** - * Generate aggregations data for specific attribute - * @param Attribute $attribute - * @param string $bucketName - * @return array + * {@inheritdoc} */ public function getAggregationData(Attribute $attribute, $bucketName) { diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php index c9353dace2226..96362ce484b1e 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/General.php @@ -15,10 +15,7 @@ class General implements GeneratorInterface { /** - * Generate filter data for specific attribute - * @param Attribute $attribute - * @param string $filterName - * @return array + * {@inheritdoc} */ public function getFilterData(Attribute $attribute, $filterName) { @@ -31,10 +28,7 @@ public function getFilterData(Attribute $attribute, $filterName) } /** - * Generate aggregations data for specific attribute - * @param Attribute $attribute - * @param string $bucketName - * @return array + * {@inheritdoc} */ public function getAggregationData(Attribute $attribute, $bucketName) { diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php index fcab75c1ab9b4..2261addd99189 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php @@ -12,7 +12,7 @@ interface GeneratorInterface { /** - * Generate filter data for specific attribute + * Get filter data for specific attribute * @param Attribute $attribute * @param string $filterName * @return array @@ -20,7 +20,7 @@ interface GeneratorInterface public function getFilterData(Attribute $attribute, $filterName); /** - * Generate aggregations data for specific attribute + * Get aggregations data for specific attribute * @param Attribute $attribute * @param string $bucketName * @return array diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php similarity index 86% rename from app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php rename to app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php index 1149cb6cc6704..bb7cb4198379b 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorCollection.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php @@ -6,20 +6,19 @@ namespace Magento\CatalogSearch\Model\Search\RequestGenerator; -class GeneratorCollection +class GeneratorResolver { /** - * @var array|GeneratorInterface[] + * @var GeneratorInterface[] */ private $generators; /** - * @var General + * @var GeneratorInterface */ private $defaultGenerator; /** - * GeneratorCollection constructor. * @param GeneratorInterface $defaultGenerator * @param GeneratorInterface[] $generators */ diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php similarity index 74% rename from app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php rename to app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php index 670592c44cec5..dcc573ddc797e 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorCollectionTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php @@ -7,13 +7,13 @@ namespace Magento\CatalogSearch\Test\Unit\Model\Search\RequestGenerator; -use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorCollection; +use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorResolver; use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorInterface; -class GeneratorCollectionTest extends \PHPUnit_Framework_TestCase +class GeneratorResolverTest extends \PHPUnit_Framework_TestCase { - /** @var GeneratorCollection */ - private $collection; + /** @var GeneratorResolver */ + private $resolver; /** @var GeneratorInterface|\PHPUnit_Framework_MockObject_MockObject */ private $defaultGenerator; @@ -38,8 +38,8 @@ protected function setUp() ->setMethods([]) ->getMockForAbstractClass(); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->collection = $objectManager->getObject( - GeneratorCollection::class, + $this->resolver = $objectManager->getObject( + GeneratorResolver::class, [ 'defaultGenerator' => $this->defaultGenerator, 'generators' => [ @@ -52,12 +52,12 @@ protected function setUp() public function testGetSpecificGenerator() { - $this->assertEquals($this->rangeGenerator, $this->collection->getGeneratorForType('range')); - $this->assertEquals($this->datetimeGenerator, $this->collection->getGeneratorForType('datetime')); + $this->assertEquals($this->rangeGenerator, $this->resolver->getGeneratorForType('range')); + $this->assertEquals($this->datetimeGenerator, $this->resolver->getGeneratorForType('datetime')); } public function testGetFallbackGenerator() { - $this->assertEquals($this->defaultGenerator, $this->collection->getGeneratorForType('unknown_type')); + $this->assertEquals($this->defaultGenerator, $this->resolver->getGeneratorForType('unknown_type')); } } diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php index 0ee31f0e40b8c..ca56dd83444b2 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php @@ -6,7 +6,7 @@ namespace Magento\CatalogSearch\Test\Unit\Model\Search; use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; -use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorCollection; +use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorResolver; use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorInterface; class RequestGeneratorTest extends \PHPUnit_Framework_TestCase @@ -27,7 +27,7 @@ protected function setUp() ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $generatorCollection = $this->getMockBuilder(GeneratorCollection::class) + $generatorResolver = $this->getMockBuilder(GeneratorResolver::class) ->disableOriginalConstructor() ->setMethods(['getGeneratorForType']) ->getMock(); @@ -40,7 +40,7 @@ protected function setUp() $generator->expects($this->any()) ->method('getAggregationData') ->willReturn(['some aggregation data goes here']); - $generatorCollection->method('getGeneratorForType') + $generatorResolver->method('getGeneratorForType') ->willReturn($generator); $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -48,7 +48,7 @@ protected function setUp() \Magento\CatalogSearch\Model\Search\RequestGenerator::class, [ 'productAttributeCollectionFactory' => $this->productAttributeCollectionFactory, - 'generatorCollection' => $generatorCollection + 'generatorResolver' => $generatorResolver ] ); } diff --git a/app/code/Magento/CatalogSearch/etc/di.xml b/app/code/Magento/CatalogSearch/etc/di.xml index 1be1ff438dde0..f62b4e47767a2 100644 --- a/app/code/Magento/CatalogSearch/etc/di.xml +++ b/app/code/Magento/CatalogSearch/etc/di.xml @@ -237,7 +237,7 @@ - + \Magento\CatalogSearch\Model\Search\RequestGenerator\General From 08548a41af191e809ce89e31d486862079d1c8d2 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Fri, 16 Sep 2016 19:46:29 +0300 Subject: [PATCH 18/29] MAGETWO-57892: L4 Plan fails on mainline branch --- .../Setup/Fixtures/FixtureModelTest.php | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Fixtures/FixtureModelTest.php b/dev/tests/integration/testsuite/Magento/Setup/Fixtures/FixtureModelTest.php index 358786901713b..b47d45e3815e7 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Fixtures/FixtureModelTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Fixtures/FixtureModelTest.php @@ -27,6 +27,14 @@ class FixtureModelTest extends \Magento\TestFramework\Indexer\TestCase public static function setUpBeforeClass() { + $db = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getBootstrap() + ->getApplication() + ->getDbInstance(); + if (!$db->isDbDumpExists()) { + throw new \LogicException('DB dump does not exist.'); + } + $db->restoreFromDbDump(); + self::$_generatorWorkingDir = realpath(__DIR__ . '/../../../../../../../setup/src/Magento/Setup/Fixtures'); copy( self::$_generatorWorkingDir . '/tax_rates.csv', @@ -72,38 +80,4 @@ public static function tearDownAfterClass() ] ); } - - /** - * Apply fixture file - * - * @param string $fixtureFilename - */ - public function applyFixture($fixtureFilename) - { - require $fixtureFilename; - } - - /** - * Get object manager - * - * @return \Magento\Framework\ObjectManagerInterface - */ - public function getObjectManager() - { - if (!$this->_objectManager) { - $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - } - return $this->_objectManager; - } - - /** - * Reset object manager - * - * @return \Magento\Framework\ObjectManagerInterface - */ - public function resetObjectManager() - { - $this->_objectManager = null; - return $this; - } } From 688f715c905e022ab7710af74263349a52d340dd Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Wed, 21 Sep 2016 16:47:46 +0300 Subject: [PATCH 19/29] MAGETWO-52926: Impossible to find product on Store Front with name like lowerCamelCaseNumber --- .../Magento/Test/Legacy/CopyrightTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php index 582a63ceb19ed..a1ede987dac78 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php @@ -27,7 +27,7 @@ function ($filename) { public function copyrightDataProvider() { - $blackList = include __DIR__ . '/_files/copyright/blacklist.php'; + $blackList = $this->getFilesData('blacklist*.php'); $changedFiles = []; foreach (glob(__DIR__ . '/../_files/changed_files*') as $listFile) { @@ -56,4 +56,18 @@ function ($path) use ($blackList) { ); return $changedFiles; } + + /** + * @param string $filePattern + * @return array + */ + protected function getFilesData($filePattern) + { + $result = []; + foreach (glob(__DIR__ . '/_files/copyright/' . $filePattern) as $file) { + $fileData = include $file; + $result = array_merge($result, $fileData); + } + return $result; + } } From deb30e5c03099958d4dd8a5302d85dd6c1e95fb0 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Thu, 22 Sep 2016 13:57:30 +0300 Subject: [PATCH 20/29] MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline --- .../Search/RequestGenerator/GeneratorInterface.php | 2 +- .../Search/RequestGenerator/GeneratorResolver.php | 9 ++++++++- .../RequestGenerator/GeneratorResolverTest.php | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php index 2261addd99189..c43786db2b696 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php @@ -20,7 +20,7 @@ interface GeneratorInterface public function getFilterData(Attribute $attribute, $filterName); /** - * Get aggregations data for specific attribute + * Get aggregation data for specific attribute * @param Attribute $attribute * @param string $bucketName * @return array diff --git a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php index bb7cb4198379b..129a036ff2544 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php +++ b/app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php @@ -31,9 +31,16 @@ public function __construct(GeneratorInterface $defaultGenerator, array $generat /** * @param string $type * @return GeneratorInterface + * @throws \InvalidArgumentException */ public function getGeneratorForType($type) { - return isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator; + $generator = isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator; + if (!($generator instanceof GeneratorInterface)) { + throw new \InvalidArgumentException( + 'Generator must implement ' . GeneratorInterface::class + ); + } + return $generator; } } diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php index dcc573ddc797e..0b8bf882b850e 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php @@ -37,6 +37,10 @@ protected function setUp() $this->rangeGenerator = $this->getMockBuilder(GeneratorInterface::class) ->setMethods([]) ->getMockForAbstractClass(); + + $invalidTypeGenerator = $this->getMockBuilder(\stdClass::class) + ->setMethods([]); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->resolver = $objectManager->getObject( GeneratorResolver::class, @@ -45,6 +49,7 @@ protected function setUp() 'generators' => [ 'datetime' => $this->datetimeGenerator, 'range' => $this->datetimeGenerator, + 'invalid_type' => $invalidTypeGenerator, ], ] ); @@ -60,4 +65,12 @@ public function testGetFallbackGenerator() { $this->assertEquals($this->defaultGenerator, $this->resolver->getGeneratorForType('unknown_type')); } + + /** + * @expectedException InvalidArgumentException + */ + public function testGetInvalidGeneratorType() + { + $this->resolver->getGeneratorForType('invalid_type'); + } } From 9f92f936e6ee59d1caa46e0a3383e3eb8b49d48e Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Thu, 22 Sep 2016 17:59:50 +0300 Subject: [PATCH 21/29] MAGETWO-57852: [FT] There is no "Reset filter" button on grids that use UI grid component --- .../Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php | 6 +++--- .../Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php index 501d3ec65dd74..9b15cfb39a30b 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php @@ -36,13 +36,13 @@ public function processAssert( $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $salesOrderView->getOrderForm()->openTab('invoices'); /** @var Grid $grid */ - $grid = $salesOrderView->getOrderForm()->getTab('invoices')->getGridBlock(); + $grid = $salesOrderView->getOrderInvoiceGrid(); $amount = $order->getPrice(); foreach ($ids['invoiceIds'] as $key => $invoiceId) { $filter = [ 'id' => $invoiceId, - 'amount_from' => $amount[$key]['grand_invoice_total'], - 'amount_to' => $amount[$key]['grand_invoice_total'], + 'grand_total_from' => $amount[$key]['grand_invoice_total'], + 'grand_total_to' => $amount[$key]['grand_invoice_total'], ]; $grid->search($filter); $filter['amount_from'] = number_format($amount[$key]['grand_invoice_total'], 2); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml index d5b7d99661806..674b42732d2cd 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml @@ -16,5 +16,6 @@ +
From bada2dc0ed2cd4fbcf9b1a406be685ca17da43a2 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Fri, 23 Sep 2016 12:17:01 +0300 Subject: [PATCH 22/29] MAGETWO-58133: Incorrect number of login failures to lock Customer account --- .../Security/Test/TestCase/LockCustomerOnEditPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php index df1f872006561..eb18e1ded2a2a 100644 --- a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php +++ b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php @@ -125,7 +125,7 @@ public function test( $this->cmsIndex->getLinksBlock()->openLink('My Account'); $this->customerAccountIndex->getInfoBlock()->openChangePassword(); - for ($i = 0; $i < $attempts; $i++) { + for ($i = 0; $i <= $attempts; $i++) { if ($i > 0) { $this->customerAccountIndex->getInfoBlock()->checkChangePassword(); } From 935dcd731f20d7fd931b9229594e9cdbbe2aecd3 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Mon, 26 Sep 2016 10:34:05 +0300 Subject: [PATCH 23/29] MAGETWO-56587: [FT] Fix AssertProductDataInMiniShoppingCart constraint --- .../Bundle/Test/Repository/BundleProduct/CheckoutData.xml | 4 ++-- .../Test/Repository/CatalogProductVirtual/CheckoutData.xml | 5 +++++ .../app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php | 2 +- .../Test/Repository/ConfigurableProduct/CheckoutData.xml | 2 +- .../Test/Repository/DownloadableProduct/CheckoutData.xml | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml index 97c11284d77c8..3e7550b9d784e 100644 --- a/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml @@ -95,9 +95,9 @@ 1 - 756 + 755 1 - 756 + 755 diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml index 026b32c021980..5fb85d4c4f053 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml @@ -34,6 +34,11 @@ 2 + + 10 + 2 + 20 + diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php index b171a7062e942..1eb5ddf43fc52 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php @@ -46,7 +46,7 @@ class Item extends Sidebar * * @var string */ - protected $price = '.product .price'; + protected $price = '.minicart-price .price'; /** * CSS selector for update button. diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml index f075312343c21..bb9f7a4ae03b1 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml @@ -64,7 +64,7 @@ 1 - 120 + 42 1 172 diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml index 74abeeb6cb325..5170d8f9c5427 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml @@ -73,8 +73,8 @@ - 23 - 23 + 25.43 + 25.43 From 0395357fdabb4d7cfd9c48c9a289d569b18264e0 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Mon, 26 Sep 2016 12:23:49 +0300 Subject: [PATCH 24/29] MAGETWO-58133: Incorrect number of login failures to lock Customer account --- .../Security/Test/TestCase/LockCustomerOnEditPageTest.php | 2 +- .../Security/Test/TestCase/LockCustomerOnEditPageTest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php index eb18e1ded2a2a..df1f872006561 100644 --- a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php +++ b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.php @@ -125,7 +125,7 @@ public function test( $this->cmsIndex->getLinksBlock()->openLink('My Account'); $this->customerAccountIndex->getInfoBlock()->openChangePassword(); - for ($i = 0; $i <= $attempts; $i++) { + for ($i = 0; $i < $attempts; $i++) { if ($i > 0) { $this->customerAccountIndex->getInfoBlock()->checkChangePassword(); } diff --git a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml index 89435ba2fb7f8..eeb0dd7ab12e9 100644 --- a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml +++ b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml @@ -14,7 +14,7 @@ incorrect password 123123^a 123123^a - 6 + 7 From 0f5977ea4ee32dd864cb081acfc68660b5bd4e11 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Mon, 26 Sep 2016 14:46:50 +0300 Subject: [PATCH 25/29] MAGETWO-54109: Unskip Tests which Refer to Already Closed Tickets --- .../ShippingInformationManagementTest.php | 574 ++++++------------ .../Model/Address/AbstractAddressTest.php | 5 +- .../Model/BillingAddressManagementTest.php | 117 ++-- .../Unit/Model/Quote/Item/RepositoryTest.php | 474 +++------------ .../Unit/Model/QuoteAddressValidatorTest.php | 53 +- .../Test/Unit/Model/QuoteRepositoryTest.php | 89 ++- .../Model/ShippingAddressManagementTest.php | 228 +++++-- .../Model/ShippingMethodManagementTest.php | 88 +-- .../Bundle/Api/ProductLinkManagementTest.php | 1 - .../Magento/Bundle/Api/ProductServiceTest.php | 7 +- .../Api/CategoryLinkRepositoryTest.php | 22 - .../Api/GuestCartTotalRepositoryTest.php | 18 +- .../Api/ShippingMethodManagementTest.php | 5 +- .../Sales/Service/V1/CreditmemoCancelTest.php | 6 +- .../Model/Category/CategoryImageTest.php | 99 --- .../StubZendLogWriterStream.php | 34 -- .../Magento/Catalog/Model/CategoryTest.php | 21 + .../Model/Import/ProductTest.php | 1 - .../_files/quote_with_address_saved.php | 6 +- .../Model/OptionRepositoryTest.php | 1 - .../Model/DownloadableTest.php | 13 +- .../testsuite/Magento/MemoryUsageTest.php | 4 +- .../Integrity/AbstractConfig.php | 4 +- .../Php/_files/phpcpd/blacklist/common.txt | 41 +- 24 files changed, 693 insertions(+), 1218 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php delete mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php diff --git a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php index c6ef3aac3ba7e..1b68ad4ce85cf 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php @@ -7,6 +7,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase { @@ -70,10 +71,38 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase */ protected $model; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingAssignmentFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $cartExtensionFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $cartExtensionMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingAssignmentMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingMock; + protected function setUp() { - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->paymentMethodManagementMock = $this->getMock(\Magento\Quote\Api\PaymentMethodManagementInterface::class); $this->paymentDetailsFactoryMock = $this->getMock( \Magento\Checkout\Model\PaymentDetailsFactory::class, @@ -96,21 +125,6 @@ protected function setUp() $this->scopeConfigMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->totalsCollectorMock = $this->getMock(\Magento\Quote\Model\Quote\TotalsCollector::class, [], [], '', false); - $this->model = $objectManager->getObject( - \Magento\Checkout\Model\ShippingInformationManagement::class, - [ - 'paymentMethodManagement' => $this->paymentMethodManagementMock, - 'paymentDetailsFactory' => $this->paymentDetailsFactoryMock, - 'cartTotalsRepository' => $this->cartTotalsRepositoryMock, - 'quoteRepository' => $this->quoteRepositoryMock, - 'addressValidator' => $this->addressValidatorMock, - 'logger' => $this->loggerMock, - 'addressRepository' => $this->addressRepositoryMock, - 'scopeConfig' => $this->scopeConfigMock, - 'totalsCollector' => $this->totalsCollectorMock - ] - ); - $this->shippingAddressMock = $this->getMock( \Magento\Quote\Model\Quote\Address::class, [ @@ -144,39 +158,40 @@ protected function setUp() 'getStoreId', 'setShippingAddress', 'getShippingAddress', - 'collectTotals' + 'collectTotals', + 'getExtensionAttributes', + 'setExtensionAttributes', + 'setBillingAddress' ], [], '', false ); - } - - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable. - */ - public function testSaveAddressInformationIfCartIsVirtual() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 100; - $carrierCode = 'carrier_code'; - $shippingMethod = 'shipping_method'; - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); - - $addressInformationMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); - $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(true); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - - $this->model->saveAddressInformation($cartId, $addressInformationMock); + $this->shippingAssignmentFactoryMock = + $this->getMock(\Magento\Quote\Model\ShippingAssignmentFactory::class, ['create'], [], '', false); + $this->cartExtensionFactoryMock = + $this->getMock(\Magento\Quote\Api\Data\CartExtensionInterfaceFactory::class, ['create'], [], '', false); + $this->shippingFactoryMock = + $this->getMock(\Magento\Quote\Model\ShippingFactory::class, ['create'], [], '', false); + + $this->prepareObjectManager([ + [\Magento\Quote\Model\ShippingAssignmentFactory::class, $this->shippingAssignmentFactoryMock], + [\Magento\Quote\Api\Data\CartExtensionFactory::class, $this->cartExtensionFactoryMock], + [\Magento\Quote\Model\ShippingFactory::class, $this->shippingFactoryMock], + ]); + + $this->model = new \Magento\Checkout\Model\ShippingInformationManagement( + $this->paymentMethodManagementMock, + $this->paymentDetailsFactoryMock, + $this->cartTotalsRepositoryMock, + $this->quoteRepositoryMock, + $this->addressValidatorMock, + $this->loggerMock, + $this->addressRepositoryMock, + $this->scopeConfigMock, + $this->totalsCollectorMock + ); } /** @@ -185,19 +200,23 @@ public function testSaveAddressInformationIfCartIsVirtual() */ public function testSaveAddressInformationIfCartIsEmpty() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); + + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(0); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') @@ -208,468 +227,209 @@ public function testSaveAddressInformationIfCartIsEmpty() } /** - * @expectedException \Magento\Framework\Exception\StateException - * @expectedExceptionMessage Shipping address is not set + * @param string $shippingMethod */ - public function testSaveAddressInformationIfShippingAddressNotSet() + private function setShippingAssignmentsMocks($shippingMethod) { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 100; - $carrierCode = 'carrier_code'; - $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); + $this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null); - $addressInformationMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); - $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); + $this->cartExtensionMock = $this->getMock( + \Magento\Quote\Api\Data\CartExtension::class, + ['getShippingAssignments', 'setShippingAssignments'], + [], + '', + false + ); + $this->cartExtensionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->cartExtensionMock); + $this->cartExtensionMock->expects($this->once())->method('getShippingAssignments')->willReturn(null); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $this->shippingAssignmentMock = $this->getMock( + \Magento\Quote\Model\ShippingAssignment::class, + [], + [], + '', + false + ); + $this->shippingAssignmentFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->shippingAssignmentMock); + $this->shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn(null); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $this->shippingMock = $this->getMock(\Magento\Quote\Model\Shipping::class, [], [], '', false); + $this->shippingFactoryMock->expects($this->once())->method('create')->willReturn($this->shippingMock); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') + $this->shippingMock->expects($this->once()) + ->method('setAddress') ->with($this->shippingAddressMock) ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->shippingMock->expects($this->once())->method('setMethod')->with($shippingMethod)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) + $this->shippingAssignmentMock->expects($this->once()) + ->method('setShipping') + ->with($this->shippingMock) ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(false); - $this->model->saveAddressInformation($cartId, $addressInformationMock); - } - - /** - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Unable to save address. Please check input data. - */ - public function testSaveAddressInformationThrowExceptionWhileAddressSaving() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 100; - $carrierCode = 'carrier_code'; - $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $exception = new \Exception(); - - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); - $addressInformationMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); - $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) + $this->cartExtensionMock->expects($this->once()) + ->method('setShippingAssignments') + ->with([$this->shippingAssignmentMock]) ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->willThrowException($exception); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); - - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) + ->method('setExtensionAttributes') + ->with($this->cartExtensionMock) ->willReturnSelf(); - - $this->loggerMock->expects($this->once())->method('critical')->with($exception); - - $this->model->saveAddressInformation($cartId, $addressInformationMock); } /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Carrier with such method not found: carrier_code, shipping_method + * @expectedException \Magento\Framework\Exception\StateException + * @expectedExceptionMessage Shipping address is not set */ - public function testSaveAddressInformationIfCarrierCodeIsInvalid() + public function testSaveAddressInformationIfShippingAddressNotSet() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); + $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); - - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); - - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once()) - ->method('getShippingRateByCode') - ->with($shippingMethod) - ->willReturn(false); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(null); $this->model->saveAddressInformation($cartId, $addressInformationMock); } /** * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Wrong minimum amount. + * @expectedExceptionMessage Unable to save shipping information. Please check input data. */ - public function testSaveAddressInformationIfMinimumAmountIsNotValid() + public function testSaveAddressInformationIfCanNotSaveQuote() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $storeId = 500; - $minAmountExceptionMessage = __('Wrong minimum amount.'); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(true); - $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); - $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(true)->willReturn(false); - $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); + $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with($cartId) ->willReturn($this->quoteMock); - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); - - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once()) - ->method('getShippingRateByCode') - ->with($shippingMethod) - ->willReturn($this->getMock(\Magento\Quote\Model\Quote\Address\Rate::class, [], [], '', false)); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(100); + $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddress)->willReturnSelf(); - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->with('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId) - ->willReturn($minAmountExceptionMessage); + $this->quoteRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->quoteMock) + ->willThrowException(new \Exception()); $this->model->saveAddressInformation($cartId, $addressInformationMock); } /** - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Unable to save shipping information. Please check input data. + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Carrier with such method not found: carrier_code, shipping_method */ - public function testSaveAddressInformationIfCanNotSaveQuote() + public function testSaveAddressInformationIfCarrierCodeIsInvalid() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $exception = new \Exception(); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(true); - $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); - $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(true)->willReturn(true); - $this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with($cartId) ->willReturn($this->quoteMock); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock) - ->willThrowException($exception); - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(100); + $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddress)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->shippingAddressMock); - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->quoteRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->quoteMock); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('save')->willReturnSelf(); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); $this->shippingAddressMock->expects($this->once()) ->method('getShippingRateByCode') ->with($shippingMethod) - ->willReturn($this->getMock(\Magento\Quote\Model\Quote\Address\Rate::class, [], [], '', false)); - - $this->loggerMock->expects($this->once())->method('critical')->with($exception); + ->willReturn(false); $this->model->saveAddressInformation($cartId, $addressInformationMock); } public function testSaveAddressInformation() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(true); - $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); - $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(true)->willReturn(true); - $this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with($cartId) ->willReturn($this->quoteMock); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock); - - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(100); + $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddress)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->shippingAddressMock); + + $this->quoteRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->quoteMock); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); $this->shippingAddressMock->expects($this->once()) ->method('getShippingRateByCode') ->with($shippingMethod) - ->willReturn($this->getMock(\Magento\Quote\Model\Quote\Address\Rate::class, [], [], '', false)); + ->willReturn('rates'); $paymentDetailsMock = $this->getMock(\Magento\Checkout\Api\Data\PaymentDetailsInterface::class); $this->paymentDetailsFactoryMock->expects($this->once())->method('create')->willReturn($paymentDetailsMock); @@ -679,18 +439,38 @@ public function testSaveAddressInformation() ->method('getList') ->with($cartId) ->willReturn([$paymentMethodMock]); - $totalsMock = $this->getMock(\Magento\Quote\Api\Data\TotalsInterface::class); - $this->cartTotalsRepositoryMock->expects($this->once())->method('get')->with($cartId)->willReturn($totalsMock); + + $cartTotalsMock = $this->getMock(\Magento\Quote\Api\Data\TotalsInterface::class); + $this->cartTotalsRepositoryMock->expects($this->once()) + ->method('get') + ->with($cartId) + ->willReturn($cartTotalsMock); $paymentDetailsMock->expects($this->once()) ->method('setPaymentMethods') ->with([$paymentMethodMock]) ->willReturnSelf(); - $paymentDetailsMock->expects($this->once())->method('setTotals')->with($totalsMock)->willReturnSelf(); + $paymentDetailsMock->expects($this->once())->method('setTotals')->with()->willReturnSelf($cartTotalsMock); $this->assertEquals( $paymentDetailsMock, $this->model->saveAddressInformation($cartId, $addressInformationMock) ); } + + /** + * @param $map + */ + private function prepareObjectManager($map) + { + $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf(); + $objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + $reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); + $reflectionProperty = $reflectionClass->getProperty('_instance'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($objectManagerMock); + } } diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php index 4e0922721de5c..32112ccdeb1ae 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php @@ -245,15 +245,14 @@ public function testSetData() */ public function testSetDataWithMultidimensionalArray() { - $this->markTestSkipped('Need to revert changes from MAGETWO-39106 and then modify this test.'); $expected = [ 'key' => 'value', - 'array' => 'value1', + 'street' => 'value1', ]; $key = [ 'key' => 'value', - 'array' => [ + 'street' => [ 'key1' => 'value1', ] ]; diff --git a/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php index 3219b137b4775..114ee560059ee 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php @@ -76,95 +76,40 @@ public function testGetAddress() $this->assertEquals($addressMock, $this->model->get('cartId')); } - /** - * @return void - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage error123 - */ - public function testSetAddressValidationFailed() - { - $this->markTestSkipped('MAGETWO-48531'); - $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with('cartId') - ->will($this->returnValue($quoteMock)); - - $this->validatorMock->expects($this->once()) - ->method('validate') - ->will($this->throwException(new \Magento\Framework\Exception\NoSuchEntityException(__('error123')))); - - $this->model->assign('cartId', $address); - } - /** * @return void */ public function testSetAddress() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $useForShipping = true; $addressId = 1; - $customerAddressId = 10; $address = $this->getMock( \Magento\Quote\Model\Quote\Address::class, - ['setSaveInAddressBook', 'getCustomerAddressId', 'getSaveInAddressBook'], + ['getId'], [], '', false ); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($quoteMock); - $this->validatorMock->expects($this->once())->method('validate') - ->with($address) - ->willReturn(true); - - $address->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); - $address->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class, [], [], '', false); - $this->addressRepository->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); - - $quoteBillingAddress = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false); - $quoteBillingAddress->expects($this->once())->method('getId')->will($this->returnValue($addressId)); - $quoteMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($quoteBillingAddress); - $quoteBillingAddress->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - - $quoteShippingAddress = $this->getMock( - \Magento\Quote\Model\Quote\Address::class, - ['setSaveInAddressBook', 'setSameAsBilling', 'setCollectShippingRates', 'importCustomerAddressData'], + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['removeAddress', 'getBillingAddress', 'setBillingAddress', 'setDataChanges'], [], '', false ); - $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($quoteShippingAddress); - $quoteShippingAddress->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $quoteShippingAddress->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $quoteBillingAddress->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $quoteMock->expects($this->once())->method('setBillingAddress')->with($quoteBillingAddress)->willReturnSelf(); - - $quoteShippingAddress->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $quoteShippingAddress->expects($this->once())->method('setCollectShippingRates')->with(true)->willReturnSelf(); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($cartId) + ->willReturn($quoteMock); - $quoteMock->expects($this->once())->method('setShippingAddress')->with($quoteShippingAddress); - $quoteMock->expects($this->once())->method('setDataChanges')->with(true); + $address->expects($this->exactly(2))->method('getId')->willReturn($addressId); + $quoteMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($address); + $quoteMock->expects($this->once())->method('removeAddress')->with($addressId)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setBillingAddress')->with($address)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setDataChanges')->with(1)->willReturnSelf(); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $this->assertEquals($addressId, $this->model->assign($cartId, $address, $useForShipping)); @@ -177,27 +122,41 @@ public function testSetAddress() */ public function testSetAddressWithInabilityToSaveQuote() { - $this->markTestSkipped('MAGETWO-48531'); - $address = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false, false); + $cartId = 100; + $addressId = 1; + + $address = $this->getMock( + \Magento\Quote\Model\Quote\Address::class, + ['getId'], + [], + '', + false + ); + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['removeAddress', 'getBillingAddress', 'setBillingAddress', 'setDataChanges'], + [], + '', + false + ); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') - ->with('cartId') - ->will($this->returnValue($quoteMock)); + ->with($cartId) + ->willReturn($quoteMock); - $this->validatorMock->expects($this->once())->method('validate') - ->with($address) - ->will($this->returnValue(true)); + $address->expects($this->once())->method('getId')->willReturn($addressId); + $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($address); + $quoteMock->expects($this->once())->method('removeAddress')->with($addressId)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setBillingAddress')->with($address)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setDataChanges')->with(1)->willReturnSelf(); - $quoteMock->expects($this->once())->method('setBillingAddress')->with($address); - $quoteMock->expects($this->once())->method('setDataChanges')->with(true); $this->quoteRepositoryMock->expects($this->once()) ->method('save') ->with($quoteMock) ->willThrowException( new \Exception('Some DB Error') ); - $this->model->assign('cartId', $address); + $this->model->assign($cartId, $address); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php index 76c3766d1f248..c8e186aaff3c2 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php @@ -30,7 +30,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $dataMock; + protected $itemMock; /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -58,6 +58,11 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $shippingAddressMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $optionsProcessorMock; + /** * @return void */ @@ -67,7 +72,7 @@ protected function setUp() $this->productRepositoryMock = $this->getMock(\Magento\Catalog\Api\ProductRepositoryInterface::class); $this->itemDataFactoryMock = $this->getMock(\Magento\Quote\Api\Data\CartItemInterfaceFactory::class, ['create'], [], '', false); - $this->dataMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false); + $this->itemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false); $this->quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); $this->productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); $methods = ['getId', 'getSku', 'getQty', 'setData', '__wakeUp', 'getProduct', 'addProduct']; @@ -88,6 +93,20 @@ protected function setUp() false ); + $this->optionsProcessorMock = $this->getMock( + \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor::class, + [], + [], + '', + false + ); + $this->prepareObjectManager([ + [ + \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor::class, + $this->optionsProcessorMock + ] + ]); + $this->repository = new \Magento\Quote\Model\Quote\Item\Repository( $this->quoteRepositoryMock, $this->productRepositoryMock, @@ -96,395 +115,40 @@ protected function setUp() ); } - /** - * @param null|string|bool|int|float $value - * @return void - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Invalid value of - * @dataProvider addItemWithInvalidQtyDataProvider - */ - public function testSaveItemWithInvalidQty($value) - { - $this->markTestSkipped('MAGETWO-48531'); - $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue($value)); - $this->repository->save($this->dataMock); - } - - /** - * @return array - */ - public function addItemWithInvalidQtyDataProvider() - { - return [ - ['string'], - [0], - [''], - [null], - [-12], - [false], - [-13.1], - ]; - } - - /** - * @return void - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Please specify all the required information. - */ - public function testSaveCouldNotAddProduct() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock - ->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn('Please specify all the required information.'); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteRepositoryMock->expects($this->never())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->never()) - ->method('getAllItems'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->repository->save($this->dataMock); - } - - /** - * @return void - * @expectedException \Magento\Framework\Exception\CouldNotSaveException - * @expectedExceptionMessage Could not save quote - */ - public function testSaveCouldNotSaveException() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock - ->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn($this->productMock); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $exceptionMessage = 'Could not save quote'; - $exception = new \Magento\Framework\Exception\CouldNotSaveException(__($exceptionMessage)); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock) - ->willThrowException($exception); - $this->quoteMock - ->expects($this->never()) - ->method('getAllItems'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->repository->save($this->dataMock); - } - /** * @return void */ public function testSave() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock - ->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn($this->productMock); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $this->quoteMock - ->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); - } + $itemId = 20; - public function testSaveWithCustomOption() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn($this->productMock); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $this->quoteMock->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); - } + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getItems', 'setItems', 'collectTotals', 'getLastAddedItem'], + [], + '', + false + ); - /** - * @return void - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Cart 11 doesn't contain item 5 - */ - public function testUpdateItemWithInvalidQuoteItem() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); + $this->itemMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue(false)); - $this->quoteItemMock->expects($this->never())->method('setData'); - $this->quoteItemMock->expects($this->never())->method('addProduct'); + ->method('getActive') + ->with($cartId) + ->willReturn($quoteMock); - $this->repository->save($this->dataMock); - } + $quoteMock->expects($this->once())->method('getItems')->willReturn([]); + $quoteMock->expects($this->once()) + ->method('setItems') + ->with([$this->itemMock]) + ->willReturnSelf(); - /** - * @return void - * @expectedException \Magento\Framework\Exception\CouldNotSaveException - * @expectedExceptionMessage Could not save quote - */ - public function testUpdateItemWithCouldNotSaveException() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); - $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple'); - $this->quoteItemMock->expects($this->never())->method('setData'); - $this->productRepositoryMock - ->expects($this->never())->method('get'); - $this->quoteItemMock->expects($this->never())->method('addProduct'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock - ->expects($this->never()) - ->method('getAllItems'); - $this->quoteItemMock->expects($this->never())->method('getId'); - $exceptionMessage = 'Could not save quote'; - $exception = new \Magento\Framework\Exception\CouldNotSaveException(__($exceptionMessage)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock) - ->willThrowException($exception); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->repository->save($this->dataMock); - } + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); - /** - * @return void - */ - public function testUpdateItemQty() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getId')->willReturn($itemId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock); - $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple'); - $this->quoteItemMock->expects($this->never())->method('setData'); - $this->productRepositoryMock - ->expects($this->never())->method('get'); - $this->quoteItemMock->expects($this->never())->method('addProduct'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId')->willReturn($itemId); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->quoteMock->expects($this->once()) - ->method('updateItem') - ->with($itemId, $buyRequest) - ->willReturn($this->dataMock); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); - } + $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $quoteMock->expects($this->once())->method('getLastAddedItem')->willReturn($itemId); - /** - * @return void - */ - public function testUpdateItemOptions() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $cartItemProcessorMock = $this->getMock(\Magento\Quote\Model\Quote\Item\CartItemProcessorInterface::class); - $this->repository = new \Magento\Quote\Model\Quote\Item\Repository( - $this->quoteRepositoryMock, - $this->productRepositoryMock, - $this->itemDataFactoryMock, - ['simple' => $cartItemProcessorMock, 'custom_options' => $this->customOptionProcessor] - ); - $requestMock = $this->getMock(\Magento\Framework\DataObject::class, ['setQty', 'getData'], [], '', false); - $cartItemProcessorMock->expects($this->once())->method('convertToBuyRequest')->willReturn($requestMock); - $cartItemProcessorMock - ->expects($this->once()) - ->method('processOptions') - ->willReturn($this->quoteItemMock); - $requestMock->expects($this->once())->method('setQty')->with(12)->willReturnSelf(); - $requestMock->expects($this->once()) - ->method('getData') - ->willReturn([]); - $this->quoteMock - ->expects($this->once()) - ->method('updateItem') - ->with($itemId, $buyRequest) - ->willReturn($this->quoteItemMock); - $this->dataMock->expects($this->any())->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock); - $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple'); - $this->productRepositoryMock - ->expects($this->never())->method('get'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId')->willReturn($itemId); - $this->quoteItemMock->expects($this->any())->method('getQty')->willReturn(12); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); + $this->assertEquals($itemId, $this->repository->save($this->itemMock)); } /** @@ -512,16 +176,20 @@ public function testDeleteWithInvalidQuoteItem() */ public function testDeleteWithCouldNotSaveException() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 11; $itemId = 5; $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + ->method('getActive') + ->with($cartId) + ->willReturn($this->quoteMock); $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + ->method('getItemById') + ->with($itemId) + ->willReturn($this->quoteItemMock); $this->quoteMock->expects($this->once()) - ->method('removeItem')->with($itemId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + ->method('removeItem') + ->with($itemId) + ->willReturn($this->quoteMock); $exceptionMessage = 'Could not remove item from quote'; $exception = new \Magento\Framework\Exception\CouldNotSaveException(__($exceptionMessage)); $this->quoteRepositoryMock->expects($this->once()) @@ -537,13 +205,23 @@ public function testDeleteWithCouldNotSaveException() */ public function testGetList() { - $this->markTestSkipped('MAGETWO-48531'); + $productType = 'type'; $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('getActive') ->with(33) ->will($this->returnValue($quoteMock)); $itemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false); - $quoteMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); + $quoteMock->expects($this->once())->method('getAllVisibleItems')->will($this->returnValue([$itemMock])); + $itemMock->expects($this->once())->method('getProductType')->willReturn($productType); + + $this->optionsProcessorMock->expects($this->once()) + ->method('addProductOptions') + ->with($productType, $itemMock) + ->willReturn($itemMock); + $this->optionsProcessorMock->expects($this->once()) + ->method('applyCustomOptions') + ->with($itemMock) + ->willReturn($itemMock); $this->assertEquals([$itemMock], $this->repository->getList(33)); } @@ -553,17 +231,35 @@ public function testGetList() */ public function testDeleteById() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 11; $itemId = 5; $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + ->method('getActive') + ->with($cartId) + ->willReturn($this->quoteMock); $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + ->method('getItemById') + ->with($itemId) + ->willReturn($this->quoteItemMock); $this->quoteMock->expects($this->once())->method('removeItem'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); $this->assertTrue($this->repository->deleteById($cartId, $itemId)); } + + /** + * @param $map + */ + private function prepareObjectManager($map) + { + $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf(); + $objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + $reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); + $reflectionProperty = $reflectionClass->getProperty('_instance'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($objectManagerMock); + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php index 2ba9aaa751e4d..9d75c219e6978 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php @@ -96,10 +96,10 @@ public function testValidateInvalidCustomer() */ public function testValidateInvalidAddress() { - $this->markTestSkipped('MAGETWO-48531'); $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $this->customerRepositoryMock->expects($this->never())->method('getById'); - $address->expects($this->atLeastOnce())->method('getId')->willReturn(101); + $address->expects($this->atLeastOnce())->method('getCustomerAddressId')->willReturn(101); + $address->expects($this->once())->method('getId')->willReturn(101); $this->addressRepositoryMock->expects($this->once())->method('getById') ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException()); @@ -118,70 +118,23 @@ public function testValidateNewAddress() $this->assertTrue($this->model->validate($address)); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Invalid address id 100 - */ - public function testValidateWithAddressOfOtherCustomer() - { - $this->markTestSkipped('MAGETWO-48531'); - $addressCustomer = 100; - $addressId = 100; - $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class); - - $this->customerRepositoryMock->expects($this->once())->method('getById')->with($addressCustomer) - ->willReturn($customerMock); - $this->addressRepositoryMock->expects($this->once())->method('getById')->willReturn($this->quoteAddressMock); - $customerMock->expects($this->once())->method('getId')->willReturn(42); - $address->expects($this->atLeastOnce())->method('getId')->willReturn($addressId); - $address->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($addressCustomer); - - $this->quoteAddressMock->expects($this->once())->method('getCustomerId')->willReturn(42); - $this->model->validate($address); - } - - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Invalid address id 42 - */ - public function testValidateWithInvalidCustomerAddressId() - { - $this->markTestSkipped('MAGETWO-48531'); - $customerAddressId = 42; - $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $customerAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class); - - $address->expects($this->atLeastOnce())->method('getCustomerAddressId')->willReturn($customerAddressId); - $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerMock); - $customerMock->expects($this->once())->method('getAddresses')->willReturn([$customerAddress]); - $customerAddress->expects($this->once())->method('getId')->willReturn(43); - - $this->model->validate($address); - } - public function testValidateWithValidAddress() { - $this->markTestSkipped('MAGETWO-48531'); $addressCustomer = 100; - $addressId = 100; $customerAddressId = 42; $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $address->expects($this->atLeastOnce())->method('getId')->willReturn($addressId); $address->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($addressCustomer); $address->expects($this->atLeastOnce())->method('getCustomerAddressId')->willReturn($customerAddressId); $customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class); $customerAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($customerMock); + $this->customerRepositoryMock->expects($this->exactly(2))->method('getById')->willReturn($customerMock); $customerMock->expects($this->once())->method('getId')->willReturn($addressCustomer); $this->addressRepositoryMock->expects($this->once())->method('getById')->willReturn($this->quoteAddressMock); $this->quoteAddressMock->expects($this->any())->method('getCustomerId')->willReturn($addressCustomer); - $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerMock); $customerMock->expects($this->once())->method('getAddresses')->willReturn([$customerAddress]); $customerAddress->expects($this->once())->method('getId')->willReturn(42); diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php index 3bd838d9d4b75..891eb108b224d 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\ExtensionAttribute\JoinProcessorInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\QuoteRepository\LoadHandler; +use Magento\Quote\Model\QuoteRepository\SaveHandler; use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory; /** @@ -63,6 +64,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase */ private $loadHandlerMock; + /** + * @var LoadHandler|\PHPUnit_Framework_MockObject_MockObject + */ + private $saveHandlerMock; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -91,7 +97,9 @@ protected function setUp() 'setSharedStoreIds', 'save', 'delete', - 'getCustomerId' + 'getCustomerId', + 'getStoreId', + 'getData' ], [], '', @@ -136,10 +144,16 @@ protected function setUp() ); $this->loadHandlerMock = $this->getMock(LoadHandler::class, [], [], '', false); + $this->saveHandlerMock = $this->getMock(SaveHandler::class, [], [], '', false); + $reflection = new \ReflectionClass(get_class($this->model)); $reflectionProperty = $reflection->getProperty('loadHandler'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->model, $this->loadHandlerMock); + + $reflectionProperty = $reflection->getProperty('saveHandler'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $this->saveHandlerMock); } /** @@ -235,7 +249,6 @@ public function testGetForCustomerAfterGet() public function testGetWithSharedStoreIds() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 16; $sharedStoreIds = [1, 2]; @@ -252,7 +265,11 @@ public function testGetWithSharedStoreIds() ->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds)); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + $this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds)); } @@ -316,7 +333,6 @@ public function testGetActiveWithExceptionById() */ public function testGetActiveWithExceptionByIsActive() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 15; $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); @@ -330,12 +346,16 @@ public function testGetActiveWithExceptionByIsActive() $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(0); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + $this->model->getActive($cartId); } public function testGetActive() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 15; $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); @@ -347,15 +367,18 @@ public function testGetActive() ->with($cartId) ->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1); + $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(1); + + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); - $this->assertEquals($this->quoteMock, $this->model->getActive($cartId)); $this->assertEquals($this->quoteMock, $this->model->getActive($cartId)); } public function testGetActiveWithSharedStoreIds() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 16; $sharedStoreIds = [1, 2]; @@ -371,15 +394,18 @@ public function testGetActiveWithSharedStoreIds() ->with($cartId) ->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1); + $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(1); + + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); - $this->assertEquals($this->quoteMock, $this->model->getActive($cartId, $sharedStoreIds)); $this->assertEquals($this->quoteMock, $this->model->getActive($cartId, $sharedStoreIds)); } public function testGetActiveForCustomer() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 17; $customerId = 23; @@ -394,19 +420,50 @@ public function testGetActiveForCustomer() $this->quoteMock->expects($this->exactly(2))->method('getId')->willReturn($cartId); $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + $this->assertEquals($this->quoteMock, $this->model->getActiveForCustomer($customerId)); $this->assertEquals($this->quoteMock, $this->model->getActiveForCustomer($customerId)); } public function testSave() { - $this->markTestSkipped('MAGETWO-48531'); + $cartId = 100; + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getId', 'getCustomerId', 'getStoreId', 'hasData', 'setData'], + [], + '', + false + ); + $quoteMock->expects($this->exactly(3))->method('getId')->willReturn($cartId); + $quoteMock->expects($this->once())->method('getCustomerId')->willReturn(2); + $quoteMock->expects($this->once())->method('getStoreId')->willReturn(5); + + $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->once())->method('getId')->willReturn($cartId); + $this->quoteMock->expects($this->once())->method('setSharedStoreIds'); $this->quoteMock->expects($this->once()) - ->method('save'); - $this->quoteMock->expects($this->exactly(1))->method('getId')->willReturn(1); - $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); + ->method('load') + ->with($cartId) + ->willReturn($this->storeMock); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + + $this->quoteMock->expects($this->once())->method('getData')->willReturn(['key' => 'value']); + + $quoteMock->expects($this->once())->method('hasData')->with('key')->willReturn(false); + $quoteMock->expects($this->once())->method('setData')->with('key', 'value')->willReturnSelf(); - $this->model->save($this->quoteMock); + $this->saveHandlerMock->expects($this->once())->method('save')->with($quoteMock)->willReturn($quoteMock); + $this->model->save($quoteMock); } public function testDelete() diff --git a/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php index 09125c0328725..abae7bae110e6 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php @@ -50,6 +50,16 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase */ protected $totalsCollectorMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $addressRepository; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $amountErrorMessageMock; + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -66,7 +76,10 @@ protected function setUp() 'save', 'getId', 'getCustomerAddressId', - 'getSaveInAddressBook' + 'getSaveInAddressBook', + 'getSameAsBilling', + 'importCustomerAddressData', + 'setSaveInAddressBook', ], [], '', @@ -82,6 +95,22 @@ protected function setUp() '', false ); + $this->addressRepository = $this->getMock(\Magento\Customer\Api\AddressRepositoryInterface::class); + + $this->amountErrorMessageMock = $this->getMock( + \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class, + ['getMessage'], + [], + '', + false + ); + $this->prepareObjectManager([ + [ + \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class, + $this->amountErrorMessageMock + ] + ]); + $this->service = $this->objectManager->getObject( \Magento\Quote\Model\ShippingAddressManagement::class, [ @@ -89,7 +118,8 @@ protected function setUp() 'addressValidator' => $this->validatorMock, 'logger' => $this->getMock(\Psr\Log\LoggerInterface::class), 'scopeConfig' => $this->scopeConfigMock, - 'totalsCollector' => $this->totalsCollectorMock + 'totalsCollector' => $this->totalsCollectorMock, + 'addressRepository' => $this->addressRepository ] ); } @@ -114,34 +144,58 @@ public function testSetAddressValidationFailed() public function testSetAddress() { - $this->markTestSkipped('MAGETWO-48531'); $addressId = 1; - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); + $customerAddressId = 150; + + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getIsMultiShipping', 'isVirtual', 'validateMinimumAmount', 'setShippingAddress', 'getShippingAddress'], + [], + '', + false + ); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with('cart867') - ->will($this->returnValue($quoteMock)); + ->willReturn($quoteMock); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $quoteMock->expects($this->once()) + ->method('setShippingAddress') + ->with($this->quoteAddressMock) + ->willReturnSelf(); + + $this->quoteAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); + + $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); + $this->addressRepository->expects($this->once()) + ->method('getById') + ->with($customerAddressId) + ->willReturn($customerAddressMock); $this->validatorMock->expects($this->once())->method('validate') ->with($this->quoteAddressMock) - ->will($this->returnValue(true)); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($quoteMock, $this->quoteAddressMock); - $this->quoteAddressMock->expects($this->once())->method('save')->willReturnSelf(); - $this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); + ->willReturn(true); - $quoteMock->expects($this->any()) - ->method('setShippingAddress') - ->with($this->quoteAddressMock) + $quoteMock->expects($this->exactly(3))->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->once()) + ->method('importCustomerAddressData') + ->with($customerAddressMock) ->willReturnSelf(); - $quoteMock->expects($this->any()) - ->method('getShippingAddress') - ->will($this->returnValue($this->quoteAddressMock)); - $quoteMock->expects($this->once())->method('validateMinimumAmount')->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + $quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false); + $quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('save')->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); $this->assertEquals($addressId, $this->service->assign('cart867', $this->quoteAddressMock)); } @@ -174,52 +228,122 @@ public function testSetAddressForVirtualProduct() */ public function testSetAddressWithInabilityToSaveQuote() { - $this->markTestSkipped('MAGETWO-48531'); $this->quoteAddressMock->expects($this->once())->method('save')->willThrowException( new \Exception('Unable to save address. Please check input data.') ); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($quoteMock, $this->quoteAddressMock); + $customerAddressId = 150; + + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getIsMultiShipping', 'isVirtual', 'validateMinimumAmount', 'setShippingAddress', 'getShippingAddress'], + [], + '', + false + ); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with('cart867') - ->will($this->returnValue($quoteMock)); + ->willReturn($quoteMock); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $quoteMock->expects($this->once()) + ->method('setShippingAddress') + ->with($this->quoteAddressMock) + ->willReturnSelf(); + + $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); + + $this->addressRepository->expects($this->once()) + ->method('getById') + ->with($customerAddressId) + ->willReturn($customerAddressMock); $this->validatorMock->expects($this->once())->method('validate') ->with($this->quoteAddressMock) - ->will($this->returnValue(true)); + ->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); + + $quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->once()) + ->method('importCustomerAddressData') + ->with($customerAddressMock) + ->willReturnSelf(); + + $this->quoteAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + $quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false); + $quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(true); + $this->service->assign('cart867', $this->quoteAddressMock); } /** * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Incorrect amount */ public function testSetAddressWithViolationOfMinimumAmount() { - $this->markTestSkipped('MAGETWO-48531'); - $storeId = 12; - $this->quoteAddressMock->expects($this->once())->method('save'); + $customerAddressId = 150; - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with('cart123') - ->will($this->returnValue($quoteMock)); + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getIsMultiShipping', 'isVirtual', 'validateMinimumAmount', 'setShippingAddress', 'getShippingAddress'], + [], + '', + false + ); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with('cart867') + ->willReturn($quoteMock); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->quoteAddressMock); - $quoteMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($quoteMock, $this->quoteAddressMock); - $this->scopeConfigMock->expects($this->once())->method('getValue') - ->with('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); - - $this->service->assign('cart123', $this->quoteAddressMock); + $quoteMock->expects($this->once()) + ->method('setShippingAddress') + ->with($this->quoteAddressMock) + ->willReturnSelf(); + + $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); + + $this->addressRepository->expects($this->once()) + ->method('getById') + ->with($customerAddressId) + ->willReturn($customerAddressMock); + + $this->validatorMock->expects($this->once())->method('validate') + ->with($this->quoteAddressMock) + ->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); + + $quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->once()) + ->method('importCustomerAddressData') + ->with($customerAddressMock) + ->willReturnSelf(); + + $this->quoteAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + + $this->amountErrorMessageMock->expects($this->once()) + ->method('getMessage') + ->willReturn(__('Incorrect amount')); + $quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false); + $quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(false); + + $this->service->assign('cart867', $this->quoteAddressMock); } public function testGetAddress() @@ -251,4 +375,20 @@ public function testGetAddressOfQuoteWithVirtualProducts() $this->service->get('cartId'); } + + /** + * @param $map + */ + private function prepareObjectManager($map) + { + $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf(); + $objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + $reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); + $reflectionProperty = $reflectionClass->getProperty('_instance'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($objectManagerMock); + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php index 5f31b7b1219ce..bb0eab1d8aed2 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php @@ -311,12 +311,13 @@ public function testGetList() */ public function testSetMethodWithInputException() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(0)); $this->quote->expects($this->never())->method('isVirtual'); @@ -329,13 +330,14 @@ public function testSetMethodWithInputException() */ public function testSetMethodWithVirtualProduct() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(true)); @@ -348,12 +350,13 @@ public function testSetMethodWithVirtualProduct() */ public function testSetMethodWithoutShippingAddress() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) @@ -363,60 +366,34 @@ public function testSetMethodWithoutShippingAddress() $this->model->set($cartId, $carrierCode, $methodCode); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Carrier with such method not found: 34, 56 - */ - public function testSetMethodWithNotFoundMethod() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 12; - $carrierCode = 34; - $methodCode = 56; - $countryId = 1; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); - $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quote->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); - $this->shippingAddress->expects($this->once()) - ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddress->expects($this->once()) - ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddress->expects($this->once()) - ->method('getShippingRateByCode')->will($this->returnValue(false)); - $this->shippingAddress->expects($this->never())->method('save'); - - $this->model->set($cartId, $carrierCode, $methodCode); - } - /** * @expectedException \Magento\Framework\Exception\CouldNotSaveException * @expectedExceptionMessage Cannot set shipping method. Custom Error */ public function testSetMethodWithCouldNotSaveException() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); - $this->shippingAddress->expects($this->once()) - ->method('getCountryId')->will($this->returnValue($countryId)); + ->method('getShippingAddress') + ->willReturn($this->shippingAddress); $this->shippingAddress->expects($this->once()) - ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); + ->method('getCountryId') + ->willReturn($countryId); $this->shippingAddress->expects($this->once()) - ->method('getShippingRateByCode')->will($this->returnValue(true)); + ->method('setShippingMethod') + ->with($carrierCode . '_' . $methodCode); $exception = new \Exception('Custom Error'); - $this->quote->expects($this->once())->method('collectTotals')->will($this->returnSelf()); + $this->quote->expects($this->once())->method('collectTotals')->willReturnSelf(); $this->quoteRepository->expects($this->once()) ->method('save') ->with($this->quote) @@ -431,16 +408,18 @@ public function testSetMethodWithCouldNotSaveException() */ public function testSetMethodWithoutAddress() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + ->method('getShippingAddress') + ->willReturn($this->shippingAddress); $this->shippingAddress->expects($this->once())->method('getCountryId'); $this->model->set($cartId, $carrierCode, $methodCode); @@ -448,13 +427,14 @@ public function testSetMethodWithoutAddress() public function testSetMethod() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) @@ -463,8 +443,6 @@ public function testSetMethod() ->method('getCountryId')->will($this->returnValue($countryId)); $this->shippingAddress->expects($this->once()) ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddress->expects($this->once()) - ->method('getShippingRateByCode')->will($this->returnValue(true)); $this->quote->expects($this->once())->method('collectTotals')->will($this->returnSelf()); $this->quoteRepository->expects($this->once())->method('save')->with($this->quote); diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php index 070de886077ff..0b8e468b014d6 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php @@ -51,7 +51,6 @@ public function testGetChildren() */ public function testRemoveChild() { - $this->markTestSkipped('must be unskipped after fixing bug about wrong saving bundle option price'); $productSku = 'bundle-product'; $childSku = 'simple'; $optionIds = $this->getProductOptions(3); diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php index 47e6db6a27e0b..63b5b76a8d15d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php @@ -144,16 +144,12 @@ public function testUpdateBundleModifyExistingSelection() */ public function testUpdateBundleModifyExistingOptionOnly() { - $this->markTestSkipped('Skipped, due to MAGETWO-46857'); $bundleProduct = $this->createFixedPriceBundleProduct(); $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); - $existingSelectionId = $bundleProductOptions[0]['product_links'][0]['id']; - //Change the type of existing option $bundleProductOptions[0]['type'] = 'select'; - //unset product_links attribute - unset($bundleProductOptions[0]['product_links']); + $this->setBundleProductOptions($bundleProduct, $bundleProductOptions); $updatedProduct = $this->saveProduct($bundleProduct); @@ -162,7 +158,6 @@ public function testUpdateBundleModifyExistingOptionOnly() $this->assertEquals('select', $bundleOptions[0]['type']); $this->assertEquals('simple', $bundleOptions[0]['product_links'][0]['sku']); $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['qty']); - $this->assertEquals($existingSelectionId, $bundleOptions[0]['product_links'][0]['id']); $this->assertEquals(20, $bundleOptions[0]['product_links'][0]['price']); $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['price_type']); } diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php index 9828d85fb5de0..3e03ea49771c9 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php @@ -27,8 +27,6 @@ class CategoryLinkRepositoryTest extends WebapiAbstract */ public function testSave($productLink, $productId, $productPosition = 0) { - $this->checkIfTestable(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH_SUFFIX @@ -71,8 +69,6 @@ public function saveDataProvider() */ public function testUpdateProduct($productLink, $productId, $productPosition = 0) { - $this->checkIfTestable(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH_SUFFIX @@ -111,8 +107,6 @@ public function updateProductProvider() */ public function testDelete() { - $this->checkIfTestable(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH_SUFFIX . '/' . $this->categoryId . @@ -153,20 +147,4 @@ private function isProductInCategory($categoryId, $productId, $productPosition) return false; } } - - /** - * MAGETWO-41737: Skip tests when the flag 'custom_categories_sort' is up - * @return void - */ - private function checkIfTestable() - { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - /** @var \Magento\Framework\App\Config\ScopeConfigInterface $config */ - $config = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class); - - if ($config->getValue('catalog/custom_categories_sort') == 1) { - $this->markTestSkipped('Will be fixed after MAGETWO-41737'); - } - } } diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php index c7227d4ecca16..3bf5d592fef3c 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php @@ -54,7 +54,6 @@ protected function getQuoteMaskedId($quoteId) */ public function testGetTotals() { - $this->markTestSkipped('Will be fixed after MAGETWO-35573'); /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); $quote->load('test_order_1', 'reserved_order_id'); @@ -86,6 +85,7 @@ public function testGetTotals() Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), + Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], ]; @@ -93,7 +93,17 @@ public function testGetTotals() $data = $this->formatTotalsData($data); - $this->assertEquals($data, $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData)); + $actual = $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData); + + unset($actual['items'][0]['options']); + unset($actual['weee_tax_applied_amount']); + + unset($actual['total_segments']); + if (array_key_exists('extension_attributes', $actual)) { + unset($actual['extension_attributes']); + } + + $this->assertEquals($data, $actual); } /** @@ -162,6 +172,7 @@ protected function getQuoteItemTotalsData(\Magento\Quote\Model\Quote $quote) $item = array_shift($items); return [ + ItemTotals::KEY_ITEM_ID => $item->getItemId(), ItemTotals::KEY_PRICE => $item->getPrice(), ItemTotals::KEY_BASE_PRICE => $item->getBasePrice(), ItemTotals::KEY_QTY => $item->getQty(), @@ -178,6 +189,9 @@ protected function getQuoteItemTotalsData(\Magento\Quote\Model\Quote $quote) ItemTotals::KEY_BASE_PRICE_INCL_TAX => $item->getBasePriceInclTax(), ItemTotals::KEY_ROW_TOTAL_INCL_TAX => $item->getRowTotalInclTax(), ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => $item->getBaseRowTotalInclTax(), + ItemTotals::KEY_WEEE_TAX_APPLIED_AMOUNT => $item->getWeeeTaxAppliedAmount(), + ItemTotals::KEY_WEEE_TAX_APPLIED => $item->getWeeeTaxApplied(), + ItemTotals::KEY_NAME => $item->getName(), ]; } } diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php index 8ab7c765409b5..941a27cdbb699 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php @@ -78,7 +78,6 @@ public function testGetList() */ public function testGetListForMyCart() { - $this->markTestSkipped('Will be fixed after MAGETWO-35573'); $this->_markTestAsRestOnly(); $this->quote->load('test_order_1', 'reserved_order_id'); @@ -89,9 +88,9 @@ public function testGetListForMyCart() ); $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */ + /** @var \Magento\Quote\Model\ShippingMethodManagementInterface $shippingMethodManagementService */ $shippingMethodManagementService = $this->objectManager->create( - \Magento\Quote\Api\ShippingMethodManagementInterface::class + \Magento\Quote\Model\ShippingMethodManagementInterface::class ); $shippingMethodManagementService->set($this->quote->getId(), 'flatrate', 'flatrate'); diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php index d9f7bf1425c96..8446c27d3d45f 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php @@ -20,10 +20,11 @@ class CreditmemoCancelTest extends WebapiAbstract /** * @magentoApiDataFixture Magento/Sales/_files/creditmemo_with_list.php + * @expectedException \Exception + * @expectedExceptionMessage You can not cancel Credit Memo */ public function testCreditmemoCancel() { - $this->markTestSkipped('You can not cancel Credit Memo'); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection $creditmemoCollection */ @@ -44,7 +45,6 @@ public function testCreditmemoCancel() ], ]; $requestData = ['id' => $creditmemo->getId()]; - $result = $this->_webApiCall($serviceInfo, $requestData); - $this->assertTrue($result); + $this->_webApiCall($serviceInfo, $requestData); } } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php deleted file mode 100644 index 22acb11976315..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php +++ /dev/null @@ -1,99 +0,0 @@ - magentoDataFixture -> magentoConfigFixture - * (https://wiki.magento.com/display/PAAS/Integration+Tests+Development+Guide - * #IntegrationTestsDevelopmentGuide-ApplyingAnnotations) - * config fixtures can't be applied before data fixture. - */ -namespace Magento\Catalog\Model\Category; - -use Magento\Catalog\Model\Category\CategoryImageTest\StubZendLogWriterStream; - -class CategoryImageTest extends \PHPUnit_Framework_TestCase -{ - /** @var int */ - protected $_oldLogActive; - - /** @var string */ - protected $_oldExceptionFile; - - /** @var string */ - protected $_oldWriterModel; - - protected function setUp() - { - $this->_oldLogActive = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Store\Model\StoreManagerInterface::class - )->getStore()->getConfig( - 'dev/log/active' - ); - $this->_oldExceptionFile = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Store\Model\StoreManagerInterface::class - )->getStore()->getConfig( - 'dev/log/exception_file' - ); - } - - protected function tearDown() - { - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class - )->setValue( - 'dev/log/active', - $this->_oldLogActive, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - $this->_oldLogActive = null; - - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class - )->setValue( - 'dev/log/exception_file', - $this->_oldExceptionFile, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - $this->_oldExceptionFile = null; - - $this->_oldWriterModel = null; - - /** - * @TODO: refactor this test - * Changing store configuration in such a way totally breaks the idea of application isolation. - * Class declaration in data fixture file is dumb too. - * Added a quick fix to be able run separate tests with "phpunit --filter testMethod" - */ - if (class_exists(\Magento\Catalog\Model\Category\CategoryImageTest\StubZendLogWriterStreamTest::class, false)) { - StubZendLogWriterStream::$exceptions = []; - } - } - - /** - * Test that there is no exception '$_FILES array is empty' in \Magento\Framework\File\Uploader::_setUploadFileId() - * if category image was not set - * - */ - public function testSaveCategoryWithoutImage() - { - $this->markTestSkipped('MAGETWO-15096'); - - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - /** @var $category \Magento\Catalog\Model\Category */ - $category = $objectManager->get(\Magento\Framework\Registry::class) - ->registry('_fixture/Magento\Catalog\Model\Category'); - $this->assertNotEmpty($category->getId()); - - foreach (StubZendLogWriterStream::$exceptions as $exception) { - $this->assertNotContains('$_FILES array is empty', $exception['message']); - } - } -} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php deleted file mode 100644 index 3915ad47b3b1c..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php +++ /dev/null @@ -1,34 +0,0 @@ -get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class -)->setValue( - 'dev/log/active', - 1, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE -); - -\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class -)->setValue( - 'dev/log/exception_file', - 'save_category_without_image.log', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE -); -class StubZendLogWriterStream extends \Zend_Log_Writer_Stream -{ - /** @var array */ - public static $exceptions = []; - - public function write($event) - { - self::$exceptions[] = $event; - - parent::write($event); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php index 83e0f352a68ea..a3e90819912f0 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php @@ -275,6 +275,27 @@ public function testSaveCategoryWithPosition() $this->assertEquals('5', $category->getPosition()); } + /** + * @magentoDbIsolation enabled + */ + public function testSaveCategoryWithoutImage() + { + $model = $this->objectManager->create(\Magento\Catalog\Model\Category::class); + $repository = $this->objectManager->get(\Magento\Catalog\Api\CategoryRepositoryInterface::class); + + $model->setName('Test Category 100') + ->setParentId(2) + ->setLevel(2) + ->setAvailableSortBy(['position', 'name']) + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1) + ->isObjectNew(true); + + $repository->save($model); + $this->assertNull($model->getImage()); + } + /** * @magentoAppArea adminhtml */ diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php index db5511bf9d8ff..f72cf66fc76c1 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php @@ -1197,7 +1197,6 @@ public function testProductWithLinks() */ public function testExistingProductWithUrlKeys() { - $this->markTestSkipped('Test must be unskiped after implementation MAGETWO-48871'); $products = [ 'simple1' => 'url-key1', 'simple2' => 'url-key2', diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php index 21486448f6191..7a9e73fe78f16 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php @@ -11,7 +11,11 @@ require 'quote_with_address.php'; -$quote->collectTotals()->save(); + +$quoteRepository = \Magento\Framework\App\ObjectManager::getInstance()->get( + \Magento\Quote\Api\CartRepositoryInterface::class +); +$quoteRepository->save($quote); /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php index 90fac3c4caca7..37a087eaa02b2 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php @@ -12,7 +12,6 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase */ public function testGetListWithExtensionAttributes() { - $this->markTestSkipped('Test skipped due to MAGETWO-45654'); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $productSku = 'configurable'; /** @var \Magento\ConfigurableProduct\Api\OptionRepositoryInterface $optionRepository */ diff --git a/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php b/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php index 3a9bee9f8aad2..ff908c78b9fed 100644 --- a/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php +++ b/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php @@ -43,11 +43,11 @@ public function importReplaceDataProvider() * @dataProvider exportImportDataProvider * @SuppressWarnings(PHPMD.UnusedFormalParameter) * - * @todo remove after MAGETWO-49467 resolved + * @todo remove after MAGETWO-38240 resolved */ public function testExport($fixtures, $skus, $skippedAttributes = [], $rollbackFixtures = []) { - $this->markTestSkipped('Uncomment after MAGETWO-49467 resolved'); + $this->markTestSkipped('Uncomment after MAGETWO-38240 resolved'); } /** @@ -56,11 +56,11 @@ public function testExport($fixtures, $skus, $skippedAttributes = [], $rollbackF * @dataProvider exportImportDataProvider * @SuppressWarnings(PHPMD.UnusedFormalParameter) * - * @todo remove after MAGETWO-49467 resolved + * @todo remove after MAGETWO-38240 resolved */ public function testImportDelete($fixtures, $skus, $skippedAttributes = [], $rollbackFixtures = []) { - $this->markTestSkipped('Uncomment after MAGETWO-49467 resolved'); + $this->markTestSkipped('Uncomment after MAGETWO-38240 resolved'); } /** @@ -72,12 +72,13 @@ public function testImportDelete($fixtures, $skus, $skippedAttributes = [], $rol * @param string[] $skus * @param string[] $skippedAttributes * @dataProvider importReplaceDataProvider + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * - * @todo remove after MAGETWO-49467 resolved + * @todo remove after MAGETWO-38240 resolved */ public function testImportReplace($fixtures, $skus, $skippedAttributes = [], $rollbackFixtures = []) { - $this->markTestSkipped('Uncomment after MAGETWO-49467 resolved'); + $this->markTestSkipped('Uncomment after MAGETWO-38240 resolved'); } /** diff --git a/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php b/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php index 8a6e4747a0d7a..9afc2ca119bba 100644 --- a/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php +++ b/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php @@ -20,7 +20,7 @@ class MemoryUsageTest extends \PHPUnit_Framework_TestCase protected function setUp() { if (defined('HHVM_VERSION')) { - $this->markTestSkipped("For HHVM it's not relevant while MAGETWO-33679 is not resolved"); + $this->markTestSkipped("Test not relevant because no gc in HHVM."); } $this->_helper = new \Magento\TestFramework\Helper\Memory( new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer()) @@ -32,7 +32,7 @@ protected function setUp() */ public function testAppReinitializationNoMemoryLeak() { - $this->markTestSkipped('Test fails at Travis. Skipped in scope of MAGETWO-48538'); + $this->markTestSkipped('Test fails at Travis. Skipped until MAGETWO-47111'); $this->_deallocateUnusedMemory(); $actualMemoryUsage = $this->_helper->getRealMemoryUsage(); diff --git a/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php b/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php index afa5981e70f7e..811f62186eeae 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php +++ b/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php @@ -36,7 +36,7 @@ public function testSchemaUsingValidXml() public function testSchemaUsingInvalidXml($expectedErrors = null) { if (!function_exists('libxml_set_external_entity_loader')) { - $this->markTestSkipped('Skipped due to MAGETWO-44919'); + $this->markTestSkipped('Skipped due to MAGETWO-45033'); } $xmlFile = $this->_getKnownInvalidXml(); $schema = $this->_getXsd(); @@ -46,7 +46,7 @@ public function testSchemaUsingInvalidXml($expectedErrors = null) public function testFileSchemaUsingPartialXml() { if (!function_exists('libxml_set_external_entity_loader')) { - $this->markTestSkipped('Skipped due to MAGETWO-44919'); + $this->markTestSkipped('Skipped due to MAGETWO-45033'); } $xmlFile = $this->_getKnownValidPartialXml(); if ($xmlFile === null) { diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt index 852bb6707cd84..56e0d51516c26 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt @@ -1,5 +1,3 @@ -app/code/Magento -lib/internal/Magento Magento/Adminhtml Magento/Authorizenet/Model Magento/Backend @@ -160,3 +158,42 @@ Magento/Sales/Setup Magento/SalesRule/Setup Magento/Eav/Setup setup/src/Magento/Setup/Fixtures +Magento/ConfigurableProduct/Setup +Magento/Weee/Setup +Magento/Wishlist/Setup +Magento/CatalogUrlRewrite/Setup +Magento/AdvancedSalesRule/Setup +Magento/VisualMerchandiser/Setup +Magento/Catalog/Model +Magento/Catalog/Ui/Component/Listing +Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Tab/Variations/Config +Magento/Payment/Gateway/Data/Order +Magento/ProductAlert/Controller/Unsubscribe +Magento/Reports/Model/ResourceModel/Customer/Orders +Magento/Sales/Model/ResourceModel/Report +Magento/SalesRule/Model +Magento/Search/Ui/Component/Listing/Column/Scope +Magento/Tax/Model/Calculation +Magento/Tax/Observer +Magento/Vault/Model/Ui +Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price +Magento/AdvancedSalesRule/Model/Rule/Condition/Product +Magento/CmsStaging/Controller/Adminhtml/Block/Update +Magento/Customer/Block/Widget +Magento/Persistent/Observer +Magento/Elasticsearch/Model/Adapter/Container +Magento/Elasticsearch/SearchAdapter +Magento/Staging/Model/Entity/DataProvider +Magento/CatalogStaging/Model/Update/Grid +Magento/Eav/Model/Api/SearchCriteria/CollectionProcessor +Magento/Framework/App/AreaList +Magento/Framework/App/Route/ConfigInterface +Magento/Framework/DataObject/Copy/Config/Data +Magento/Framework/Backup/Filesystem/Iterator +Magento/Theme/Model/Indexer/Design +Magento/Framework/EntityManager/Db +Magento/Framework/Mview/Config/Data +Magento/Framework/View/File/Collector/Override +Magento/Framework/MessageQueue/Consumer/Config/ConsumerConfigItem +Magento/Framework/MessageQueue/Publisher/Config/PublisherConfigItem +Magento/Framework/MessageQueue/Topology/Config/ExchangeConfigItem \ No newline at end of file From 2f864132d9242dc8a7200fe8ae2414e03fa7c1e4 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Mon, 26 Sep 2016 16:39:13 +0300 Subject: [PATCH 26/29] MAGETWO-57986: [FT] Can not get discount price in shopping cart --- .../tests/app/Magento/Checkout/Test/Block/Cart/Totals.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php index ef7ac1fc55f32..2cf6d5ad87dff 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php @@ -205,6 +205,8 @@ protected function escapeCurrency($price) */ public function getDiscount() { + $this->waitForElementNotVisible($this->blockWaitElement); + $this->waitForElementVisible($this->discount, Locator::SELECTOR_CSS); $priceElement = $this->_rootElement->find($this->discount, Locator::SELECTOR_CSS); return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } From d0afa1f6ac4e21b26ee9cceb961822b223c3a9a6 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Mon, 26 Sep 2016 16:48:43 +0300 Subject: [PATCH 27/29] MAGETWO-56587: [FT] Fix AssertProductDataInMiniShoppingCart constraint --- .../Test/TestCase/AddProductsToShoppingCartEntityTest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml index f64258b1de297..30688723ae8ed 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml @@ -99,8 +99,8 @@ configurableProduct::default bundleProduct::bundle_fixed_product bundleProduct::bundle_dynamic_product - 2922.43 - 2852.43 + 3473.43 + 3408.43 From a71fb415187bc852a14962f6ce0d9ae7c4992bbd Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 27 Sep 2016 10:51:27 +0300 Subject: [PATCH 28/29] MAGETWO-54109: Unskip Tests which Refer to Already Closed Tickets --- .../Test/Unit/Model/ShippingInformationManagementTest.php | 2 +- .../Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php index 1b68ad4ce85cf..04d347ec237a9 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php @@ -459,7 +459,7 @@ public function testSaveAddressInformation() } /** - * @param $map + * @param array $map */ private function prepareObjectManager($map) { diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php index c8e186aaff3c2..dae3d56aa04b0 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php @@ -248,7 +248,7 @@ public function testDeleteById() } /** - * @param $map + * @param array $map */ private function prepareObjectManager($map) { From 26d7e9eb931533fb15d7c358057baa399dc13b67 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Wed, 28 Sep 2016 10:22:48 +0300 Subject: [PATCH 29/29] MAGETWO-54109: Unskip Tests which Refer to Already Closed Tickets --- .../Model/BillingAddressManagementTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php index 114ee560059ee..81eaeed19fe15 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php @@ -40,6 +40,11 @@ class BillingAddressManagementTest extends \PHPUnit_Framework_TestCase */ protected $addressRepository; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingAssignmentMock; + /** * @return void */ @@ -59,6 +64,19 @@ protected function setUp() 'addressRepository' => $this->addressRepository ] ); + + $this->shippingAssignmentMock = $this->getMock( + \Magento\Quote\Model\ShippingAddressAssignment::class, + ['setAddress'], + [], + '', + false + ); + $this->objectManager->setBackwardCompatibleProperty( + $this->model, + 'shippingAddressAssignment', + $this->shippingAssignmentMock + ); } /** @@ -111,6 +129,10 @@ public function testSetAddress() $quoteMock->expects($this->once())->method('setBillingAddress')->with($address)->willReturnSelf(); $quoteMock->expects($this->once())->method('setDataChanges')->with(1)->willReturnSelf(); + $this->shippingAssignmentMock->expects($this->once()) + ->method('setAddress') + ->with($quoteMock, $address, $useForShipping); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $this->assertEquals($addressId, $this->model->assign($cartId, $address, $useForShipping)); } @@ -151,6 +173,10 @@ public function testSetAddressWithInabilityToSaveQuote() $quoteMock->expects($this->once())->method('setBillingAddress')->with($address)->willReturnSelf(); $quoteMock->expects($this->once())->method('setDataChanges')->with(1)->willReturnSelf(); + $this->shippingAssignmentMock->expects($this->once()) + ->method('setAddress') + ->with($quoteMock, $address, false); + $this->quoteRepositoryMock->expects($this->once()) ->method('save') ->with($quoteMock)