From e788a2421f5cfe2df9d5028b08141d92f70819b8 Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Wed, 28 Sep 2016 11:15:04 +0300 Subject: [PATCH 01/11] MAGETWO-58730: [Github] Incorrect province code sent on Checkout to UPS #6564 --- .../view/frontend/web/js/model/address-converter.js | 7 +++++++ .../view/frontend/web/js/model/new-customer-address.js | 2 +- .../view/frontend/web/js/model/shipping-rates-validator.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js b/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js index 2d6fa460ef66d..3ec34cd96574b 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js @@ -44,6 +44,13 @@ define( addressData.region.region_code = region['code']; addressData.region.region = region['name']; } + } else if ( + !addressData.region_id + && countryData()[addressData.country_id] + && countryData()[addressData.country_id]['regions'] + ) { + addressData.region.region_code = ''; + addressData.region.region = ''; } delete addressData.region_id; diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js b/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js index bee4480b0dfb1..fe05dcebfc99a 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js @@ -22,7 +22,7 @@ define([], function () { return { email: addressData.email, countryId: addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId, - regionId: regionId, + regionId: regionId || addressData.regionId, regionCode: (addressData.region) ? addressData.region.region_code : null, region: (addressData.region) ? addressData.region.region : null, customerId: addressData.customer_id, diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js index 420d50b83478a..c49960ecfb91d 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js @@ -176,7 +176,7 @@ define( address; if (this.validateAddressData(addressFlat)) { - addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat); + addressFlat = uiRegistry.get('checkoutProvider').shippingAddress; address = addressConverter.formAddressDataToQuoteAddress(addressFlat); selectShippingAddress(address); } From fe97d9e4540741edb0abc876d169c1df60a06b70 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Thu, 6 Oct 2016 12:56:04 +0300 Subject: [PATCH 02/11] MAGETWO-54412: [MERCHANT] Integrity Constraint Violation when creating orders #4580 --- app/code/Magento/Quote/Model/Quote.php | 6 ++ .../Quote/Model/ResourceModel/Quote.php | 22 +++++ .../Quote/Test/Unit/Model/QuoteTest.php | 31 ++++++- .../Unit/Model/ResourceModel/QuoteTest.php | 85 +++++++++++++++++++ .../etc/install-config-mysql.php.dist | 2 +- .../Magento/Quote/Model/QuoteTest.php | 19 +++++ .../Quote/Model/ResourceModel/QuoteTest.php | 45 ++++++++++ .../Test/Legacy/_files/obsolete_methods.php | 1 - 8 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Quote/Model/ResourceModel/QuoteTest.php diff --git a/app/code/Magento/Quote/Model/Quote.php b/app/code/Magento/Quote/Model/Quote.php index 3cdcf70cf2426..f84ca33b436f9 100644 --- a/app/code/Magento/Quote/Model/Quote.php +++ b/app/code/Magento/Quote/Model/Quote.php @@ -2157,6 +2157,12 @@ public function reserveOrderId() { if (!$this->getReservedOrderId()) { $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this)); + } else { + //checking if reserved order id was already used for some order + //if yes reserving new one if not using old one + if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) { + $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this)); + } } return $this; } diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote.php b/app/code/Magento/Quote/Model/ResourceModel/Quote.php index 241f0d6b272fc..72172c128c58c 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote.php @@ -172,6 +172,28 @@ public function getReservedOrderId($quote) ->getNextValue(); } + /** + * Check is order increment id use in sales/order table + * + * @param int $orderIncrementId + * @return bool + */ + public function isOrderIncrementIdUsed($orderIncrementId) + { + /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */ + $adapter = $this->getConnection(); + $bind = [':increment_id' => $orderIncrementId]; + /** @var \Magento\Framework\DB\Select $select */ + $select = $adapter->select(); + $select->from($this->getTable('sales_order'), 'entity_id')->where('increment_id = :increment_id'); + $entity_id = $adapter->fetchOne($select, $bind); + if ($entity_id > 0) { + return true; + } + + return false; + } + /** * Mark quotes - that depend on catalog price rules - to be recollected on demand * diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php index 5165f299d45a9..b54ce84fe1ac4 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php @@ -314,7 +314,10 @@ protected function setUp() 'customerRepository' => $this->customerRepositoryMock, 'objectCopyService' => $this->objectCopyServiceMock, 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock, - 'customerDataFactory' => $this->customerDataFactoryMock + 'customerDataFactory' => $this->customerDataFactoryMock, + 'data' => [ + 'reserved_order_id' => 1000001 + ] ] ); } @@ -1237,4 +1240,30 @@ public function testGetAllItems() $this->assertEquals($itemResult, $this->quote->getAllItems()); } + + /** + * Test to verify if existing reserved_order_id in use + * + * @param bool $isReservedOrderIdExist + * @param int $reservedOrderId + * @dataProvider reservedOrderIdDataProvider + */ + public function testReserveOrderId($isReservedOrderIdExist, $reservedOrderId) + { + $this->resourceMock + ->expects($this->once()) + ->method('isOrderIncrementIdUsed') + ->with(1000001)->willReturn($isReservedOrderIdExist); + $this->resourceMock->expects($this->any())->method('getReservedOrderId')->willReturn($reservedOrderId); + $this->quote->reserveOrderId(); + $this->assertEquals($reservedOrderId, $this->quote->getReservedOrderId()); + } + + public function reservedOrderIdDataProvider() + { + return [ + 'id_already_in_use' => [true, 100002], + 'id_not_in_use' => [false, 1000001] + ]; + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php new file mode 100644 index 0000000000000..102e3471063f1 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php @@ -0,0 +1,85 @@ +selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) + ->disableOriginalConstructor() + ->getMock(); + $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf()); + $this->selectMock->expects($this->any())->method('where'); + + $this->adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class) + ->disableOriginalConstructor() + ->getMock(); + $this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock)); + + $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resourceMock->expects( + $this->any() + )->method( + 'getConnection' + )->will( + $this->returnValue($this->adapterMock) + ); + + $this->model = $objectManagerHelper->getObject( + \Magento\Quote\Model\ResourceModel\Quote::class, + [ + 'resource' => $this->resourceMock + ] + ); + } + + /** + * Unit test to verify if isOrderIncrementIdUsed method works with different types increment ids + * + * @param array $value + * @dataProvider isOrderIncrementIdUsedDataProvider + */ + public function testIsOrderIncrementIdUsed($value) + { + $expectedBind = [':increment_id' => $value]; + $this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind); + $this->model->isOrderIncrementIdUsed($value); + } + + /** + * @return array + */ + public function isOrderIncrementIdUsedDataProvider() + { + return [[100000001], ['10000000001'], ['M10000000001']]; + } +} diff --git a/dev/tests/integration/etc/install-config-mysql.php.dist b/dev/tests/integration/etc/install-config-mysql.php.dist index 6fffcb22b5000..967914e238251 100644 --- a/dev/tests/integration/etc/install-config-mysql.php.dist +++ b/dev/tests/integration/etc/install-config-mysql.php.dist @@ -7,7 +7,7 @@ return [ 'db-host' => 'localhost', 'db-user' => 'root', - 'db-password' => '123123q', + 'db-password' => '', 'db-name' => 'magento_integration_tests', 'db-prefix' => '', 'backend-frontname' => 'backend', diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php index da035c8eec78f..8f295077afe33 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php @@ -404,4 +404,23 @@ protected function _getCustomerDataArray() \Magento\Customer\Model\Data\Customer::WEBSITE_ID => 1 ]; } + + /** + * Test to verify that reserved_order_id will be changed if it already in used + * + * @magentoDataFixture Magento/Sales/_files/order.php + * @magentoDataFixture Magento/Quote/_files/empty_quote.php + */ + public function testReserveOrderId() + { + $objectManager = Bootstrap::getObjectManager(); + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $objectManager->create(\Magento\Quote\Model\Quote::class); + $quote->load('reserved_order_id', 'reserved_order_id'); + $quote->reserveOrderId(); + $this->assertEquals('reserved_order_id', $quote->getReservedOrderId()); + $quote->setReservedOrderId('100000001'); + $quote->reserveOrderId(); + $this->assertNotEquals('100000001', $quote->getReservedOrderId()); + } } diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/ResourceModel/QuoteTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/ResourceModel/QuoteTest.php new file mode 100644 index 0000000000000..43ee0893b75f9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/ResourceModel/QuoteTest.php @@ -0,0 +1,45 @@ +_resourceModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Quote\Model\ResourceModel\Quote::class + ); + } + + /** + * Test to verify if isOrderIncrementIdUsed method works with numeric increment ids + * + * @magentoDataFixture Magento/Sales/_files/order.php + */ + public function testIsOrderIncrementIdUsedNumericIncrementId() + { + $this->assertTrue($this->_resourceModel->isOrderIncrementIdUsed('100000001')); + } + + /** + * Test to verify if isOrderIncrementIdUsed method works with alphanumeric increment ids + * + * @magentoDataFixture Magento/Sales/_files/order_alphanumeric_id.php + */ + public function testIsOrderIncrementIdUsedAlphanumericIncrementId() + { + $this->assertTrue($this->_resourceModel->isOrderIncrementIdUsed('M00000001')); + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index bc49ab15a7d54..2ce1bf02bf389 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -2155,7 +2155,6 @@ ['addOrderedQty', 'Magento\Reports\Model\ResourceModel\Product\Collection'], ['prepareForProductsInCarts', 'Magento\Reports\Model\ResourceModel\Quote\Collection'], ['getOrdersSubSelect', 'Magento\Reports\Model\ResourceModel\Quote\Collection'], - ['isOrderIncrementIdUsed', 'Magento\Quote\Model\ResourceModel\Quote'], ['isStateProtected', 'Magento\Sales\Model\Order'], ['_getBundleOptions', 'Magento\Bundle\Block\Checkout\Cart\Item\Renderer'], ['_getSelectionFinalPrice', 'Magento\Bundle\Block\Checkout\Cart\Item\Renderer'], From a42acc28b6b2f70d6a6f08d5d35a2a9a75971c88 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Thu, 6 Oct 2016 15:41:21 +0300 Subject: [PATCH 03/11] MAGETWO-54412: [MERCHANT] Integrity Constraint Violation when creating orders #4580 --- dev/tests/integration/etc/install-config-mysql.php.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/etc/install-config-mysql.php.dist b/dev/tests/integration/etc/install-config-mysql.php.dist index 967914e238251..6fffcb22b5000 100644 --- a/dev/tests/integration/etc/install-config-mysql.php.dist +++ b/dev/tests/integration/etc/install-config-mysql.php.dist @@ -7,7 +7,7 @@ return [ 'db-host' => 'localhost', 'db-user' => 'root', - 'db-password' => '', + 'db-password' => '123123q', 'db-name' => 'magento_integration_tests', 'db-prefix' => '', 'backend-frontname' => 'backend', From 716df9290d73aa39301c1e47da8dc0b7aa9dc7ac Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Fri, 7 Oct 2016 15:38:21 +0300 Subject: [PATCH 04/11] MAGETWO-56836: [FT] Update wishlist button doesn't receive the click in AddProductsToCartFromCustomerWishlistOnFrontendTest --- .../Wishlist/Controller/Index/Cart.php | 5 + .../Test/Unit/Controller/Index/CartTest.php | 174 +++++++++++++++++- .../wishlist_index_configure_type_bundle.xml | 2 +- .../app/Magento/Checkout/Test/Block/Cart.php | 9 +- .../Wishlist/Test/Block/Customer/Wishlist.php | 1 + 5 files changed, 188 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Index/Cart.php b/app/code/Magento/Wishlist/Controller/Index/Cart.php index f15e89d16c9b4..a907abcd1c56c 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Index/Cart.php @@ -113,6 +113,7 @@ public function __construct( * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function execute() { @@ -137,6 +138,10 @@ public function execute() // Set qty $qty = $this->getRequest()->getParam('qty'); + $postQty = $this->getRequest()->getPostValue('qty'); + if ($postQty !== null && $qty !== $postQty) { + $qty = $postQty; + } if (is_array($qty)) { if (isset($qty[$itemId])) { $qty = $qty[$itemId]; diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php index e1a7cd448569f..743fc39e4b43d 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php @@ -159,7 +159,7 @@ protected function setUp() $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class) ->disableOriginalConstructor() - ->setMethods(['getParams', 'getParam', 'isAjax']) + ->setMethods(['getParams', 'getParam', 'isAjax', 'getPostValue']) ->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder(\Magento\Framework\App\Response\RedirectInterface::class) @@ -916,4 +916,176 @@ public function testExecuteWithoutQuantityArrayAndConfigurable() $this->assertSame($this->resultRedirectMock, $this->model->execute()); } + + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testExecuteWithEditQuantity() + { + $itemId = 2; + $wishlistId = 1; + $qty = 1; + $postQty = 2; + $productId = 4; + $indexUrl = 'index_url'; + $configureUrl = 'configure_url'; + $options = [5 => 'option']; + $params = ['item' => $itemId, 'qty' => $qty]; + + $this->formKeyValidator->expects($this->once()) + ->method('validate') + ->with($this->requestMock) + ->willReturn(true); + + $itemMock = $this->getMockBuilder(\Magento\Wishlist\Model\Item::class) + ->disableOriginalConstructor() + ->setMethods( + [ + 'load', + 'getId', + 'getWishlistId', + 'setQty', + 'setOptions', + 'getBuyRequest', + 'mergeBuyRequest', + 'addToCart', + 'getProduct', + 'getProductId', + ] + ) + ->getMock(); + + $this->requestMock->expects($this->at(0)) + ->method('getParam') + ->with('item', null) + ->willReturn($itemId); + $this->itemFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($itemMock); + + $itemMock->expects($this->once()) + ->method('load') + ->with($itemId, null) + ->willReturnSelf(); + $itemMock->expects($this->exactly(2)) + ->method('getId') + ->willReturn($itemId); + $itemMock->expects($this->once()) + ->method('getWishlistId') + ->willReturn($wishlistId); + + $wishlistMock = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->wishlistProviderMock->expects($this->once()) + ->method('getWishlist') + ->with($wishlistId) + ->willReturn($wishlistMock); + + $this->requestMock->expects($this->at(1)) + ->method('getParam') + ->with('qty', null) + ->willReturn($qty); + + $this->requestMock->expects($this->once()) + ->method('getPostValue') + ->with('qty') + ->willReturn($postQty); + + $this->quantityProcessorMock->expects($this->once()) + ->method('process') + ->with($postQty) + ->willReturnArgument(0); + + $itemMock->expects($this->once()) + ->method('setQty') + ->with($postQty) + ->willReturnSelf(); + + $this->urlMock->expects($this->at(0)) + ->method('getUrl') + ->with('*/*', null) + ->willReturn($indexUrl); + + $itemMock->expects($this->once()) + ->method('getProductId') + ->willReturn($productId); + + $this->urlMock->expects($this->at(1)) + ->method('getUrl') + ->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId]) + ->willReturn($configureUrl); + + $optionMock = $this->getMockBuilder(\Magento\Wishlist\Model\Item\Option::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->optionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($optionMock); + + $optionsMock = $this->getMockBuilder(\Magento\Wishlist\Model\ResourceModel\Item\Option\Collection::class) + ->disableOriginalConstructor() + ->getMock(); + $optionMock->expects($this->once()) + ->method('getCollection') + ->willReturn($optionsMock); + + $optionsMock->expects($this->once()) + ->method('addItemFilter') + ->with([$itemId]) + ->willReturnSelf(); + $optionsMock->expects($this->once()) + ->method('getOptionsByItem') + ->with($itemId) + ->willReturn($options); + + $itemMock->expects($this->once()) + ->method('setOptions') + ->with($options) + ->willReturnSelf(); + + $this->requestMock->expects($this->once()) + ->method('getParams') + ->willReturn($params); + + $buyRequestMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->disableOriginalConstructor() + ->getMock(); + + $itemMock->expects($this->once()) + ->method('getBuyRequest') + ->willReturn($buyRequestMock); + + $this->productHelperMock->expects($this->once()) + ->method('addParamsToBuyRequest') + ->with($params, ['current_config' => $buyRequestMock]) + ->willReturn($buyRequestMock); + + $itemMock->expects($this->once()) + ->method('mergeBuyRequest') + ->with($buyRequestMock) + ->willReturnSelf(); + $itemMock->expects($this->once()) + ->method('addToCart') + ->with($this->checkoutCartMock, true) + ->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message'))); + + $this->messageManagerMock->expects($this->once()) + ->method('addNotice') + ->with('message', null) + ->willReturnSelf(); + + $this->helperMock->expects($this->once()) + ->method('calculate') + ->willReturnSelf(); + + $this->resultRedirectMock->expects($this->once()) + ->method('setUrl') + ->with($configureUrl) + ->willReturnSelf(); + + $this->assertSame($this->resultRedirectMock, $this->model->execute()); + } } diff --git a/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_configure_type_bundle.xml b/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_configure_type_bundle.xml index dbb680f8f2580..b08816a6728eb 100644 --- a/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_configure_type_bundle.xml +++ b/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_configure_type_bundle.xml @@ -22,7 +22,7 @@ template="Magento_Catalog::product/view/addto.phtml" cacheable="false"> - diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php index 697733fd3c33d..fac0f811be261 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php @@ -99,6 +99,13 @@ class Cart extends Block */ protected $preloaderSpinner = '#preloaderSpinner'; + /** + * Cart item class name. + * + * @var string + */ + protected $cartItemClass = \Magento\Checkout\Test\Block\Cart\CartItem::class; + /** * Wait for PayPal page is loaded. * @@ -129,7 +136,7 @@ public function getCartItem(FixtureInterface $product) Locator::SELECTOR_XPATH ); $cartItem = $this->blockFactory->create( - '\\' . get_class($this) . '\CartItem', + $this->cartItemClass, ['element' => $cartItemBlock] ); } diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/Block/Customer/Wishlist.php b/dev/tests/functional/tests/app/Magento/Wishlist/Test/Block/Customer/Wishlist.php index 47f787da38b04..bda0780f55300 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/Block/Customer/Wishlist.php +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/Block/Customer/Wishlist.php @@ -99,6 +99,7 @@ public function clickAddToCart() public function clickUpdateWishlist() { $this->waitFormToLoad(); + $this->_rootElement->hover(); $this->_rootElement->find($this->updateButton)->click(); } From 4204843323c2358ae99a840dc503b0bf205abdad Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Mon, 10 Oct 2016 16:29:58 +0300 Subject: [PATCH 05/11] MAGETWO-58334: [Github] Free shipping is not applied if cart price rule match #6584 --- .../Quote/Model/Quote/Address/Total/Shipping.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php b/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php index f1660c9f9d642..7d8946661476c 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php +++ b/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php @@ -59,10 +59,8 @@ public function collect( $addressWeight = $address->getWeight(); $freeMethodWeight = $address->getFreeMethodWeight(); + $addressFreeShipping = $address->getFreeShipping(); - $address->setFreeShipping( - $this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems()) - ); $total->setTotalAmount($this->getCode(), 0); $total->setBaseTotalAmount($this->getCode(), 0); @@ -98,7 +96,7 @@ public function collect( $itemQty = $child->getTotalQty(); $rowWeight = $itemWeight * $itemQty; $addressWeight += $rowWeight; - if ($address->getFreeShipping() || $child->getFreeShipping() === true) { + if ($addressFreeShipping || $child->getFreeShipping() === true) { $rowWeight = 0; } elseif (is_numeric($child->getFreeShipping())) { $freeQty = $child->getFreeShipping(); @@ -116,7 +114,7 @@ public function collect( $itemWeight = $item->getWeight(); $rowWeight = $itemWeight * $item->getQty(); $addressWeight += $rowWeight; - if ($address->getFreeShipping() || $item->getFreeShipping() === true) { + if ($addressFreeShipping || $item->getFreeShipping() === true) { $rowWeight = 0; } elseif (is_numeric($item->getFreeShipping())) { $freeQty = $item->getFreeShipping(); @@ -136,7 +134,7 @@ public function collect( $itemWeight = $item->getWeight(); $rowWeight = $itemWeight * $item->getQty(); $addressWeight += $rowWeight; - if ($address->getFreeShipping() || $item->getFreeShipping() === true) { + if ($addressFreeShipping || $item->getFreeShipping() === true) { $rowWeight = 0; } elseif (is_numeric($item->getFreeShipping())) { $freeQty = $item->getFreeShipping(); @@ -157,6 +155,10 @@ public function collect( $address->setWeight($addressWeight); $address->setFreeMethodWeight($freeMethodWeight); + $address->setFreeShipping( + $this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems()) + ); + $address->collectShippingRates(); if ($method) { From 3524943ac6544ee969480536ef6f0cd1a29b0b56 Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Tue, 11 Oct 2016 09:17:15 +0300 Subject: [PATCH 06/11] MAGETWO-57675: [GITHUB] WYSIWYG editor does not show. #6222 #4828 #6815 --- lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js index 66b72857d0033..217c5331c6b90 100755 --- a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js +++ b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js @@ -53,6 +53,10 @@ define([ }); } + if (jQuery.isReady) { + tinyMCE.dom.Event.domLoaded = true; + } + tinyMCE.init(this.getSettings(mode)); }, From 66134b4fe08f40a5e621fa9e7353add132d400ee Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 11 Oct 2016 11:35:31 +0300 Subject: [PATCH 07/11] MAGETWO-58334: [Github] Free shipping is not applied if cart price rule match #6584 --- .../Quote/Address/Total/ShippingTest.php | 106 ++++++++++++++++++ .../rule_free_shipping_by_product_weight.php | 35 ++++++ 2 files changed, 141 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/SalesRule/Model/Quote/Address/Total/ShippingTest.php create mode 100644 dev/tests/integration/testsuite/Magento/SalesRule/_files/rule_free_shipping_by_product_weight.php diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Quote/Address/Total/ShippingTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Quote/Address/Total/ShippingTest.php new file mode 100644 index 0000000000000..543d02e420674 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Quote/Address/Total/ShippingTest.php @@ -0,0 +1,106 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->cartManagement = $this->objectManager->get(\Magento\Quote\Api\GuestCartManagementInterface::class); + $this->itemRepository = $this->objectManager->get(\Magento\Quote\Api\GuestCartItemRepositoryInterface::class); + } + + /** + * @magentoDataFixture Magento/SalesRule/_files/rule_free_shipping_by_product_weight.php + * @magentoDataFixture Magento/Catalog/_files/product_simple.php + */ + public function testRuleByProductWeightWithFreeShipping() + { + $cartId = $this->prepareQuote(1); + $methods = $this->estimateShipping($cartId); + + $this->assertTrue(count($methods) > 0); + $this->assertEquals('flatrate', $methods[0]->getMethodCode()); + $this->assertEquals(0, $methods[0]->getAmount()); + + } + + /** + * @magentoDataFixture Magento/SalesRule/_files/rule_free_shipping_by_product_weight.php + * @magentoDataFixture Magento/Catalog/_files/product_simple.php + */ + public function testRuleByProductWeightWithoutFreeShipping() + { + $cartId = $this->prepareQuote(5); + $methods = $this->estimateShipping($cartId); + + $this->assertTrue(count($methods) > 0); + $this->assertEquals('flatrate', $methods[0]->getMethodCode()); + $this->assertEquals(25, $methods[0]->getAmount()); + + } + + /** + * Estimate shipment for guest cart + * + * @param int $cartId + * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] + */ + private function estimateShipping($cartId) + { + $addressFactory = $this->objectManager->get(\Magento\Quote\Api\Data\AddressInterfaceFactory::class); + /** @var \Magento\Quote\Api\Data\AddressInterface $address */ + $address = $addressFactory->create(); + $address->setCountryId('US'); + $address->setRegionId(2); + + /** @var \Magento\Quote\Api\GuestShipmentEstimationInterface $estimation */ + $estimation = $this->objectManager->get(\Magento\Quote\Api\GuestShipmentEstimationInterface::class); + return $estimation->estimateByExtendedAddress($cartId, $address); + } + + /** + * Create guest quote with products + * + * @param int $itemQty + * @return int + */ + private function prepareQuote($itemQty) + { + $cartId = $this->cartManagement->createEmptyCart(); + + /** @var \Magento\Quote\Api\Data\CartItemInterfaceFactory $cartItemFactory */ + $cartItemFactory = $this->objectManager->get(\Magento\Quote\Api\Data\CartItemInterfaceFactory::class); + + /** @var \Magento\Quote\Api\Data\CartItemInterface $cartItem */ + $cartItem = $cartItemFactory->create(); + $cartItem->setQuoteId($cartId); + $cartItem->setQty($itemQty); + $cartItem->setSku('simple'); + $cartItem->setProductType(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); + + $this->itemRepository->save($cartItem); + + return $cartId; + } +} diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rule_free_shipping_by_product_weight.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rule_free_shipping_by_product_weight.php new file mode 100644 index 0000000000000..d59f63d2f3136 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rule_free_shipping_by_product_weight.php @@ -0,0 +1,35 @@ + 'Free shipping if item weight <= 1', + 'conditions' => [ + 1 => + [ + 'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class, + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => [ + [ + 'type' => Magento\SalesRule\Model\Rule\Condition\Address::class, + 'attribute' => 'weight', + 'operator' => '<=', + 'value' => '1', + 'is_value_processed' => false, + ] + ] + ] + + ], + 'actions' => [], + ]; +$salesRule->loadPost($row); +$salesRule->save(); From 60e8c843983d9e5c64786991d07fe8be11250683 Mon Sep 17 00:00:00 2001 From: aakimov Date: Tue, 11 Oct 2016 17:21:09 +0300 Subject: [PATCH 08/11] MAGETWO-57278: ZIP in Checkout Gives Out a "validation failed" Error at Page Load --- .../Checkout/view/frontend/web/js/model/new-customer-address.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js b/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js index fe05dcebfc99a..9a3685b212b43 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js @@ -30,7 +30,7 @@ define([], function () { company: addressData.company, telephone: addressData.telephone, fax: addressData.fax, - postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode, + postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode || undefined, city: addressData.city, firstname: addressData.firstname, lastname: addressData.lastname, From b2bb4f7d88188d6457b9f75d2de23f908dba978d Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Mon, 17 Oct 2016 11:49:54 +0300 Subject: [PATCH 09/11] MAGETWO-58334: [Github] Free shipping is not applied if cart price rule match #6584 -- functional test --- .../Test/Repository/CatalogProductSimple.xml | 30 ++++++++ .../SalesRule/Test/Handler/SalesRule/Curl.php | 4 + .../SalesRule/Test/Repository/SalesRule.xml | 19 +++++ .../ShoppingCartWithFreeShippingTest.php | 77 +++++++++++++++++++ .../ShoppingCartWithFreeShippingTest.xml | 25 ++++++ 5 files changed, 155 insertions(+) create mode 100644 dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.php create mode 100644 dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.xml diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml index ecd68593b08cc..e1cbc1a1d8ba2 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml @@ -1233,5 +1233,35 @@ overnight-duffle + + + default + + Simple Product %isolation% + sku_simple_product_%isolation% + This item has weight + 10 + + 25 + In Stock + + + 560 + + + taxable_goods + + + + default + + + Catalog, Search + simple-product-%isolation% + + simple_order_default + + + diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php index 5ab10a0e26f79..310f52f75e2cf 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php @@ -70,6 +70,10 @@ class Curl extends Conditions implements SalesRuleInterface 'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class, 'attribute' => 'postcode', ], + 'Total Weight' => [ + 'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class, + 'attribute' => 'weight', + ], 'Category' => [ 'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class, 'attribute' => 'category_ids', diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml index 010b9d3233d16..13b68aca6c6eb 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml @@ -279,5 +279,24 @@ No No + + Cart price rule with free shipping by weight + Yes + + Main Website + + + NOT LOGGED IN + + No Coupon + 1 + Yes + [Total Weight|is|1] + Percent of product price discount + 0 + No + No + For matching items only + diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.php new file mode 100644 index 0000000000000..11e510759fdcc --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.php @@ -0,0 +1,77 @@ +testStepFactory = $testStepFactory; + } + + /** + * Test sales rule with free shipping applied by product weight + * + * @param \Magento\SalesRule\Test\Fixture\SalesRule $salesRule + * @param \Magento\Catalog\Test\Fixture\CatalogProductSimple $product + * @param \Magento\Checkout\Test\Fixture\Cart $cart + * @return void + */ + public function testRuleWithFreeShippingByWeight( + \Magento\SalesRule\Test\Fixture\SalesRule $salesRule, + \Magento\Catalog\Test\Fixture\CatalogProductSimple $product, + \Magento\Checkout\Test\Fixture\Cart $cart + ) { + $salesRule->persist(); + $product->persist(); + + $this->testStepFactory->create( + \Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class, + ['products' => [$product]] + )->run(); + + $this->testStepFactory->create( + \Magento\Checkout\Test\TestStep\EstimateShippingAndTaxStep::class, + ['products' => [$product], 'cart' => $cart] + )->run(); + } + + /** + * Clear data after test. + * + * @return void + */ + public function tearDown() + { + $this->testStepFactory->create(\Magento\SalesRule\Test\TestStep\DeleteAllSalesRuleStep::class)->run(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.xml new file mode 100644 index 0000000000000..7391d2281f809 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/ShoppingCartWithFreeShippingTest.xml @@ -0,0 +1,25 @@ + + + + + + rule_with_freeshipping_by_weight + default + 560.00 + 0.00 + 560.00 + + + rule_with_freeshipping_by_weight + simple_with_weight_10_for_salesrule + 560.00 + 5.00 + 565.00 + + + From 78a84d0a55b0a013d98d025472810fb3bd485263 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 18 Oct 2016 12:21:31 +0300 Subject: [PATCH 10/11] MAGETWO-57278: For Dutch locale, ZIP in checkout is already giving out a "validation failed" error at page load -- functional test --- .../Quote/Model/ResourceModel/Quote.php | 3 +- .../Unit/Model/ResourceModel/QuoteTest.php | 1 - .../Checkout/Test/Block/Onepage/Shipping.php | 10 +++- ...ingAddressJsValidationMessagesIsAbsent.php | 47 +++++++++++++++++++ .../OnePageCheckoutJsValidationTest.php | 33 +++++++++++++ .../OnePageCheckoutJsValidationTest.xml | 16 +++++++ .../Magento/Checkout/Test/etc/testcase.xml | 6 +++ 7 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertShippingAddressJsValidationMessagesIsAbsent.php create mode 100644 dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.php create mode 100644 dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.xml diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote.php b/app/code/Magento/Quote/Model/ResourceModel/Quote.php index 72172c128c58c..6113a1ba56ac1 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote.php @@ -173,7 +173,8 @@ public function getReservedOrderId($quote) } /** - * Check is order increment id use in sales/order table + * Check if order increment ID is already used. + * Method can be used to avoid collisions of order IDs. * * @param int $orderIncrementId * @return bool diff --git a/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php index 102e3471063f1..15c58073c2e26 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php @@ -6,7 +6,6 @@ namespace Magento\Quote\Test\Unit\Model\ResourceModel; - class QuoteTest extends \PHPUnit_Framework_TestCase { /** diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php index a3eda5ea1b3c5..d29bad980faca 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php @@ -13,5 +13,13 @@ */ class Shipping extends Form { - // + /** + * Returns form's required elements + * + * @return \Magento\Mtf\Client\ElementInterface[] + */ + public function getRequiredFields() + { + return $this->_rootElement->getElements("div .field._required"); + } } diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertShippingAddressJsValidationMessagesIsAbsent.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertShippingAddressJsValidationMessagesIsAbsent.php new file mode 100644 index 0000000000000..f4f46a1c2b7c2 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertShippingAddressJsValidationMessagesIsAbsent.php @@ -0,0 +1,47 @@ +getShippingBlock()->getRequiredFields(); + + /** @var \Magento\Mtf\Client\ElementInterface $field */ + foreach ($requiredFields as $field) { + $errorContainer = $field->find("div .field-error"); + \PHPUnit_Framework_Assert::assertFalse( + $errorContainer->isVisible(), + 'Js validation error messages must be absent for required fields after checkout start.' + ); + } + } + + /** + * Returns string representation of successful assertion + * + * @return string + */ + public function toString() + { + return 'Js validation messages are absent for required fields.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.php new file mode 100644 index 0000000000000..5361ee6e3c127 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.php @@ -0,0 +1,33 @@ +executeScenario(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.xml b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.xml new file mode 100644 index 0000000000000..e930ff29882ce --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutJsValidationTest.xml @@ -0,0 +1,16 @@ + + + + + + catalogProductSimple::default + guest + + + + diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml index a26a2cead49b0..24eb96c0a9347 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml @@ -22,4 +22,10 @@ + + + + + + From 242c0d370b67fe314b624eca46f771cdde0f76ad Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 18 Oct 2016 13:00:53 +0300 Subject: [PATCH 11/11] MAGETWO-57278: For Dutch locale, ZIP in checkout is already giving out a "validation failed" error at page load --- .../Magento/Test/Integrity/_files/blacklist/reference.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt index 836a928dc5a72..e4078a959c7a8 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt @@ -115,3 +115,4 @@ DoubleColon \Magento\TestModuleMessageQueueConfiguration\AsyncHandler \Magento\TestModuleMessageQueueConfiguration\SyncHandler \Magento\TestModuleAsyncAmqp\Model\AsyncTestData +\Magento\Mtf\Client\ElementInterface