From 648dcf43278863acf5c029bbd7cb94e569ea54e6 Mon Sep 17 00:00:00 2001 From: Erfan Date: Wed, 19 Dec 2018 16:36:15 +0800 Subject: [PATCH 01/80] Added custom_options file upload directory to .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 68d38d9ca7817..8a15fbacaf638 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ atlassian* /pub/media/import/* !/pub/media/import/.htaccess /pub/media/logo/* +/pub/media/custom_options/* /pub/media/theme/* /pub/media/theme_customization/* !/pub/media/theme_customization/.htaccess From 3ee104d59b0dbe9f843bcca162ce24cef6ac09fa Mon Sep 17 00:00:00 2001 From: Jeroen van Leusden Date: Wed, 12 Dec 2018 15:29:34 +0100 Subject: [PATCH 02/80] Use repository to load order when manually creating an invoice ENGCOM-3679: Static test fix. ENGCOM-3679: Unit test fix. --- .../Adminhtml/Order/Invoice/NewAction.php | 28 +++++++---- .../Adminhtml/Order/Invoice/NewActionTest.php | 47 +++++++++---------- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php index 3295b244f323e..ceb231248ef5e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php @@ -1,18 +1,21 @@ registry = $registry; $this->resultPageFactory = $resultPageFactory; - parent::__construct($context); $this->invoiceService = $invoiceService; + $this->orderRepository = $orderRepository ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(OrderRepositoryInterface::class); } /** @@ -78,14 +91,11 @@ public function execute() { $orderId = $this->getRequest()->getParam('order_id'); $invoiceData = $this->getRequest()->getParam('invoice', []); - $invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : []; + $invoiceItems = $invoiceData['items'] ?? []; try { /** @var \Magento\Sales\Model\Order $order */ - $order = $this->_objectManager->create(\Magento\Sales\Model\Order::class)->load($orderId); - if (!$order->getId()) { - throw new \Magento\Framework\Exception\LocalizedException(__('The order no longer exists.')); - } + $order = $this->orderRepository->get($orderId); if (!$order->canInvoice()) { throw new \Magento\Framework\Exception\LocalizedException( diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php index 05c99c9f9ef98..87e27fdb2206b 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php @@ -6,12 +6,14 @@ namespace Magento\Sales\Test\Unit\Controller\Adminhtml\Order\Invoice; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Sales\Api\OrderRepositoryInterface; /** * Class NewActionTest * @package Magento\Sales\Controller\Adminhtml\Order\Invoice * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class NewActionTest extends \PHPUnit\Framework\TestCase { @@ -90,6 +92,11 @@ class NewActionTest extends \PHPUnit\Framework\TestCase */ protected $invoiceServiceMock; + /** + * @var OrderRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $orderRepositoryMock; + protected function setUp() { $objectManager = new ObjectManager($this); @@ -215,12 +222,15 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->orderRepositoryMock = $this->createMock(OrderRepositoryInterface::class); + $this->controller = $objectManager->getObject( \Magento\Sales\Controller\Adminhtml\Order\Invoice\NewAction::class, [ 'context' => $contextMock, 'resultPageFactory' => $this->resultPageFactoryMock, - 'invoiceService' => $this->invoiceServiceMock + 'invoiceService' => $this->invoiceServiceMock, + 'orderRepository' => $this->orderRepositoryMock ] ); } @@ -250,19 +260,17 @@ public function testExecute() $orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class) ->disableOriginalConstructor() - ->setMethods(['load', 'getId', 'canInvoice']) + ->setMethods(['load', 'canInvoice']) ->getMock(); - $orderMock->expects($this->once()) - ->method('load') - ->with($orderId) - ->willReturnSelf(); - $orderMock->expects($this->once()) - ->method('getId') - ->willReturn($orderId); $orderMock->expects($this->once()) ->method('canInvoice') ->willReturn(true); + $this->orderRepositoryMock->expects($this->once()) + ->method('get') + ->with($orderId) + ->willReturn($orderMock); + $this->invoiceServiceMock->expects($this->once()) ->method('prepareInvoice') ->with($orderMock, []) @@ -285,11 +293,7 @@ public function testExecute() ->with(true) ->will($this->returnValue($commentText)); - $this->objectManagerMock->expects($this->at(0)) - ->method('create') - ->with(\Magento\Sales\Model\Order::class) - ->willReturn($orderMock); - $this->objectManagerMock->expects($this->at(1)) + $this->objectManagerMock->expects($this->once()) ->method('get') ->with(\Magento\Backend\Model\Session::class) ->will($this->returnValue($this->sessionMock)); @@ -318,19 +322,12 @@ public function testExecuteNoOrder() $orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class) ->disableOriginalConstructor() - ->setMethods(['load', 'getId', 'canInvoice']) + ->setMethods(['canInvoice']) ->getMock(); - $orderMock->expects($this->once()) - ->method('load') - ->with($orderId) - ->willReturnSelf(); - $orderMock->expects($this->once()) - ->method('getId') - ->willReturn(null); - $this->objectManagerMock->expects($this->at(0)) - ->method('create') - ->with(\Magento\Sales\Model\Order::class) + $this->orderRepositoryMock->expects($this->once()) + ->method('get') + ->with($orderId) ->willReturn($orderMock); $resultRedirect = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class) From a0566abffe872cca0a7e06eb2b4d08093f15fbda Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Fri, 11 Jan 2019 11:18:28 +0100 Subject: [PATCH 03/80] Deny access to XML and PHTML files in pub/errors For apache via .htaccess and in nginx sample configuration --- nginx.conf.sample | 7 ++++++- pub/errors/.htaccess | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nginx.conf.sample b/nginx.conf.sample index 90604808f6ec0..80cc88431eff8 100644 --- a/nginx.conf.sample +++ b/nginx.conf.sample @@ -159,6 +159,11 @@ location /media/downloadable/ { location /media/import/ { deny all; } +location /errors/ { + location ~* \.xml$ { + deny all; + } +} # PHP entry point for main application location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ { @@ -198,6 +203,6 @@ gzip_types gzip_vary on; # Banned locations (only reached if the earlier PHP entry point regexes don't match) -location ~* (\.php$|\.htaccess$|\.git) { +location ~* (\.php$|\.phtml$|\.htaccess$|\.git) { deny all; } diff --git a/pub/errors/.htaccess b/pub/errors/.htaccess index 3692dd439e2ff..a7b9cbda05893 100644 --- a/pub/errors/.htaccess +++ b/pub/errors/.htaccess @@ -1,4 +1,7 @@ Options None + + Deny from all + RewriteEngine Off From 24382e3eb968d13e4a86955cbdc2966b989afe1c Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Tue, 29 Jan 2019 19:34:06 +0200 Subject: [PATCH 04/80] ENGCOM-20434: Consider deleting/creating url rewrites on change the product attribute visibility via mass action --- ...writeOnChangeProductVisibilityObserver.php | 106 ++++++++++++++++++ ...ProductProcessUrlRewriteSavingObserver.php | 39 ++++++- ...uctProcessUrlRewriteSavingObserverTest.php | 52 +++++++-- .../Magento/CatalogUrlRewrite/etc/events.xml | 3 + .../product_configurable_not_available.php | 2 +- ...uctProcessUrlRewriteSavingObserverTest.php | 30 ++++- .../_files/configurable_products.php | 2 +- .../Framework/DB/Adapter/Pdo/Mysql.php | 4 - 8 files changed, 213 insertions(+), 25 deletions(-) create mode 100644 app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php new file mode 100644 index 0000000000000..16d12bd4c7e4b --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php @@ -0,0 +1,106 @@ +productCollectionFactory = $collectionFactory; + $this->urlRewriteGenerator = $urlRewriteGenerator; + $this->urlPersist = $urlPersist; + $this->urlPathGenerator = $urlPathGenerator; + } + /** + * Generate urls for UrlRewrites and save it in storage + * + * @param Observer $observer + * @return array + * @throws UrlAlreadyExistsException + */ + public function execute(Observer $observer) + { + $event = $observer->getEvent(); + $attrData = $event->getAttributesData(); + $productIds = $event->getProductIds(); + $storeId = $event->getStoreId(); + $visibility = $attrData[ProductInterface::VISIBILITY] ?? null; + + if (!$visibility) { + return [$attrData, $productIds, $storeId]; + } + + $productCollection = $this->productCollectionFactory->create(); + $productCollection->addAttributeToSelect(ProductInterface::VISIBILITY); + $productCollection->addAttributeToSelect('url_key'); + $productCollection->addFieldToFilter( + 'entity_id', + ['in' => array_unique($productIds)] + ); + + foreach ($productCollection as $product) { + if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) { + $this->urlPersist->deleteByData( + [ + UrlRewrite::ENTITY_ID => $product->getId(), + UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, + ] + ); + } elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) { + $product->setVisibility($visibility); + $productUrlPath = $this->urlPathGenerator->getUrlPath($product); + $productUrlRewrite = $this->urlRewriteGenerator->generate($product); + $product->unsUrlPath(); + $product->setUrlPath($productUrlPath); + $this->urlPersist->replace($productUrlRewrite); + } + } + + return [$attrData, $productIds, $storeId]; + } +} diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php index 6eda8dd0b61ee..c5a1c1e429bfa 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php @@ -3,14 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\CatalogUrlRewrite\Observer; use Magento\Catalog\Model\Product; use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator; use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; use Magento\Framework\App\ObjectManager; +use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; use Magento\UrlRewrite\Model\UrlPersistInterface; use Magento\Framework\Event\ObserverInterface; +use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; /** * Class ProductProcessUrlRewriteSavingObserver @@ -32,20 +36,29 @@ class ProductProcessUrlRewriteSavingObserver implements ObserverInterface */ private $productUrlPathGenerator; + /** + * @var CollectionFactory + */ + private $collectionFactory; + /** * @param ProductUrlRewriteGenerator $productUrlRewriteGenerator * @param UrlPersistInterface $urlPersist - * @param ProductUrlPathGenerator|null $productUrlPathGenerator + * @param ProductUrlPathGenerator|null $urlPathGenerator + * @param CollectionFactory|null $collectionFactory */ public function __construct( ProductUrlRewriteGenerator $productUrlRewriteGenerator, UrlPersistInterface $urlPersist, - ProductUrlPathGenerator $productUrlPathGenerator = null + ProductUrlPathGenerator $urlPathGenerator = null, + CollectionFactory $collectionFactory = null ) { $this->productUrlRewriteGenerator = $productUrlRewriteGenerator; $this->urlPersist = $urlPersist; - $this->productUrlPathGenerator = $productUrlPathGenerator ?: ObjectManager::getInstance() + $this->productUrlPathGenerator = $urlPathGenerator ?: ObjectManager::getInstance() ->get(ProductUrlPathGenerator::class); + $this->collectionFactory = $collectionFactory ?: ObjectManager::getInstance() + ->get(CollectionFactory::class); } /** @@ -69,7 +82,27 @@ public function execute(\Magento\Framework\Event\Observer $observer) $product->unsUrlPath(); $product->setUrlPath($this->productUrlPathGenerator->getUrlPath($product)); $this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product)); + return; } } + $this->validateUrlKey($product); + } + + /** + * @param Product $product + * @throws UrlAlreadyExistsException + */ + private function validateUrlKey(Product $product) + { + $productCollection = $this->collectionFactory->create(); + $productCollection->addFieldToFilter( + 'url_key', + ['in' => $product->getUrlKey()] + ); + $productCollection->getSelect()->where('e.entity_id != ?', $product->getId()); + + if ($productCollection->getItems()) { + throw new UrlAlreadyExistsException(); + } } } diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php index 39317b42af989..3df850f51e695 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php @@ -6,9 +6,7 @@ namespace Magento\CatalogUrlRewrite\Test\Unit\Observer; -use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; /** * Class ProductProcessUrlRewriteSavingObserverTest @@ -48,6 +46,21 @@ class ProductProcessUrlRewriteSavingObserverTest extends \PHPUnit\Framework\Test */ protected $objectManager; + /** + * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory + */ + private $collectionFactory; + + /** + * @var \Magento\Catalog\Model\ResourceModel\Product\Collection + */ + private $productCollection; + + /** + * @var \Magento\Framework\DB\Select + */ + private $select; + /** * @var \Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver */ @@ -60,13 +73,13 @@ protected function setUp() { $this->urlPersist = $this->createMock(\Magento\UrlRewrite\Model\UrlPersistInterface::class); $this->product = $this->createPartialMock(\Magento\Catalog\Model\Product::class, [ - 'getId', - 'dataHasChangedFor', - 'isVisibleInSiteVisibility', - 'getIsChangedWebsites', - 'getIsChangedCategories', - 'getStoreId' - ]); + 'getId', + 'dataHasChangedFor', + 'isVisibleInSiteVisibility', + 'getIsChangedWebsites', + 'getIsChangedCategories', + 'getStoreId' + ]); $this->product->expects($this->any())->method('getId')->will($this->returnValue(3)); $this->event = $this->createPartialMock(\Magento\Framework\Event::class, ['getProduct']); $this->event->expects($this->any())->method('getProduct')->willReturn($this->product); @@ -79,12 +92,28 @@ protected function setUp() $this->productUrlRewriteGenerator->expects($this->any()) ->method('generate') ->will($this->returnValue([3 => 'rewrite'])); + $this->collectionFactory = $this->createMock( + \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class + ); + $this->productCollection = $this->createMock( + \Magento\Catalog\Model\ResourceModel\Product\Collection::class + ); + $this->select = $this->createMock( + \Magento\Framework\DB\Select::class + ); + $this->collectionFactory->expects($this->any()) + ->method('create') + ->will($this->returnValue($this->productCollection)); + $this->productCollection->expects($this->any()) + ->method('getSelect') + ->will($this->returnValue($this->select)); $this->objectManager = new ObjectManager($this); $this->model = $this->objectManager->getObject( \Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver::class, [ 'productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, - 'urlPersist' => $this->urlPersist + 'urlPersist' => $this->urlPersist, + 'collectionFactory' => $this->collectionFactory ] ); } @@ -103,8 +132,7 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => false, 'visibilityResult' => true, - 'expectedReplaceCount' => 1, - + 'expectedReplaceCount' => 1 ], 'no chnages' => [ 'isChangedUrlKey' => false, diff --git a/app/code/Magento/CatalogUrlRewrite/etc/events.xml b/app/code/Magento/CatalogUrlRewrite/etc/events.xml index cc558fe81f16d..728442acf7a44 100644 --- a/app/code/Magento/CatalogUrlRewrite/etc/events.xml +++ b/app/code/Magento/CatalogUrlRewrite/etc/events.xml @@ -27,6 +27,9 @@ + + + diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php index 73467cd8d063e..87290e0b8259c 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php @@ -43,7 +43,7 @@ $productSku = array_shift($productsSku); $product->setTypeId(Type::TYPE_SIMPLE) ->setAttributeSetId($attributeSetId) - ->setName('Configurable Option' . $option->getLabel()) + ->setName('Configurable Option Not Available' . $option->getLabel()) ->setSku('simple_not_avalilable_' . $productSku) ->setPrice(11) ->setTestConfigurable($option->getValue()) diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php index c72a58197b1fd..f902ee993b84e 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php @@ -5,9 +5,11 @@ */ namespace Magento\CatalogUrlRewrite\Observer; +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Catalog\Model\Product\Visibility; use Magento\Store\Model\StoreManagerInterface; +use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; -use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; /** * @magentoAppArea adminhtml @@ -18,12 +20,16 @@ class ProductProcessUrlRewriteSavingObserverTest extends \PHPUnit\Framework\Test /** @var \Magento\Framework\ObjectManagerInterface */ protected $objectManager; + /** @var ProductRepositoryInterface */ + private $productRepository; + /** * Set up */ protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); } /** @@ -136,10 +142,8 @@ public function testUrlKeyHasChangedInGlobalContext() */ public function testUrlKeyHasChangedInStoreviewContextWithPermanentRedirection() { - /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository*/ - $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); /** @var \Magento\Catalog\Model\Product $product*/ - $product = $productRepository->get('product1'); + $product = $this->productRepository->get('product1'); /** @var StoreManagerInterface $storeManager */ $storeManager = $this->objectManager->get(StoreManagerInterface::class); @@ -234,4 +238,22 @@ public function testUrlKeyHasChangedInStoreviewContextWithoutPermanentRedirectio $this->assertContains($row, $actual); } } + + /** + * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php + * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php + * @magentoAppIsolation enabled + */ + public function testDuplicatedUrlKeyInvisibleProduct() + { + $this->expectException( + UrlAlreadyExistsException::class, + 'URL key for specified store already exists' + ); + /** @var \Magento\Catalog\Model\Product $product*/ + $product = $this->productRepository->get('simple2'); + $product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE); + $product->setUrlKey('simple_product'); + $product->save(); + } } diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php index 985c77dba6626..afebcab773d9c 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php @@ -107,7 +107,7 @@ ->setId($productId) ->setAttributeSetId($attributeSetId) ->setWebsiteIds([1]) - ->setName('Configurable Option' . $option->getLabel()) + ->setName('Configurable Option 12345' . $option->getLabel()) ->setSku('simple_' . $productId) ->setPrice($productId) ->setTestConfigurable($option->getValue()) diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index 86266ec23fe47..dfa30e1964e31 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -384,10 +384,6 @@ protected function _connect() throw new \Zend_Db_Adapter_Exception('No host configured to connect'); } - if (isset($this->_config['port'])) { - throw new \Zend_Db_Adapter_Exception('Port must be configured within host parameter (like localhost:3306'); - } - unset($this->_config['port']); if (strpos($this->_config['host'], '/') !== false) { From 4d18c9a92cd8f1acdd780ce933f2860e7d092f7f Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Tue, 29 Jan 2019 19:36:12 +0200 Subject: [PATCH 05/80] ENGCOM-20434: Added accidentally removed code --- lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index dfa30e1964e31..86266ec23fe47 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -384,6 +384,10 @@ protected function _connect() throw new \Zend_Db_Adapter_Exception('No host configured to connect'); } + if (isset($this->_config['port'])) { + throw new \Zend_Db_Adapter_Exception('Port must be configured within host parameter (like localhost:3306'); + } + unset($this->_config['port']); if (strpos($this->_config['host'], '/') !== false) { From 6a5776c46396810875f46e986e56594e8e5ea30c Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sat, 2 Feb 2019 20:02:54 +0200 Subject: [PATCH 06/80] ENGCOM-20434: Removed url key validation for invisible products --- ...ProductProcessUrlRewriteSavingObserver.php | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php index c5a1c1e429bfa..6eda8dd0b61ee 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php @@ -3,18 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); - namespace Magento\CatalogUrlRewrite\Observer; use Magento\Catalog\Model\Product; use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator; use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; use Magento\Framework\App\ObjectManager; -use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; use Magento\UrlRewrite\Model\UrlPersistInterface; use Magento\Framework\Event\ObserverInterface; -use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; /** * Class ProductProcessUrlRewriteSavingObserver @@ -36,29 +32,20 @@ class ProductProcessUrlRewriteSavingObserver implements ObserverInterface */ private $productUrlPathGenerator; - /** - * @var CollectionFactory - */ - private $collectionFactory; - /** * @param ProductUrlRewriteGenerator $productUrlRewriteGenerator * @param UrlPersistInterface $urlPersist - * @param ProductUrlPathGenerator|null $urlPathGenerator - * @param CollectionFactory|null $collectionFactory + * @param ProductUrlPathGenerator|null $productUrlPathGenerator */ public function __construct( ProductUrlRewriteGenerator $productUrlRewriteGenerator, UrlPersistInterface $urlPersist, - ProductUrlPathGenerator $urlPathGenerator = null, - CollectionFactory $collectionFactory = null + ProductUrlPathGenerator $productUrlPathGenerator = null ) { $this->productUrlRewriteGenerator = $productUrlRewriteGenerator; $this->urlPersist = $urlPersist; - $this->productUrlPathGenerator = $urlPathGenerator ?: ObjectManager::getInstance() + $this->productUrlPathGenerator = $productUrlPathGenerator ?: ObjectManager::getInstance() ->get(ProductUrlPathGenerator::class); - $this->collectionFactory = $collectionFactory ?: ObjectManager::getInstance() - ->get(CollectionFactory::class); } /** @@ -82,27 +69,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $product->unsUrlPath(); $product->setUrlPath($this->productUrlPathGenerator->getUrlPath($product)); $this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product)); - return; } } - $this->validateUrlKey($product); - } - - /** - * @param Product $product - * @throws UrlAlreadyExistsException - */ - private function validateUrlKey(Product $product) - { - $productCollection = $this->collectionFactory->create(); - $productCollection->addFieldToFilter( - 'url_key', - ['in' => $product->getUrlKey()] - ); - $productCollection->getSelect()->where('e.entity_id != ?', $product->getId()); - - if ($productCollection->getItems()) { - throw new UrlAlreadyExistsException(); - } } } From f2088d9b59d0fcf6d521d510fcc37d11e3308f03 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sat, 2 Feb 2019 20:04:24 +0200 Subject: [PATCH 07/80] ENGCOM-20434: Removed url key validation for invisible products (revert tests) --- .../product_configurable_not_available.php | 2 +- ...uctProcessUrlRewriteSavingObserverTest.php | 30 +++---------------- .../_files/configurable_products.php | 2 +- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php index 87290e0b8259c..73467cd8d063e 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/_files/product_configurable_not_available.php @@ -43,7 +43,7 @@ $productSku = array_shift($productsSku); $product->setTypeId(Type::TYPE_SIMPLE) ->setAttributeSetId($attributeSetId) - ->setName('Configurable Option Not Available' . $option->getLabel()) + ->setName('Configurable Option' . $option->getLabel()) ->setSku('simple_not_avalilable_' . $productSku) ->setPrice(11) ->setTestConfigurable($option->getValue()) diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php index f902ee993b84e..c72a58197b1fd 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php @@ -5,11 +5,9 @@ */ namespace Magento\CatalogUrlRewrite\Observer; -use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Catalog\Model\Product\Visibility; use Magento\Store\Model\StoreManagerInterface; -use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; +use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; /** * @magentoAppArea adminhtml @@ -20,16 +18,12 @@ class ProductProcessUrlRewriteSavingObserverTest extends \PHPUnit\Framework\Test /** @var \Magento\Framework\ObjectManagerInterface */ protected $objectManager; - /** @var ProductRepositoryInterface */ - private $productRepository; - /** * Set up */ protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); } /** @@ -142,8 +136,10 @@ public function testUrlKeyHasChangedInGlobalContext() */ public function testUrlKeyHasChangedInStoreviewContextWithPermanentRedirection() { + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository*/ + $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); /** @var \Magento\Catalog\Model\Product $product*/ - $product = $this->productRepository->get('product1'); + $product = $productRepository->get('product1'); /** @var StoreManagerInterface $storeManager */ $storeManager = $this->objectManager->get(StoreManagerInterface::class); @@ -238,22 +234,4 @@ public function testUrlKeyHasChangedInStoreviewContextWithoutPermanentRedirectio $this->assertContains($row, $actual); } } - - /** - * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php - * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php - * @magentoAppIsolation enabled - */ - public function testDuplicatedUrlKeyInvisibleProduct() - { - $this->expectException( - UrlAlreadyExistsException::class, - 'URL key for specified store already exists' - ); - /** @var \Magento\Catalog\Model\Product $product*/ - $product = $this->productRepository->get('simple2'); - $product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE); - $product->setUrlKey('simple_product'); - $product->save(); - } } diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php index afebcab773d9c..985c77dba6626 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_products.php @@ -107,7 +107,7 @@ ->setId($productId) ->setAttributeSetId($attributeSetId) ->setWebsiteIds([1]) - ->setName('Configurable Option 12345' . $option->getLabel()) + ->setName('Configurable Option' . $option->getLabel()) ->setSku('simple_' . $productId) ->setPrice($productId) ->setTestConfigurable($option->getValue()) From 4edec382f3517f64284ba45fb341e4bcce1745ab Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sat, 2 Feb 2019 20:06:54 +0200 Subject: [PATCH 08/80] ENGCOM-20434: Removed url key validation for invisible products (revert unit test) --- ...uctProcessUrlRewriteSavingObserverTest.php | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php index 3df850f51e695..39317b42af989 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php @@ -6,7 +6,9 @@ namespace Magento\CatalogUrlRewrite\Test\Unit\Observer; +use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; /** * Class ProductProcessUrlRewriteSavingObserverTest @@ -46,21 +48,6 @@ class ProductProcessUrlRewriteSavingObserverTest extends \PHPUnit\Framework\Test */ protected $objectManager; - /** - * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory - */ - private $collectionFactory; - - /** - * @var \Magento\Catalog\Model\ResourceModel\Product\Collection - */ - private $productCollection; - - /** - * @var \Magento\Framework\DB\Select - */ - private $select; - /** * @var \Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver */ @@ -73,13 +60,13 @@ protected function setUp() { $this->urlPersist = $this->createMock(\Magento\UrlRewrite\Model\UrlPersistInterface::class); $this->product = $this->createPartialMock(\Magento\Catalog\Model\Product::class, [ - 'getId', - 'dataHasChangedFor', - 'isVisibleInSiteVisibility', - 'getIsChangedWebsites', - 'getIsChangedCategories', - 'getStoreId' - ]); + 'getId', + 'dataHasChangedFor', + 'isVisibleInSiteVisibility', + 'getIsChangedWebsites', + 'getIsChangedCategories', + 'getStoreId' + ]); $this->product->expects($this->any())->method('getId')->will($this->returnValue(3)); $this->event = $this->createPartialMock(\Magento\Framework\Event::class, ['getProduct']); $this->event->expects($this->any())->method('getProduct')->willReturn($this->product); @@ -92,28 +79,12 @@ protected function setUp() $this->productUrlRewriteGenerator->expects($this->any()) ->method('generate') ->will($this->returnValue([3 => 'rewrite'])); - $this->collectionFactory = $this->createMock( - \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class - ); - $this->productCollection = $this->createMock( - \Magento\Catalog\Model\ResourceModel\Product\Collection::class - ); - $this->select = $this->createMock( - \Magento\Framework\DB\Select::class - ); - $this->collectionFactory->expects($this->any()) - ->method('create') - ->will($this->returnValue($this->productCollection)); - $this->productCollection->expects($this->any()) - ->method('getSelect') - ->will($this->returnValue($this->select)); $this->objectManager = new ObjectManager($this); $this->model = $this->objectManager->getObject( \Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver::class, [ 'productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, - 'urlPersist' => $this->urlPersist, - 'collectionFactory' => $this->collectionFactory + 'urlPersist' => $this->urlPersist ] ); } @@ -132,7 +103,8 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => false, 'visibilityResult' => true, - 'expectedReplaceCount' => 1 + 'expectedReplaceCount' => 1, + ], 'no chnages' => [ 'isChangedUrlKey' => false, From a8d1dc042d663adf6b1667192ba3f044c57d51f1 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sat, 2 Feb 2019 20:09:02 +0200 Subject: [PATCH 09/80] ENGCOM-20434: static fixes --- .../ProcessUrlRewriteOnChangeProductVisibilityObserver.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php index 16d12bd4c7e4b..6006f75035409 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php @@ -27,18 +27,22 @@ class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInte * @var CollectionFactory */ private $productCollectionFactory; + /** * @var ProductUrlRewriteGenerator */ private $urlRewriteGenerator; + /** * @var UrlPersistInterface */ private $urlPersist; + /** * @var ProductUrlPathGenerator */ private $urlPathGenerator; + /** * @param CollectionFactory $collectionFactory * @param ProductUrlRewriteGenerator $urlRewriteGenerator @@ -56,6 +60,7 @@ public function __construct( $this->urlPersist = $urlPersist; $this->urlPathGenerator = $urlPathGenerator; } + /** * Generate urls for UrlRewrites and save it in storage * From 7e87746f56a46c1be06111520030ca5b917bdec5 Mon Sep 17 00:00:00 2001 From: vprohorov Date: Tue, 12 Feb 2019 22:36:01 +0300 Subject: [PATCH 10/80] MAGETWO-62728: My Wishlist - quantity input box issue - Adding min/max qty checks - Adding js validation --- .../Wishlist/ViewModel/AllowedQuantity.php | 80 +++++++++++++++++++ .../frontend/layout/wishlist_index_index.xml | 1 + .../frontend/templates/item/column/cart.phtml | 5 +- .../view/frontend/web/js/add-to-wishlist.js | 57 ++++++------- 4 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 app/code/Magento/Wishlist/ViewModel/AllowedQuantity.php diff --git a/app/code/Magento/Wishlist/ViewModel/AllowedQuantity.php b/app/code/Magento/Wishlist/ViewModel/AllowedQuantity.php new file mode 100644 index 0000000000000..5e4c6b39f3c36 --- /dev/null +++ b/app/code/Magento/Wishlist/ViewModel/AllowedQuantity.php @@ -0,0 +1,80 @@ +stockRegistry = $stockRegistry; + } + + /** + * Set product configuration item + * + * @param ItemInterface $item + * @return self + */ + public function setItem(ItemInterface $item): self + { + $this->item = $item; + return $this; + } + + /** + * Get product configuration item + * + * @return ItemInterface + */ + public function getItem(): ItemInterface + { + return $this->item; + } + + /** + * Get min and max qty for wishlist form. + * + * @return array + */ + public function getMinMaxQty(): array + { + $product = $this->getItem()->getProduct(); + $stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId()); + $params = []; + + $params['minAllowed'] = (float)$stockItem->getMinSaleQty(); + if ($stockItem->getMaxSaleQty()) { + $params['maxAllowed'] = (float)$stockItem->getMaxSaleQty(); + } else { + $params['maxAllowed'] = (float)StockDataFilter::MAX_QTY_VALUE; + } + + return $params; + } +} diff --git a/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_index.xml b/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_index.xml index d3f21dda9ccde..e9076021a5b73 100644 --- a/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_index.xml +++ b/app/code/Magento/Wishlist/view/frontend/layout/wishlist_index_index.xml @@ -40,6 +40,7 @@ + Magento\Wishlist\ViewModel\AllowedQuantity Add to Cart diff --git a/app/code/Magento/Wishlist/view/frontend/templates/item/column/cart.phtml b/app/code/Magento/Wishlist/view/frontend/templates/item/column/cart.phtml index 9ea0d1a823235..6cb32d70ee1d8 100644 --- a/app/code/Magento/Wishlist/view/frontend/templates/item/column/cart.phtml +++ b/app/code/Magento/Wishlist/view/frontend/templates/item/column/cart.phtml @@ -11,6 +11,9 @@ /** @var \Magento\Wishlist\Model\Item $item */ $item = $block->getItem(); $product = $item->getProduct(); +/** @var \Magento\Wishlist\ViewModel\AllowedQuantity $viewModel */ +$viewModel = $block->getData('allowedQuantityViewModel'); +$allowedQty = $viewModel->setItem($item)->getMinMaxQty(); ?> getChildNames() as $childName): ?> getLayout()->renderElement($childName, false) ?> @@ -21,7 +24,7 @@ $product = $item->getProduct();
-
diff --git a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js index b38c5c2cda3ad..7a166b47256cb 100644 --- a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js +++ b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js @@ -63,12 +63,6 @@ define([ isFileUploaded = false, self = this; - if (event.handleObj.selector == this.options.qtyInfo) { //eslint-disable-line eqeqeq - this._updateAddToWishlistButton({}); - event.stopPropagation(); - - return; - } $(event.handleObj.selector).each(function (index, element) { if ($(element).is('input[type=text]') || $(element).is('input[type=email]') || @@ -89,9 +83,7 @@ define([ } }); - if (isFileUploaded) { - this.bindFormSubmit(); - } + this.bindFormSubmit(isFileUploaded); this._updateAddToWishlistButton(dataToAdd); event.stopPropagation(); }, @@ -189,34 +181,45 @@ define([ /** * Bind form submit. + * + * @param {Boolean} isFileUploaded */ - bindFormSubmit: function () { + bindFormSubmit: function (isFileUploaded) { var self = this; $('[data-action="add-to-wishlist"]').on('click', function (event) { var element, params, form, action; - event.stopPropagation(); - event.preventDefault(); + if (!$($(self.options.qtyInfo).closest('form')).valid()) { + event.stopPropagation(); + event.preventDefault(); - element = $('input[type=file]' + self.options.customOptionsInfo); - params = $(event.currentTarget).data('post'); - form = $(element).closest('form'); - action = params.action; - - if (params.data.id) { - $('', { - type: 'hidden', - name: 'id', - value: params.data.id - }).appendTo(form); + return; } - if (params.data.uenc) { - action += 'uenc/' + params.data.uenc; - } + if (isFileUploaded) { + + element = $('input[type=file]' + self.options.customOptionsInfo); + params = $(event.currentTarget).data('post'); + form = $(element).closest('form'); + action = params.action; + + if (params.data.id) { + $('', { + type: 'hidden', + name: 'id', + value: params.data.id + }).appendTo(form); + } - $(form).attr('action', action).submit(); + if (params.data.uenc) { + action += 'uenc/' + params.data.uenc; + } + + $(form).attr('action', action).submit(); + event.stopPropagation(); + event.preventDefault(); + } }); } }); From 5951f685da0ada37e8aadbaa6de08d75a9099ec9 Mon Sep 17 00:00:00 2001 From: Mikalai Shostka Date: Wed, 13 Feb 2019 21:04:01 +0300 Subject: [PATCH 11/80] MAGETWO-51459: [FT] CreateCategoryEntityTest fail when system message about indexers update is displayed - Fixed MFT test; --- .../app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php | 2 ++ .../Catalog/Test/Block/Product/ProductList/TopToolbar.php | 2 +- .../Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php index 2035e7e83200f..30a323eebb736 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php @@ -187,6 +187,8 @@ public function assignCategory($parentCategoryName, $childCategoryName) */ public function expandAllCategories() { + $this->getTemplateBlock()->waitLoader(); $this->_rootElement->find($this->expandAll)->click(); + $this->getTemplateBlock()->waitLoader(); } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php index 090042140a548..48769126d88ea 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php @@ -48,7 +48,7 @@ public function getSelectSortType() public function getSortType() { $content = $this->_rootElement->find($this->sorter)->getText(); - return explode("\n", $content); + return array_values(array_filter(array_map('trim', explode("\n", $content)))); } /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml index c6a66beac7c79..ea6808ee2a7f5 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml @@ -96,6 +96,7 @@ + test_type:acceptance_test Create anchor subcategory with all fields addSubcategory default_category From d79eb085cabfb16ed8f4432f5cd25b00cf3ba686 Mon Sep 17 00:00:00 2001 From: "Rav [RedChamps]" Date: Sat, 16 Feb 2019 10:38:57 +0530 Subject: [PATCH 12/80] Added refunded discount amount to the total revenue calculation and fixed Negative order amount in dashboard when viewing particular store data --- .../Reports/Model/ResourceModel/Order/Collection.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php index fd9adbe734101..5c92fc4c3cdb5 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php @@ -773,6 +773,7 @@ public function addRevenueToSelect($convertCurrency = false) !$convertCurrency, $this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0), + $this->getConnection()->getIfNullSql('main_table.base_discount_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0) ); $this->getSelect()->columns(['revenue' => $expr]); @@ -795,6 +796,7 @@ public function addSumAvgTotals($storeId = 0) $storeId, $this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0), + $this->getConnection()->getIfNullSql('main_table.base_discount_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0) ); @@ -813,6 +815,7 @@ public function addSumAvgTotals($storeId = 0) * @param int $storeId * @param string $baseSubtotalRefunded * @param string $baseSubtotalCanceled + * @param string $baseDiscountRefunded * @param string $baseDiscountCanceled * @return string */ @@ -820,13 +823,14 @@ protected function getTotalsExpression( $storeId, $baseSubtotalRefunded, $baseSubtotalCanceled, + $baseDiscountRefunded, $baseDiscountCanceled ) { $template = ($storeId != 0) - ? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)' - : '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) ' + ? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) + %3$s + %4$s)' + : '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s + %4$s) ' . ' * main_table.base_to_global_rate)'; - return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled); + return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountRefunded, $baseDiscountCanceled); } /** From d1e71b96056f2b83d182c92120008837cd665b9f Mon Sep 17 00:00:00 2001 From: "Rav [RedChamps]" Date: Sat, 16 Feb 2019 19:55:46 +0530 Subject: [PATCH 13/80] Fixed bug that total amount is showing negative when order with discount is partially refunded --- .../Reports/Model/ResourceModel/Order/Collection.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php index 5c92fc4c3cdb5..19549f7181aa9 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php @@ -773,8 +773,8 @@ public function addRevenueToSelect($convertCurrency = false) !$convertCurrency, $this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0), - $this->getConnection()->getIfNullSql('main_table.base_discount_refunded', 0), - $this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0) + $this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0), + $this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0) ); $this->getSelect()->columns(['revenue' => $expr]); @@ -796,8 +796,8 @@ public function addSumAvgTotals($storeId = 0) $storeId, $this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0), - $this->getConnection()->getIfNullSql('main_table.base_discount_refunded', 0), - $this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0) + $this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0), + $this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0) ); $this->getSelect()->columns( @@ -827,8 +827,8 @@ protected function getTotalsExpression( $baseDiscountCanceled ) { $template = ($storeId != 0) - ? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) + %3$s + %4$s)' - : '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s + %4$s) ' + ? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))' + : '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) ' . ' * main_table.base_to_global_rate)'; return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountRefunded, $baseDiscountCanceled); } From 8d4710401b9f7b5702a4addfa573b79958f02d59 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Wed, 20 Feb 2019 15:55:32 +0530 Subject: [PATCH 14/80] Correct spelling --- app/code/Magento/Ui/view/base/web/js/lib/core/storage/local.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/core/storage/local.js b/app/code/Magento/Ui/view/base/web/js/lib/core/storage/local.js index 87b5b2f5fe8fe..038907c21224d 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/core/storage/local.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/core/storage/local.js @@ -79,7 +79,7 @@ define([ /** * Extracts and parses data stored in localStorage by the - * key specified in 'root' varaible. + * key specified in 'root' variable. * * @returns {Object} */ From c865bdc25ff73168e2c2e0e093787ed766a2d068 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 20 Feb 2019 19:45:43 +0200 Subject: [PATCH 15/80] ENGCOM-20434: refactoring, test coverage --- .../AdaptUrlRewritesToVisibilityAttribute.php | 122 +++++++++++ ...writeOnChangeProductVisibilityObserver.php | 85 ++------ ...lRewriteOnChangeVisibilityObserverTest.php | 194 ++++++++++++++++++ .../_files/product_invisible_multistore.php | 40 ++++ .../product_invisible_multistore_rollback.php | 33 +++ .../_files/products_invisible.php | 38 ++++ .../_files/products_invisible_rollback.php | 37 ++++ 7 files changed, 478 insertions(+), 71 deletions(-) create mode 100644 app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible_rollback.php diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php new file mode 100644 index 0000000000000..0cadbd0acf0c2 --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php @@ -0,0 +1,122 @@ +productCollectionFactory = $collectionFactory; + $this->urlRewriteGenerator = $urlRewriteGenerator; + $this->urlPersist = $urlPersist; + $this->urlPathGenerator = $urlPathGenerator; + } + + /** + * @param array $productIds + * @param int $visibility + * @throws UrlAlreadyExistsException + */ + public function execute(array $productIds, int $visibility): void + { + $products = $this->getProductsByIds($productIds); + + /** @var Product $product */ + foreach ($products as $product) { + if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) { + $this->urlPersist->deleteByData( + [ + UrlRewrite::ENTITY_ID => $product->getId(), + UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, + ] + ); + } elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) { + $product->setVisibility($visibility); + $productUrlPath = $this->urlPathGenerator->getUrlPath($product); + $productUrlRewrite = $this->urlRewriteGenerator->generate($product); + $product->unsUrlPath(); + $product->setUrlPath($productUrlPath); + + try { + $this->urlPersist->replace($productUrlRewrite); + } catch (UrlAlreadyExistsException $e) { + throw new UrlAlreadyExistsException( + __( + 'Can not change the visibility of the product with SKU equals "%1". URL key "%2" for specified store already exists.', + $product->getSku(), + $product->getUrlKey() + ), + $e, + $e->getCode(), + $e->getUrls() + ); + } + } + } + } + + /** + * @param array $productIds + * @return array + */ + protected function getProductsByIds(array $productIds): array + { + $productCollection = $this->productCollectionFactory->create(); + $productCollection->addAttributeToSelect(ProductInterface::VISIBILITY); + $productCollection->addAttributeToSelect('url_key'); + $productCollection->addFieldToFilter( + 'entity_id', + ['in' => array_unique($productIds)] + ); + + return $productCollection->getItems(); + } +} diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php index 6006f75035409..56393c619f4ef 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php @@ -8,64 +8,34 @@ namespace Magento\CatalogUrlRewrite\Observer; use Magento\Catalog\Api\Data\ProductInterface; -use Magento\Catalog\Model\Product\Visibility; -use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator; -use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; -use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; -use Magento\UrlRewrite\Model\UrlPersistInterface; -use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; -use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; +use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; /** - * Class ProductProcessUrlRewriteSavingObserver + * Consider URL rewrites on change product visibility via mass action */ class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface { /** - * @var CollectionFactory - */ - private $productCollectionFactory; - - /** - * @var ProductUrlRewriteGenerator - */ - private $urlRewriteGenerator; - - /** - * @var UrlPersistInterface + * @var AdaptUrlRewritesToVisibilityAttribute */ - private $urlPersist; + private $adaptUrlRewritesToVisibility; /** - * @var ProductUrlPathGenerator + * @param AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility */ - private $urlPathGenerator; - - /** - * @param CollectionFactory $collectionFactory - * @param ProductUrlRewriteGenerator $urlRewriteGenerator - * @param UrlPersistInterface $urlPersist - * @param ProductUrlPathGenerator|null $urlPathGenerator - */ - public function __construct( - CollectionFactory $collectionFactory, - ProductUrlRewriteGenerator $urlRewriteGenerator, - UrlPersistInterface $urlPersist, - ProductUrlPathGenerator $urlPathGenerator - ) { - $this->productCollectionFactory = $collectionFactory; - $this->urlRewriteGenerator = $urlRewriteGenerator; - $this->urlPersist = $urlPersist; - $this->urlPathGenerator = $urlPathGenerator; + public function __construct(AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility) + { + $this->adaptUrlRewritesToVisibility = $adaptUrlRewritesToVisibility; } /** * Generate urls for UrlRewrites and save it in storage * * @param Observer $observer - * @return array + * @return void * @throws UrlAlreadyExistsException */ public function execute(Observer $observer) @@ -73,39 +43,12 @@ public function execute(Observer $observer) $event = $observer->getEvent(); $attrData = $event->getAttributesData(); $productIds = $event->getProductIds(); - $storeId = $event->getStoreId(); - $visibility = $attrData[ProductInterface::VISIBILITY] ?? null; - - if (!$visibility) { - return [$attrData, $productIds, $storeId]; - } - - $productCollection = $this->productCollectionFactory->create(); - $productCollection->addAttributeToSelect(ProductInterface::VISIBILITY); - $productCollection->addAttributeToSelect('url_key'); - $productCollection->addFieldToFilter( - 'entity_id', - ['in' => array_unique($productIds)] - ); + $visibility = $attrData[ProductInterface::VISIBILITY] ?? 0; - foreach ($productCollection as $product) { - if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) { - $this->urlPersist->deleteByData( - [ - UrlRewrite::ENTITY_ID => $product->getId(), - UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, - ] - ); - } elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) { - $product->setVisibility($visibility); - $productUrlPath = $this->urlPathGenerator->getUrlPath($product); - $productUrlRewrite = $this->urlRewriteGenerator->generate($product); - $product->unsUrlPath(); - $product->setUrlPath($productUrlPath); - $this->urlPersist->replace($productUrlRewrite); - } + if (!$visibility || !$productIds) { + return; } - return [$attrData, $productIds, $storeId]; + $this->adaptUrlRewritesToVisibility->execute($productIds, $visibility); } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php new file mode 100644 index 0000000000000..af9979309078f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php @@ -0,0 +1,194 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class); + $this->eventManager = $this->objectManager->create(ManagerInterface::class); + } + + /** + * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_rewrite_multistore.php + * @magentoAppIsolation enabled + */ + public function testMakeProductInvisibleViaMassAction() + { + /** @var \Magento\Catalog\Model\Product $product*/ + $product = $this->productRepository->get('product1'); + + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $storeManager->setCurrentStore(0); + + $testStore = $storeManager->getStore('test'); + $productFilter = [ + UrlRewrite::ENTITY_TYPE => 'product', + ]; + + $expected = [ + [ + 'request_path' => "product-1.html", + 'target_path' => "catalog/product/view/id/" . $product->getId(), + 'is_auto_generated' => 1, + 'redirect_type' => 0, + 'store_id' => '1', + ], + [ + 'request_path' => "product-1.html", + 'target_path' => "catalog/product/view/id/" . $product->getId(), + 'is_auto_generated' => 1, + 'redirect_type' => 0, + 'store_id' => $testStore->getId(), + ] + ]; + + $actual = $this->getActualResults($productFilter); + foreach ($expected as $row) { + $this->assertContains($row, $actual); + } + + $this->eventManager->dispatch( + 'catalog_product_attribute_update_before', + [ + 'attributes_data' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_NOT_VISIBLE ], + 'product_ids' => [$product->getId()] + ] + ); + + $actual = $this->getActualResults($productFilter); + $this->assertCount(0, $actual); + } + + /** + * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_invisible_multistore.php + * @magentoAppIsolation enabled + */ + public function testMakeProductVisibleViaMassAction() + { + /** @var \Magento\Catalog\Model\Product $product*/ + $product = $this->productRepository->get('product1'); + + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $storeManager->setCurrentStore(0); + + $testStore = $storeManager->getStore('test'); + $productFilter = [ + UrlRewrite::ENTITY_TYPE => 'product', + ]; + + $actual = $this->getActualResults($productFilter); + $this->assertCount(0, $actual); + + $this->eventManager->dispatch( + 'catalog_product_attribute_update_before', + [ + 'attributes_data' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH ], + 'product_ids' => [$product->getId()] + ] + ); + + $expected = [ + [ + 'request_path' => "product-1.html", + 'target_path' => "catalog/product/view/id/" . $product->getId(), + 'is_auto_generated' => 1, + 'redirect_type' => 0, + 'store_id' => '1', + ], + [ + 'request_path' => "product-1.html", + 'target_path' => "catalog/product/view/id/" . $product->getId(), + 'is_auto_generated' => 1, + 'redirect_type' => 0, + 'store_id' => $testStore->getId(), + ] + ]; + + $actual = $this->getActualResults($productFilter); + foreach ($expected as $row) { + $this->assertContains($row, $actual); + } + } + + /** + * @magentoDataFixture Magento/CatalogUrlRewrite/_files/products_invisible.php + * @magentoAppIsolation enabled + */ + public function testErrorOnDuplicatedUrlKey() + { + $skus = ['product1', 'product2']; + foreach ($skus as $sku) { + /** @var \Magento\Catalog\Model\Product $product */ + $productIds[] = $this->productRepository->get($sku)->getId(); + } + $this->expectException(UrlAlreadyExistsException::class); + $this->expectExceptionMessage('Can not change the visibility of the product with SKU equals "product2". URL key "product-1" for specified store already exists.'); + + $this->eventManager->dispatch( + 'catalog_product_attribute_update_before', + [ + 'attributes_data' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH ], + 'product_ids' => $productIds + ] + ); + } + + /** + * @param array $filter + * @return array + */ + private function getActualResults(array $filter) + { + /** @var \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder */ + $urlFinder = $this->objectManager->get(\Magento\UrlRewrite\Model\UrlFinderInterface::class); + $actualResults = []; + foreach ($urlFinder->findAllByData($filter) as $url) { + $actualResults[] = [ + 'request_path' => $url->getRequestPath(), + 'target_path' => $url->getTargetPath(), + 'is_auto_generated' => (int)$url->getIsAutogenerated(), + 'redirect_type' => $url->getRedirectType(), + 'store_id' => $url->getStoreId() + ]; + } + return $actualResults; + } +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore.php new file mode 100644 index 0000000000000..d50b29383b1ef --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore.php @@ -0,0 +1,40 @@ +loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE); + +require __DIR__ . '/../../Store/_files/store.php'; + +/** @var $installer CategorySetup */ +$objectManager = Bootstrap::getObjectManager(); +$installer = $objectManager->create(CategorySetup::class); +$storeManager = $objectManager->get(StoreManagerInterface::class); +$storeManager->setCurrentStore(0); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = $objectManager->create(\Magento\Catalog\Model\Product::class); +$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) + ->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default')) + ->setStoreId(0) + ->setWebsiteIds([1]) + ->setName('Product1') + ->setSku('product1') + ->setPrice(10) + ->setWeight(18) + ->setStockData(['use_config_manage_stock' => 0]) + ->setUrlKey('product-1') + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE) + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED); + +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->get(ProductRepositoryInterface::class); +$productRepository->save($product); diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore_rollback.php new file mode 100644 index 0000000000000..bcf399cb5e552 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_invisible_multistore_rollback.php @@ -0,0 +1,33 @@ +getInstance()->reinitialize(); + +/** @var \Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ +$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); +try { + $product = $productRepository->get('product1', true); + if ($product->getId()) { + $productRepository->delete($product); + } +} catch (NoSuchEntityException $e) { +} +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); + +require __DIR__ . '/../../Store/_files/store_rollback.php'; +require __DIR__ . '/../../Store/_files/second_store_rollback.php'; diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible.php new file mode 100644 index 0000000000000..c72d9c8284db3 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible.php @@ -0,0 +1,38 @@ +loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE); + +/** @var $installer CategorySetup */ +$objectManager = Bootstrap::getObjectManager(); +$installer = $objectManager->create(CategorySetup::class); +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->get(ProductRepositoryInterface::class); + +$skus = ['product1', 'product2']; +foreach ($skus as $sku) { + /** @var $product \Magento\Catalog\Model\Product */ + $product = $objectManager->create(\Magento\Catalog\Model\Product::class); + $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) + ->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default')) + ->setStoreId(0) + ->setWebsiteIds([1]) + ->setName('Product1') + ->setSku($sku) + ->setPrice(10) + ->setWeight(18) + ->setStockData(['use_config_manage_stock' => 0]) + ->setUrlKey('product-1') + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE) + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED); + $productRepository->save($product); +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible_rollback.php new file mode 100644 index 0000000000000..d3d17542aa6ab --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/products_invisible_rollback.php @@ -0,0 +1,37 @@ +getInstance()->reinitialize(); + +/** @var \Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ +$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); + +$skus = ['product1', 'product2']; +foreach ($skus as $sku) { + try { + $product = $productRepository->get($sku, true); + if ($product->getId()) { + $productRepository->delete($product); + } + } catch (NoSuchEntityException $e) { + } +} +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); + +require __DIR__ . '/../../Store/_files/store_rollback.php'; +require __DIR__ . '/../../Store/_files/second_store_rollback.php'; From 1c608d7b54bf08d4fe592c2a0153502c9a9527d4 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Thu, 21 Feb 2019 22:08:19 +0200 Subject: [PATCH 16/80] ENGCOM-20434: refactoring, doc blocks adjustments --- .../Products/AdaptUrlRewritesToVisibilityAttribute.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php index 0cadbd0acf0c2..cf1a7ec76f016 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php @@ -61,6 +61,8 @@ public function __construct( } /** + * Process Url Rewrites according to the products visibility attribute + * * @param array $productIds * @param int $visibility * @throws UrlAlreadyExistsException @@ -104,10 +106,12 @@ public function execute(array $productIds, int $visibility): void } /** + * Get Product Models by Id's + * * @param array $productIds * @return array */ - protected function getProductsByIds(array $productIds): array + private function getProductsByIds(array $productIds): array { $productCollection = $this->productCollectionFactory->create(); $productCollection->addAttributeToSelect(ProductInterface::VISIBILITY); From 612a650492e51e17ed5f8974a93dedf4b4e05c32 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Thu, 21 Feb 2019 12:03:19 +0300 Subject: [PATCH 17/80] MAGETWO-57934: [GitHub] Can't use "configurable" as group name in attribute sets M2.1 #6123 --- .../Magento/ConfigurableProduct/etc/di.xml | 7 +++ .../Eav/Model/Entity/Attribute/Group.php | 51 ++++++++++++------- .../Unit/Model/Entity/Attribute/GroupTest.php | 5 +- app/code/Magento/Eav/etc/di.xml | 1 - 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/etc/di.xml b/app/code/Magento/ConfigurableProduct/etc/di.xml index 0ae9ffde66f43..86717e42fa540 100644 --- a/app/code/Magento/ConfigurableProduct/etc/di.xml +++ b/app/code/Magento/ConfigurableProduct/etc/di.xml @@ -245,4 +245,11 @@ + + + + configurable + + + diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Group.php b/app/code/Magento/Eav/Model/Entity/Attribute/Group.php index 0b6ac2b998de7..0d24ea24deaec 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Group.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Group.php @@ -3,11 +3,16 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Eav\Model\Entity\Attribute; +use Magento\Eav\Api\Data\AttributeGroupExtensionInterface; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\Exception\LocalizedException; /** + * Entity attribute group model + * * @api * @method int getSortOrder() * @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value) @@ -27,6 +32,11 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements */ private $translitFilter; + /** + * @var array + */ + private $reservedSystemNames; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -35,7 +45,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements * @param \Magento\Framework\Filter\Translit $translitFilter * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param array $data + * @param array $reservedSystemNames (optional) + * @param array $data (optional) */ public function __construct( \Magento\Framework\Model\Context $context, @@ -45,6 +56,7 @@ public function __construct( \Magento\Framework\Filter\Translit $translitFilter, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + array $reservedSystemNames = [], array $data = [] ) { parent::__construct( @@ -54,8 +66,10 @@ public function __construct( $customAttributeFactory, $resource, $resourceCollection, + $reservedSystemNames, $data ); + $this->reservedSystemNames = $reservedSystemNames; $this->translitFilter = $translitFilter; } @@ -74,6 +88,7 @@ protected function _construct() * Checks if current attribute group exists * * @return bool + * @throws LocalizedException * @codeCoverageIgnore */ public function itemExists() @@ -85,6 +100,7 @@ public function itemExists() * Delete groups * * @return $this + * @throws LocalizedException * @codeCoverageIgnore */ public function deleteGroups() @@ -110,9 +126,10 @@ public function beforeSave() ), '-' ); - if (empty($attributeGroupCode)) { - // in the following code md5 is not used for security purposes - $attributeGroupCode = md5($groupName); + $isReservedSystemName = in_array(strtolower($attributeGroupCode), $this->reservedSystemNames); + if (empty($attributeGroupCode) || $isReservedSystemName) { + // in the following code sha1 is not used for security purposes + $attributeGroupCode = sha1(strtolower($groupName)); } $this->setAttributeGroupCode($attributeGroupCode); } @@ -121,7 +138,8 @@ public function beforeSave() } /** - * {@inheritdoc} + * @inheritdoc + * * @codeCoverageIgnoreStart */ public function getAttributeGroupId() @@ -130,7 +148,7 @@ public function getAttributeGroupId() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAttributeGroupName() { @@ -138,7 +156,7 @@ public function getAttributeGroupName() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAttributeSetId() { @@ -146,7 +164,7 @@ public function getAttributeSetId() } /** - * {@inheritdoc} + * @inheritdoc */ public function setAttributeGroupId($attributeGroupId) { @@ -154,7 +172,7 @@ public function setAttributeGroupId($attributeGroupId) } /** - * {@inheritdoc} + * @inheritdoc */ public function setAttributeGroupName($attributeGroupName) { @@ -162,7 +180,7 @@ public function setAttributeGroupName($attributeGroupName) } /** - * {@inheritdoc} + * @inheritdoc */ public function setAttributeSetId($attributeSetId) { @@ -170,9 +188,9 @@ public function setAttributeSetId($attributeSetId) } /** - * {@inheritdoc} + * @inheritdoc * - * @return \Magento\Eav\Api\Data\AttributeGroupExtensionInterface|null + * @return AttributeGroupExtensionInterface|null */ public function getExtensionAttributes() { @@ -180,14 +198,13 @@ public function getExtensionAttributes() } /** - * {@inheritdoc} + * @inheritdoc * - * @param \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes + * @param AttributeGroupExtensionInterface $extensionAttributes * @return $this */ - public function setExtensionAttributes( - \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes - ) { + public function setExtensionAttributes(AttributeGroupExtensionInterface $extensionAttributes) + { return $this->_setExtensionAttributes($extensionAttributes); } diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php index d4c91e98d9608..986ab517ceca1 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php @@ -40,6 +40,7 @@ protected function setUp() 'resource' => $this->resourceMock, 'translitFilter' => $translitFilter, 'context' => $contextMock, + 'reservedSystemNames' => ['configurable'], ]; $objectManager = new ObjectManager($this); $this->model = $objectManager->getObject( @@ -67,7 +68,9 @@ public function attributeGroupCodeDataProvider() { return [ ['General Group', 'general-group'], - ['///', md5('///')], + ['configurable', sha1('configurable')], + ['configurAble', sha1('configurable')], + ['///', sha1('///')], ]; } } diff --git a/app/code/Magento/Eav/etc/di.xml b/app/code/Magento/Eav/etc/di.xml index a4c89dcfab2af..db6f9b0a64f9f 100644 --- a/app/code/Magento/Eav/etc/di.xml +++ b/app/code/Magento/Eav/etc/di.xml @@ -210,4 +210,3 @@ - From d04482cbeb43abc70a8ddbed12096097a235b986 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 25 Feb 2019 11:25:14 +0300 Subject: [PATCH 18/80] MAGETWO-57934: [GitHub] Can't use "configurable" as group name in attribute sets M2.1 #6123 --- app/code/Magento/Eav/Model/Entity/Attribute/Group.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Group.php b/app/code/Magento/Eav/Model/Entity/Attribute/Group.php index 0d24ea24deaec..1f718f4277cc5 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Group.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Group.php @@ -45,8 +45,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements * @param \Magento\Framework\Filter\Translit $translitFilter * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param array $reservedSystemNames (optional) * @param array $data (optional) + * @param array $reservedSystemNames (optional) */ public function __construct( \Magento\Framework\Model\Context $context, @@ -56,8 +56,8 @@ public function __construct( \Magento\Framework\Filter\Translit $translitFilter, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $reservedSystemNames = [], - array $data = [] + array $data = [], + array $reservedSystemNames = [] ) { parent::__construct( $context, @@ -66,7 +66,6 @@ public function __construct( $customAttributeFactory, $resource, $resourceCollection, - $reservedSystemNames, $data ); $this->reservedSystemNames = $reservedSystemNames; From 27a01c038f098ab336e779432ecf53421d5562f2 Mon Sep 17 00:00:00 2001 From: vprohorov Date: Tue, 5 Mar 2019 01:07:53 +0300 Subject: [PATCH 19/80] MAGETWO-62728: My Wishlist - quantity input box issue - Fixed js validation --- .../view/frontend/web/js/add-to-wishlist.js | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js index 7a166b47256cb..b38c5c2cda3ad 100644 --- a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js +++ b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js @@ -63,6 +63,12 @@ define([ isFileUploaded = false, self = this; + if (event.handleObj.selector == this.options.qtyInfo) { //eslint-disable-line eqeqeq + this._updateAddToWishlistButton({}); + event.stopPropagation(); + + return; + } $(event.handleObj.selector).each(function (index, element) { if ($(element).is('input[type=text]') || $(element).is('input[type=email]') || @@ -83,7 +89,9 @@ define([ } }); - this.bindFormSubmit(isFileUploaded); + if (isFileUploaded) { + this.bindFormSubmit(); + } this._updateAddToWishlistButton(dataToAdd); event.stopPropagation(); }, @@ -181,45 +189,34 @@ define([ /** * Bind form submit. - * - * @param {Boolean} isFileUploaded */ - bindFormSubmit: function (isFileUploaded) { + bindFormSubmit: function () { var self = this; $('[data-action="add-to-wishlist"]').on('click', function (event) { var element, params, form, action; - if (!$($(self.options.qtyInfo).closest('form')).valid()) { - event.stopPropagation(); - event.preventDefault(); - - return; - } - - if (isFileUploaded) { - - element = $('input[type=file]' + self.options.customOptionsInfo); - params = $(event.currentTarget).data('post'); - form = $(element).closest('form'); - action = params.action; + event.stopPropagation(); + event.preventDefault(); - if (params.data.id) { - $('', { - type: 'hidden', - name: 'id', - value: params.data.id - }).appendTo(form); - } + element = $('input[type=file]' + self.options.customOptionsInfo); + params = $(event.currentTarget).data('post'); + form = $(element).closest('form'); + action = params.action; - if (params.data.uenc) { - action += 'uenc/' + params.data.uenc; - } + if (params.data.id) { + $('', { + type: 'hidden', + name: 'id', + value: params.data.id + }).appendTo(form); + } - $(form).attr('action', action).submit(); - event.stopPropagation(); - event.preventDefault(); + if (params.data.uenc) { + action += 'uenc/' + params.data.uenc; } + + $(form).attr('action', action).submit(); }); } }); From f893a925bbf5a92967a79509beefa4314b897f23 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 5 Mar 2019 17:32:16 +0200 Subject: [PATCH 20/80] ENGCOM-4302: Static test fix. --- .../Reports/Model/ResourceModel/Order/Collection.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php index 19549f7181aa9..33dfdcffc9a48 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php @@ -830,7 +830,13 @@ protected function getTotalsExpression( ? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))' : '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) ' . ' * main_table.base_to_global_rate)'; - return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountRefunded, $baseDiscountCanceled); + return sprintf( + $template, + $baseSubtotalRefunded, + $baseSubtotalCanceled, + $baseDiscountRefunded, + $baseDiscountCanceled + ); } /** From a80943f529a337b36f59d3964a8448816f5e2532 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 6 Mar 2019 10:18:36 +0200 Subject: [PATCH 21/80] ENGCOM-20434: fixed type inconsistency --- .../ProcessUrlRewriteOnChangeProductVisibilityObserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php index 56393c619f4ef..2337bb3646bd7 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php @@ -49,6 +49,6 @@ public function execute(Observer $observer) return; } - $this->adaptUrlRewritesToVisibility->execute($productIds, $visibility); + $this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility); } } From 51cf5897005ebb77d73ca088ce5c2e5fc53ca963 Mon Sep 17 00:00:00 2001 From: Stsiapan Korf Date: Wed, 6 Mar 2019 15:58:17 +0000 Subject: [PATCH 22/80] MAGETWO-53037: Product duplication allows to save non-unique values for product attributes - Add message for unique value --- .../Controller/Adminhtml/Product/Save.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php index e84d9ff12906e..825d0ee032d6c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php @@ -159,6 +159,7 @@ public function execute() if ($redirectBack === 'duplicate') { $product->unsetData('quantity_and_stock_status'); $newProduct = $this->productCopier->copy($product); + $this->checkUniqueAttributes($product); $this->messageManager->addSuccessMessage(__('You duplicated the product.')); } } catch (\Magento\Framework\Exception\LocalizedException $e) { @@ -343,4 +344,25 @@ private function persistMediaData(ProductInterface $product, array $data) return $data; } + + /** + * Check unique attributes and add error to message manager + * + * @param \Magento\Catalog\Model\Product $product + */ + private function checkUniqueAttributes(\Magento\Catalog\Model\Product $product) + { + $uniqueLabels = []; + foreach ($product->getAttributes() as $attribute) { + if ($attribute->getIsUnique() && $attribute->getIsUserDefined() + && $product->getData($attribute->getAttributeCode()) !== null + ) { + $uniqueLabels[] = $attribute->getDefaultFrontendLabel(); + } + } + if ($uniqueLabels) { + $uniqueLabels = implode('", "', $uniqueLabels); + $this->messageManager->addErrorMessage(__('The value of attribute(s) "%1" must be unique', $uniqueLabels)); + } + } } From 5e4adb83c6ad5f1cfd41551cf3d55a4ffc22bb18 Mon Sep 17 00:00:00 2001 From: AleksLi Date: Thu, 7 Mar 2019 00:28:00 +0100 Subject: [PATCH 23/80] GraphQL-432: Created separate class GetMaskedQuoteIdByReversedQuoteId and replaced method in one api-functional test --- .../GetMaskedQuoteIdByReversedQuoteId.php | 58 +++++++++++++++++++ .../Quote/SetShippingAddressOnCartTest.php | 30 +++++----- 2 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php diff --git a/app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php b/app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php new file mode 100644 index 0000000000000..60466170fc562 --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php @@ -0,0 +1,58 @@ +quoteFactory = $quoteFactory; + $this->quoteResource = $quoteResource; + $this->quoteIdToMaskedId = $quoteIdToMaskedId; + } + + /** + * @param string $reversedQuoteId + * @return string + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function execute(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php index 4916bb2aa78c3..9352111de8543 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php @@ -13,6 +13,7 @@ use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; use Magento\TestFramework\ObjectManager; @@ -37,6 +38,11 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract */ private $quoteIdToMaskedId; + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var CustomerTokenServiceInterface */ @@ -47,16 +53,20 @@ protected function setUp() $objectManager = Bootstrap::getObjectManager(); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetNewShippingAddressByGuest() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $reversedQuoteId * @param int $customerId From ae9084de11bf2a59d2540d2ba6769b9ef1d46b8d Mon Sep 17 00:00:00 2001 From: vgelani Date: Thu, 7 Mar 2019 17:18:28 +0530 Subject: [PATCH 24/80] Updated review text in admin menu --- app/code/Magento/Review/etc/acl.xml | 4 ++-- app/code/Magento/Review/etc/adminhtml/menu.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Review/etc/acl.xml b/app/code/Magento/Review/etc/acl.xml index 09b80750da14d..6932f2535090c 100644 --- a/app/code/Magento/Review/etc/acl.xml +++ b/app/code/Magento/Review/etc/acl.xml @@ -16,8 +16,8 @@ - - + + diff --git a/app/code/Magento/Review/etc/adminhtml/menu.xml b/app/code/Magento/Review/etc/adminhtml/menu.xml index 0a2e49450e0cf..72499b416cd17 100644 --- a/app/code/Magento/Review/etc/adminhtml/menu.xml +++ b/app/code/Magento/Review/etc/adminhtml/menu.xml @@ -8,8 +8,8 @@ - - + + From 63a25905793915ab720a5620a94141e4c4bd8997 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Fri, 8 Mar 2019 11:44:06 -0600 Subject: [PATCH 25/80] MAGETWO-97830: Elasticsearch date field crash quicksearch --- .../Product/FieldProvider/DynamicField.php | 2 +- .../Aggregation/Builder/Term.php | 4 +- .../SearchAdapter/Query/Builder/Match.php | 67 ++++++++-- .../ValueTransformer/DateTransformer.php | 44 +++++++ .../ValueTransformer/FloatTransformer.php | 24 ++++ .../ValueTransformer/IntegerTransformer.php | 24 ++++ .../ValueTransformer/TextTransformer.php | 65 ++++++++++ .../Query/ValueTransformerInterface.php | 22 ++++ .../Query/ValueTransformerPool.php | 46 +++++++ .../SearchAdapter/Query/Builder/MatchTest.php | 117 ++++++++++-------- app/code/Magento/Elasticsearch/etc/di.xml | 18 +++ .../Model/ResourceModel/SynonymReader.php | 14 ++- ...hp => product_text_attribute_rollback.php} | 6 +- .../_files/product_export_data_rollback.php | 8 +- ...uct_export_data_special_chars_rollback.php | 8 +- .../SearchAdapter/AdapterTest.php | 14 +++ .../Search/_files/filterable_attributes.php | 33 ++++- .../_files/filterable_attributes_rollback.php | 12 +- .../Search/Model/SynonymReaderTest.php | 17 ++- 19 files changed, 465 insertions(+), 80 deletions(-) create mode 100644 app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/DateTransformer.php create mode 100644 app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/FloatTransformer.php create mode 100644 app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/IntegerTransformer.php create mode 100644 app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/TextTransformer.php create mode 100644 app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformerInterface.php create mode 100644 app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformerPool.php rename dev/tests/integration/testsuite/Magento/Catalog/_files/{text_attribute_rollback.php => product_text_attribute_rollback.php} (84%) diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php index 181cbd4dfd4b3..7fa460fbb3968 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php @@ -140,7 +140,7 @@ public function getFields(array $context = []): array foreach ($groups as $group) { $groupPriceKey = $this->fieldNameResolver->getFieldName( $priceAttribute, - ['customerGroupId' => $group->getId(), 'websiteId' => $context['websiteId']] + array_merge($context, ['customerGroupId' => $group->getId()]) ); $allAttributes[$groupPriceKey] = [ 'type' => $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_FLOAT), diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Term.php b/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Term.php index 0c03a9df18dc8..eeb48f805bccf 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Term.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Term.php @@ -22,13 +22,15 @@ public function build( array $queryResult, DataProviderInterface $dataProvider ) { + $buckets = $queryResult['aggregations'][$bucket->getName()]['buckets'] ?? []; $values = []; - foreach ($queryResult['aggregations'][$bucket->getName()]['buckets'] as $resultBucket) { + foreach ($buckets as $resultBucket) { $values[$resultBucket['key']] = [ 'value' => $resultBucket['key'], 'count' => $resultBucket['doc_count'], ]; } + return $values; } } diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php index aaa9d8a88382f..64a82e131aad6 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php @@ -5,6 +5,11 @@ */ namespace Magento\Elasticsearch\SearchAdapter\Query\Builder; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface + as FieldTypeResolver; +use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Search\Request\Query\BoolExpression; use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; @@ -26,20 +31,49 @@ class Match implements QueryInterface private $fieldMapper; /** + * @deprecated + * @see \Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer * @var PreprocessorInterface[] */ protected $preprocessorContainer; + /** + * @var AttributeProvider + */ + private $attributeProvider; + + /** + * @var FieldTypeResolver + */ + private $fieldTypeResolver; + + /** + * @var ValueTransformerPool + */ + private $valueTransformerPool; + /** * @param FieldMapperInterface $fieldMapper * @param PreprocessorInterface[] $preprocessorContainer + * @param AttributeProvider|null $attributeProvider + * @param FieldTypeResolver|null $fieldTypeResolver + * @param ValueTransformerPool|null $valueTransformerPool */ public function __construct( FieldMapperInterface $fieldMapper, - array $preprocessorContainer + array $preprocessorContainer, + AttributeProvider $attributeProvider = null, + FieldTypeResolver $fieldTypeResolver = null, + ValueTransformerPool $valueTransformerPool = null ) { $this->fieldMapper = $fieldMapper; $this->preprocessorContainer = $preprocessorContainer; + $this->attributeProvider = $attributeProvider ?? ObjectManager::getInstance() + ->get(AttributeProvider::class); + $this->fieldTypeResolver = $fieldTypeResolver ?? ObjectManager::getInstance() + ->get(FieldTypeResolver::class); + $this->valueTransformerPool = $valueTransformerPool ?? ObjectManager::getInstance() + ->get(ValueTransformerPool::class); } /** @@ -72,10 +106,6 @@ public function build(array $selectQuery, RequestQueryInterface $requestQuery, $ */ protected function prepareQuery($queryValue, $conditionType) { - $queryValue = $this->escape($queryValue); - foreach ($this->preprocessorContainer as $preprocessor) { - $queryValue = $preprocessor->process($queryValue); - } $condition = $conditionType === BoolExpression::QUERY_CONDITION_NOT ? self::QUERY_CONDITION_MUST_NOT : $conditionType; return [ @@ -104,10 +134,24 @@ protected function buildQueries(array $matches, array $queryValue) // Checking for quoted phrase \"phrase test\", trim escaped surrounding quotes if found $count = 0; - $value = preg_replace('#^\\\\"(.*)\\\\"$#m', '$1', $queryValue['value'], -1, $count); + $value = preg_replace('#^"(.*)"$#m', '$1', $queryValue['value'], -1, $count); $condition = ($count) ? 'match_phrase' : 'match'; + $transformedTypes = []; foreach ($matches as $match) { + $attributeAdapter = $this->attributeProvider->getByAttributeCode($match['field']); + $fieldType = $this->fieldTypeResolver->getFieldType($attributeAdapter); + $valueTransformer = $this->valueTransformerPool->get($fieldType ?? 'text'); + $valueTransformerHash = \spl_object_hash($valueTransformer); + if (!isset($transformedTypes[$valueTransformerHash])) { + $transformedTypes[$valueTransformerHash] = $valueTransformer->transform($value); + } + $transformedValue = $transformedTypes[$valueTransformerHash]; + if (null === $transformedValue) { + //Value is incompatible with this field type. + continue; + } + $resolvedField = $this->fieldMapper->getFieldName( $match['field'], ['type' => FieldMapperInterface::TYPE_QUERY] @@ -117,8 +161,8 @@ protected function buildQueries(array $matches, array $queryValue) 'body' => [ $condition => [ $resolvedField => [ - 'query' => $value, - 'boost' => isset($match['boost']) ? $match['boost'] : 1, + 'query' => $transformedValue, + 'boost' => $match['boost'] ?? 1, ], ], ], @@ -131,16 +175,13 @@ protected function buildQueries(array $matches, array $queryValue) /** * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc. * - * Cut trailing plus or minus sign, and @ symbol, using of which causes InnoDB to report a syntax error. - * https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Fulltext-boolean search docs. - * + * @deprecated + * @see \Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer * @param string $value * @return string */ protected function escape($value) { - $value = preg_replace('/@+|[@+-]+$/', '', $value); - $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/'; $replace = '\\\$1'; diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/DateTransformer.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/DateTransformer.php new file mode 100644 index 0000000000000..49eca6e9d82a6 --- /dev/null +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/DateTransformer.php @@ -0,0 +1,44 @@ +dateFieldType = $dateFieldType; + } + + /** + * @inheritdoc + */ + public function transform(string $value): ?string + { + try { + $formattedDate = $this->dateFieldType->formatDate(null, $value); + } catch (\Exception $e) { + $formattedDate = null; + } + + return $formattedDate; + } +} diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/FloatTransformer.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/FloatTransformer.php new file mode 100644 index 0000000000000..5e330076d3df7 --- /dev/null +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/FloatTransformer.php @@ -0,0 +1,24 @@ +preprocessors = $preprocessors; + } + + /** + * @inheritdoc + */ + public function transform(string $value): string + { + $value = $this->escape($value); + foreach ($this->preprocessors as $preprocessor) { + $value = $preprocessor->process($value); + } + + return $value; + } + + /** + * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc. + * + * @param string $value + * @return string + */ + private function escape(string $value): string + { + $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/'; + $replace = '\\\$1'; + + return preg_replace($pattern, $replace, $value); + } +} diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformerInterface.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformerInterface.php new file mode 100644 index 0000000000000..c84ddc69cc7a8 --- /dev/null +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformerInterface.php @@ -0,0 +1,22 @@ +transformers = $valueTransformers; + } + + /** + * Get value transformer related to field type. + * + * @param string $fieldType + * @return ValueTransformerInterface + */ + public function get(string $fieldType): ValueTransformerInterface + { + return $this->transformers[$fieldType] ?? $this->transformers['default']; + } +} diff --git a/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php b/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php index 8114feb09d35d..f3e2b0e9e0fa9 100644 --- a/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php +++ b/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php @@ -5,14 +5,30 @@ */ namespace Magento\Elasticsearch\Test\Unit\SearchAdapter\Query\Builder; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface + as FieldTypeResolver; use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; use Magento\Elasticsearch\SearchAdapter\Query\Builder\Match as MatchQueryBuilder; +use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerInterface; +use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool; use Magento\Framework\Search\Request\Query\Match as MatchRequestQuery; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use PHPUnit_Framework_MockObject_MockObject as MockObject; +use PHPUnit\Framework\MockObject\MockObject as MockObject; class MatchTest extends \PHPUnit\Framework\TestCase { + /** + * @var AttributeProvider|MockObject + */ + private $attributeProvider; + + /** + * @var FieldTypeResolver|MockObject + */ + private $fieldTypeResolver; + /** * @var MatchQueryBuilder */ @@ -23,46 +39,63 @@ class MatchTest extends \PHPUnit\Framework\TestCase */ protected function setUp() { + $this->attributeProvider = $this->createMock(AttributeProvider::class); + $this->fieldTypeResolver = $this->createMock(FieldTypeResolver::class); + + $valueTransformerPoolMock = $this->createMock(ValueTransformerPool::class); + $valueTransformerMock = $this->createMock(ValueTransformerInterface::class); + $valueTransformerPoolMock->method('get') + ->willReturn($valueTransformerMock); + $valueTransformerMock->method('transform') + ->willReturnArgument(0); + $this->matchQueryBuilder = (new ObjectManager($this))->getObject( MatchQueryBuilder::class, [ 'fieldMapper' => $this->getFieldMapper(), 'preprocessorContainer' => [], + 'attributeProvider' => $this->attributeProvider, + 'fieldTypeResolver' => $this->fieldTypeResolver, + 'valueTransformerPool' => $valueTransformerPoolMock, ] ); } /** * Tests that method constructs a correct select query. - * @see MatchQueryBuilder::build - * - * @dataProvider queryValuesInvariantsProvider * - * @param string $rawQueryValue - * @param string $errorMessage + * @see MatchQueryBuilder::build */ - public function testBuild($rawQueryValue, $errorMessage) + public function testBuild() { - $this->assertSelectQuery( - $this->matchQueryBuilder->build([], $this->getMatchRequestQuery($rawQueryValue), 'not'), - $errorMessage - ); - } + $attributeAdapter = $this->createMock(AttributeAdapter::class); + $this->attributeProvider->expects($this->once()) + ->method('getByAttributeCode') + ->with('some_field') + ->willReturn($attributeAdapter); + $this->fieldTypeResolver->expects($this->once()) + ->method('getFieldType') + ->with($attributeAdapter) + ->willReturn('text'); + + $rawQueryValue = 'query_value'; + $selectQuery = $this->matchQueryBuilder->build([], $this->getMatchRequestQuery($rawQueryValue), 'not'); - /** - * @link https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Fulltext-boolean search docs. - * - * @return array - */ - public function queryValuesInvariantsProvider() - { - return [ - ['query_value', 'Select query field must match simple raw query value.'], - ['query_value+', 'Specifying a trailing plus sign causes InnoDB to report a syntax error.'], - ['query_value-', 'Specifying a trailing minus sign causes InnoDB to report a syntax error.'], - ['query_@value', 'The @ symbol is reserved for use by the @distance proximity search operator.'], - ['query_value+@', 'The @ symbol is reserved for use by the @distance proximity search operator.'], + $expectedSelectQuery = [ + 'bool' => [ + 'must_not' => [ + [ + 'match' => [ + 'some_field' => [ + 'query' => $rawQueryValue, + 'boost' => 43, + ], + ], + ], + ], + ], ]; + $this->assertEquals($expectedSelectQuery, $selectQuery); } /** @@ -76,6 +109,16 @@ public function queryValuesInvariantsProvider() */ public function testBuildMatchQuery($rawQueryValue, $queryValue, $match) { + $attributeAdapter = $this->createMock(AttributeAdapter::class); + $this->attributeProvider->expects($this->once()) + ->method('getByAttributeCode') + ->with('some_field') + ->willReturn($attributeAdapter); + $this->fieldTypeResolver->expects($this->once()) + ->method('getFieldType') + ->with($attributeAdapter) + ->willReturn('text'); + $query = $this->matchQueryBuilder->build([], $this->getMatchRequestQuery($rawQueryValue), 'should'); $expectedSelectQuery = [ @@ -111,30 +154,6 @@ public function matchProvider() ]; } - /** - * @param array $selectQuery - * @param string $errorMessage - */ - private function assertSelectQuery($selectQuery, $errorMessage) - { - $expectedSelectQuery = [ - 'bool' => [ - 'must_not' => [ - [ - 'match' => [ - 'some_field' => [ - 'query' => 'query_value', - 'boost' => 43, - ], - ], - ], - ], - ], - ]; - - $this->assertEquals($expectedSelectQuery, $selectQuery, $errorMessage); - } - /** * Gets fieldMapper mock object. * diff --git a/app/code/Magento/Elasticsearch/etc/di.xml b/app/code/Magento/Elasticsearch/etc/di.xml index 9796dc93858f1..83dfd17a61d8b 100644 --- a/app/code/Magento/Elasticsearch/etc/di.xml +++ b/app/code/Magento/Elasticsearch/etc/di.xml @@ -532,4 +532,22 @@ + + + + Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer + Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\DateTransformer + Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\FloatTransformer + Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\IntegerTransformer + + + + + + + Magento\Elasticsearch\SearchAdapter\Query\Preprocessor\Stopwords + Magento\Search\Adapter\Query\Preprocessor\Synonyms + + + diff --git a/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php b/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php index 46e794a1954cf..45eee0a4001d1 100644 --- a/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php +++ b/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php @@ -87,7 +87,7 @@ private function queryByPhrase($phrase) { $matchQuery = $this->fullTextSelect->getMatchQuery( ['synonyms' => 'synonyms'], - $phrase, + $this->escapePhrase($phrase), Fulltext::FULLTEXT_MODE_BOOLEAN ); $query = $this->getConnection()->select()->from( @@ -97,6 +97,18 @@ private function queryByPhrase($phrase) return $this->getConnection()->fetchAll($query); } + /** + * Cut trailing plus or minus sign, and @ symbol, using of which causes InnoDB to report a syntax error. + * + * @see https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html + * @param string $phrase + * @return string + */ + private function escapePhrase(string $phrase): string + { + return preg_replace('/@+|[@+-]+$/', '', $phrase); + } + /** * A private helper function to retrieve matching synonym groups per scope * diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/text_attribute_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_text_attribute_rollback.php similarity index 84% rename from dev/tests/integration/testsuite/Magento/Catalog/_files/text_attribute_rollback.php rename to dev/tests/integration/testsuite/Magento/Catalog/_files/product_text_attribute_rollback.php index cbc0476efd1b5..a9ab0e11312b2 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/text_attribute_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_text_attribute_rollback.php @@ -3,13 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + /* Delete attribute with text_attribute code */ -$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); + /** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */ $attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Catalog\Model\ResourceModel\Eav\Attribute' + \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class ); $attribute->load('text_attribute', 'attribute_code'); $attribute->delete(); diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_rollback.php index 168073bc6ab74..c57c7c3fd6a92 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_rollback.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_rollback.php @@ -5,10 +5,10 @@ */ /** Delete all products */ -require dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute_rollback.php'; +include dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute_rollback.php'; /** Delete text attribute */ -require dirname(dirname(__DIR__)) . '/Catalog/_files/text_attribute_rollback.php'; +include dirname(dirname(__DIR__)) . '/Catalog/_files/product_text_attribute_rollback.php'; -require dirname(dirname(__DIR__)) . '/Store/_files/second_store_rollback.php'; +include dirname(dirname(__DIR__)) . '/Store/_files/second_store_rollback.php'; -require dirname(dirname(__DIR__)) . '/Catalog/_files/category_rollback.php'; +include dirname(dirname(__DIR__)) . '/Catalog/_files/category_rollback.php'; diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_special_chars_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_special_chars_rollback.php index 168073bc6ab74..c57c7c3fd6a92 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_special_chars_rollback.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data_special_chars_rollback.php @@ -5,10 +5,10 @@ */ /** Delete all products */ -require dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute_rollback.php'; +include dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute_rollback.php'; /** Delete text attribute */ -require dirname(dirname(__DIR__)) . '/Catalog/_files/text_attribute_rollback.php'; +include dirname(dirname(__DIR__)) . '/Catalog/_files/product_text_attribute_rollback.php'; -require dirname(dirname(__DIR__)) . '/Store/_files/second_store_rollback.php'; +include dirname(dirname(__DIR__)) . '/Store/_files/second_store_rollback.php'; -require dirname(dirname(__DIR__)) . '/Catalog/_files/category_rollback.php'; +include dirname(dirname(__DIR__)) . '/Catalog/_files/category_rollback.php'; diff --git a/dev/tests/integration/testsuite/Magento/Elasticsearch/SearchAdapter/AdapterTest.php b/dev/tests/integration/testsuite/Magento/Elasticsearch/SearchAdapter/AdapterTest.php index dc288a18fadb7..8d80fd8533d6f 100644 --- a/dev/tests/integration/testsuite/Magento/Elasticsearch/SearchAdapter/AdapterTest.php +++ b/dev/tests/integration/testsuite/Magento/Elasticsearch/SearchAdapter/AdapterTest.php @@ -369,4 +369,18 @@ public function dateDataProvider() [['from' => '2000-02-01T00:00:00Z', 'to' => ''], 0], ]; } + + public function filterByAttributeValuesDataProvider() + { + $variations = parent::filterByAttributeValuesDataProvider(); + + $variations['quick search by date'] = [ + 'quick_search_container', + [ + 'search_term' => '2000-10-30', + ], + ]; + + return $variations; + } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes.php b/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes.php index b09af48b5f943..f4f3337a253c0 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes.php @@ -20,6 +20,10 @@ CategorySetup::class, ['resourceName' => 'catalog_setup'] ); +$productEntityTypeId = $installer->getEntityTypeId( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE +); + $selectOptions = []; $selectAttributes = []; foreach (range(1, 2) as $index) { @@ -30,7 +34,7 @@ $selectAttribute->setData( [ 'attribute_code' => 'select_attribute_' . $index, - 'entity_type_id' => $installer->getEntityTypeId('catalog_product'), + 'entity_type_id' => $productEntityTypeId, 'is_global' => 1, 'is_user_defined' => 1, 'frontend_input' => 'select', @@ -56,7 +60,8 @@ ); $selectAttribute->save(); /* Assign attribute to attribute set */ - $installer->addAttributeToGroup('catalog_product', 'Default', 'General', $selectAttribute->getId()); + $installer->addAttributeToGroup($productEntityTypeId, 'Default', 'General', $selectAttribute->getId()); + /** @var $selectOptions Collection */ $selectOption = Bootstrap::getObjectManager()->create( Collection::class @@ -65,6 +70,26 @@ $selectAttributes[$index] = $selectAttribute; $selectOptions[$index] = $selectOption; } + +$dateAttribute = Bootstrap::getObjectManager()->create(Attribute::class); +$dateAttribute->setData( + [ + 'attribute_code' => 'date_attribute', + 'entity_type_id' => $productEntityTypeId, + 'is_global' => 1, + 'is_filterable' => 1, + 'backend_type' => 'datetime', + 'frontend_input' => 'date', + 'frontend_label' => 'Test Date', + 'is_searchable' => 1, + 'is_filterable_in_search' => 1, + ] +); +$dateAttribute->save(); +/* Assign attribute to attribute set */ +$installer->addAttributeToGroup($productEntityTypeId, 'Default', 'General', $dateAttribute->getId()); + +$productAttributeSetId = $installer->getAttributeSetId($productEntityTypeId, 'Default'); /* Create simple products per each first attribute option */ foreach ($selectOptions[1] as $option) { /** @var $product Product */ @@ -74,7 +99,7 @@ $product->setTypeId( Type::TYPE_SIMPLE )->setAttributeSetId( - $installer->getAttributeSetId('catalog_product', 'Default') + $productAttributeSetId )->setWebsiteIds( [1] )->setName( @@ -92,6 +117,7 @@ )->setStockData( ['use_config_manage_stock' => 1, 'qty' => 5, 'is_in_stock' => 1] )->save(); + Bootstrap::getObjectManager()->get( Action::class )->updateAttributes( @@ -99,6 +125,7 @@ [ $selectAttributes[1]->getAttributeCode() => $option->getId(), $selectAttributes[2]->getAttributeCode() => $selectOptions[2]->getLastItem()->getId(), + $dateAttribute->getAttributeCode() => '10/30/2000', ], $product->getStoreId() ); diff --git a/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes_rollback.php b/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes_rollback.php index 18a5372d06d98..fd413726b2637 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Search/_files/filterable_attributes_rollback.php @@ -13,6 +13,7 @@ $registry = Bootstrap::getObjectManager()->get(Registry::class); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); + /** @var $productCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */ $productCollection = Bootstrap::getObjectManager() ->create(Product::class) @@ -20,17 +21,26 @@ foreach ($productCollection as $product) { $product->delete(); } + /** @var $attribute Attribute */ $attribute = Bootstrap::getObjectManager()->create( Attribute::class ); /** @var $installer CategorySetup */ $installer = Bootstrap::getObjectManager()->create(CategorySetup::class); +$productEntityTypeId = $installer->getEntityTypeId( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE +); foreach (range(1, 2) as $index) { - $attribute->loadByCode($installer->getEntityTypeId('catalog_product'), 'select_attribute_' . $index); + $attribute->loadByCode($productEntityTypeId, 'select_attribute_' . $index); if ($attribute->getId()) { $attribute->delete(); } } +$attribute->loadByCode($productEntityTypeId, 'date_attribute'); +if ($attribute->getId()) { + $attribute->delete(); +} + $registry->unregister('isSecureArea'); $registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Search/Model/SynonymReaderTest.php b/dev/tests/integration/testsuite/Magento/Search/Model/SynonymReaderTest.php index b9ba89ba53144..2d0020ba22680 100644 --- a/dev/tests/integration/testsuite/Magento/Search/Model/SynonymReaderTest.php +++ b/dev/tests/integration/testsuite/Magento/Search/Model/SynonymReaderTest.php @@ -48,7 +48,22 @@ public static function loadByPhraseDataProvider() ['synonyms' => 'queen,monarch', 'store_id' => 1, 'website_id' => 0], ['synonyms' => 'british,english', 'store_id' => 1, 'website_id' => 0] ] - ] + ], + [ + 'query_value', [] + ], + [ + 'query_value+', [] + ], + [ + 'query_value-', [] + ], + [ + 'query_@value', [] + ], + [ + 'query_value+@', [] + ], ]; } From 9f93a5e01785ce3ab143e561ff9204609e430c6d Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Fri, 8 Mar 2019 15:49:44 -0600 Subject: [PATCH 26/80] MAGETWO-97830: Elasticsearch date field crash quicksearch --- .../SearchAdapter/Query/Builder/Match.php | 11 +++++------ .../Unit/SearchAdapter/Query/Builder/MatchTest.php | 7 +++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php index 64a82e131aad6..afd383c13421f 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php @@ -6,8 +6,7 @@ namespace Magento\Elasticsearch\SearchAdapter\Query\Builder; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface - as FieldTypeResolver; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface as TypeResolver; use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool; use Magento\Framework\App\ObjectManager; use Magento\Framework\Search\Request\Query\BoolExpression; @@ -43,7 +42,7 @@ class Match implements QueryInterface private $attributeProvider; /** - * @var FieldTypeResolver + * @var TypeResolver */ private $fieldTypeResolver; @@ -56,14 +55,14 @@ class Match implements QueryInterface * @param FieldMapperInterface $fieldMapper * @param PreprocessorInterface[] $preprocessorContainer * @param AttributeProvider|null $attributeProvider - * @param FieldTypeResolver|null $fieldTypeResolver + * @param TypeResolver|null $fieldTypeResolver * @param ValueTransformerPool|null $valueTransformerPool */ public function __construct( FieldMapperInterface $fieldMapper, array $preprocessorContainer, AttributeProvider $attributeProvider = null, - FieldTypeResolver $fieldTypeResolver = null, + TypeResolver $fieldTypeResolver = null, ValueTransformerPool $valueTransformerPool = null ) { $this->fieldMapper = $fieldMapper; @@ -71,7 +70,7 @@ public function __construct( $this->attributeProvider = $attributeProvider ?? ObjectManager::getInstance() ->get(AttributeProvider::class); $this->fieldTypeResolver = $fieldTypeResolver ?? ObjectManager::getInstance() - ->get(FieldTypeResolver::class); + ->get(TypeResolver::class); $this->valueTransformerPool = $valueTransformerPool ?? ObjectManager::getInstance() ->get(ValueTransformerPool::class); } diff --git a/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php b/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php index f3e2b0e9e0fa9..d0ffc6debcd8a 100644 --- a/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php +++ b/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/MatchTest.php @@ -7,8 +7,7 @@ use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface - as FieldTypeResolver; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface as TypeResolver; use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; use Magento\Elasticsearch\SearchAdapter\Query\Builder\Match as MatchQueryBuilder; use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerInterface; @@ -25,7 +24,7 @@ class MatchTest extends \PHPUnit\Framework\TestCase private $attributeProvider; /** - * @var FieldTypeResolver|MockObject + * @var TypeResolver|MockObject */ private $fieldTypeResolver; @@ -40,7 +39,7 @@ class MatchTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->attributeProvider = $this->createMock(AttributeProvider::class); - $this->fieldTypeResolver = $this->createMock(FieldTypeResolver::class); + $this->fieldTypeResolver = $this->createMock(TypeResolver::class); $valueTransformerPoolMock = $this->createMock(ValueTransformerPool::class); $valueTransformerMock = $this->createMock(ValueTransformerInterface::class); From 04f60d5d27f661b2a33c1f6db2ef511ab5ff3c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20F=C3=BChr?= Date: Fri, 8 Mar 2019 23:20:21 +0100 Subject: [PATCH 27/80] 18752: make root cause visible for exception on submitQuote Github Issue: https://github.com/magento/magento2/issues/18752 If an exceptions happens in orderManagement->place($order) or an "sales_model_service_quote_submit_success" observer, the catch block itself fires an event that currently fails for guest checkouts in Magento\CatalogInventory\Model\ResourceModel\Stock->correctItemsQty(). This second exception hides the root exception and is logged to the exception log with the message "Rolled back transaction has not been completed correctly". This is not bound for this observer, but may occur in every other observer that is currently register or may be registered in the future. Therefore the failure event is wrapped in a try-catch itself and throws a combined exception that is logged in the exception.log. --- .../Magento/Quote/Model/QuoteManagement.php | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 8f216b64aa9b0..b10777f816fdf 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -12,6 +12,7 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\StateException; +use Magento\Framework\Phrase; use Magento\Quote\Api\Data\PaymentInterface; use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter; use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter; @@ -532,19 +533,31 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) ); $this->quoteRepository->save($quote); } catch (\Exception $e) { - if (!empty($this->addressesToSync)) { - foreach ($this->addressesToSync as $addressId) { - $this->addressRepository->deleteById($addressId); + try { + if (!empty($this->addressesToSync)) { + foreach ($this->addressesToSync as $addressId) { + $this->addressRepository->deleteById($addressId); + } } + $this->eventManager->dispatch( + 'sales_model_service_quote_submit_failure', + [ + 'order' => $order, + 'quote' => $quote, + 'exception' => $e, + ] + ); + } catch (\Exception $consecutiveException) { + $message = new Phrase( + "An exception occurred on 'sales_model_service_quote_submit_failure' event: %1\n%2", + [ + $consecutiveException->getMessage(), + $consecutiveException->getTraceAsString() + ] + ); + + throw new LocalizedException($message, $e); } - $this->eventManager->dispatch( - 'sales_model_service_quote_submit_failure', - [ - 'order' => $order, - 'quote' => $quote, - 'exception' => $e - ] - ); throw $e; } return $order; From 6b0ebf49055d0ee4bb371ffc23186eef2eb02fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20F=C3=BChr?= Date: Mon, 11 Mar 2019 15:48:37 +0100 Subject: [PATCH 28/80] amend consecutive exception handling - support masking of root cause in frontend - remove stack trace for consecutive exception to comply to default behaviour --- app/code/Magento/Quote/Model/QuoteManagement.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index b10777f816fdf..e1058c98271c1 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -12,7 +12,6 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\StateException; -use Magento\Framework\Phrase; use Magento\Quote\Api\Data\PaymentInterface; use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter; use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter; @@ -548,15 +547,12 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) ] ); } catch (\Exception $consecutiveException) { - $message = new Phrase( - "An exception occurred on 'sales_model_service_quote_submit_failure' event: %1\n%2", - [ - $consecutiveException->getMessage(), - $consecutiveException->getTraceAsString() - ] + $message = sprintf( + "An exception occurred on 'sales_model_service_quote_submit_failure' event: %s", + $consecutiveException->getMessage() ); - throw new LocalizedException($message, $e); + throw new \Exception($message, 0, $e); } throw $e; } From 9dee0e111dc25b3ea45619370b876014ca855f0d Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Tue, 12 Mar 2019 07:59:18 +0200 Subject: [PATCH 29/80] Currency misspelled in graphql attributes --- app/code/Magento/DirectoryGraphQl/etc/schema.graphqls | 4 ++-- .../testsuite/Magento/GraphQl/Directory/CurrencyTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls index 40ef6975fad8b..f2bc576f95e8e 100644 --- a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls +++ b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls @@ -10,8 +10,8 @@ type Query { type Currency { base_currency_code: String base_currency_symbol: String - default_display_currecy_code: String - default_display_currecy_symbol: String + default_display_currency_code: String + default_display_currency_symbol: String available_currency_codes: [String] exchange_rates: [ExchangeRate] } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php index 1ff0b53dda0bb..ad5d71cb08605 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php @@ -21,8 +21,8 @@ public function testGetCurrency() currency { base_currency_code base_currency_symbol - default_display_currecy_code - default_display_currecy_symbol + default_display_currency_code + default_display_currency_symbol available_currency_codes exchange_rates { currency_to @@ -36,8 +36,8 @@ public function testGetCurrency() $this->assertArrayHasKey('currency', $result); $this->assertArrayHasKey('base_currency_code', $result['currency']); $this->assertArrayHasKey('base_currency_symbol', $result['currency']); - $this->assertArrayHasKey('default_display_currecy_code', $result['currency']); - $this->assertArrayHasKey('default_display_currecy_symbol', $result['currency']); + $this->assertArrayHasKey('default_display_currency_code', $result['currency']); + $this->assertArrayHasKey('default_display_currency_symbol', $result['currency']); $this->assertArrayHasKey('available_currency_codes', $result['currency']); $this->assertArrayHasKey('exchange_rates', $result['currency']); } From bfbc5e95b74d0b96b86f3a13c978320c130971e0 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Tue, 12 Mar 2019 17:55:45 -0500 Subject: [PATCH 30/80] MAGETWO-98621: Special price not removing at website scope --- .../Eav/Model/Entity/AbstractEntity.php | 8 +++-- .../Model/ResourceModel/ProductTest.php | 34 ++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index d0a5e8de53ae9..1fd71e446e6bb 100644 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -1683,14 +1683,16 @@ public function saveAttribute(DataObject $object, $attributeCode) $connection->beginTransaction(); try { - $select = $connection->select()->from($table, 'value_id')->where($where); - $origValueId = $connection->fetchOne($select); + $select = $connection->select()->from($table, ['value_id', 'value'])->where($where); + $origRow = $connection->fetchRow($select); + $origValueId = $origRow['value_id'] ?? false; + $origValue = $origRow['value'] ?? null; if ($origValueId === false && $newValue !== null) { $this->_insertAttribute($object, $attribute, $newValue); } elseif ($origValueId !== false && $newValue !== null) { $this->_updateAttribute($object, $attribute, $origValueId, $newValue); - } elseif ($origValueId !== false && $newValue === null) { + } elseif ($origValueId !== false && $newValue === null && $origValue !== null) { $connection->delete($table, $where); } $this->_processAttributeValues(); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/ProductTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/ProductTest.php index 7954e2c36227f..476f01eb277df 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/ProductTest.php @@ -12,6 +12,11 @@ class ProductTest extends TestCase { + /** + * @var ProductRepositoryInterface + */ + private $productRepository; + /** * @var Product */ @@ -29,7 +34,8 @@ protected function setUp() { $this->objectManager = Bootstrap::getObjectManager(); - $this->model = $this->objectManager->get(Product::class); + $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class); + $this->model = $this->objectManager->create(Product::class); } /** @@ -42,11 +48,29 @@ public function testGetAttributeRawValue() $sku = 'simple'; $attribute = 'name'; - /** @var ProductRepositoryInterface $productRepository */ - $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); - $product = $productRepository->get($sku); - + $product = $this->productRepository->get($sku); $actual = $this->model->getAttributeRawValue($product->getId(), $attribute, null); self::assertEquals($product->getName(), $actual); } + + /** + * @magentoAppArea adminhtml + * @magentoDataFixture Magento/Catalog/_files/product_special_price.php + * @magentoAppIsolation enabled + * @magentoConfigFixture default_store catalog/price/scope 1 + */ + public function testUpdateStoreSpecificSpecialPrice() + { + /** @var \Magento\Catalog\Model\Product $product */ + $product = $this->productRepository->get('simple', true, 1); + $this->assertEquals(5.99, $product->getSpecialPrice()); + + $product->setSpecialPrice(''); + $this->model->save($product); + $product = $this->productRepository->get('simple', false, 1, true); + $this->assertEmpty($product->getSpecialPrice()); + + $product = $this->productRepository->get('simple', false, 0, true); + $this->assertEquals(5.99, $product->getSpecialPrice()); + } } From b62240110ec89edcefbb2f461c311086db9bc013 Mon Sep 17 00:00:00 2001 From: Vishal Gelani Date: Wed, 13 Mar 2019 11:26:19 +0530 Subject: [PATCH 31/80] Updated sort order --- app/code/Magento/Review/etc/adminhtml/menu.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/etc/adminhtml/menu.xml b/app/code/Magento/Review/etc/adminhtml/menu.xml index 72499b416cd17..7376329471921 100644 --- a/app/code/Magento/Review/etc/adminhtml/menu.xml +++ b/app/code/Magento/Review/etc/adminhtml/menu.xml @@ -8,8 +8,8 @@ - - + + From 417fda4da93bdd11f83eec9c7ed27f2a84cc2a44 Mon Sep 17 00:00:00 2001 From: Vishal Gelani Date: Wed, 13 Mar 2019 11:27:01 +0530 Subject: [PATCH 32/80] Update acl.xml --- app/code/Magento/Review/etc/acl.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Review/etc/acl.xml b/app/code/Magento/Review/etc/acl.xml index 6932f2535090c..46fdb20dee4a1 100644 --- a/app/code/Magento/Review/etc/acl.xml +++ b/app/code/Magento/Review/etc/acl.xml @@ -16,8 +16,8 @@ - - + + From aa25ca575a2f379dc69f2b7edc77c15ebf60f118 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Wed, 13 Mar 2019 10:01:26 +0300 Subject: [PATCH 33/80] MAGETWO-57934: [GitHub] Can't use "configurable" as group name in attribute sets M2.1 #6123 --- app/code/Magento/Eav/Model/Entity/Attribute/Group.php | 4 ++-- .../Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Group.php b/app/code/Magento/Eav/Model/Entity/Attribute/Group.php index 4570dfb2af5ec..2e55964560588 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Group.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Group.php @@ -127,8 +127,8 @@ public function beforeSave() ); $isReservedSystemName = in_array(strtolower($attributeGroupCode), $this->reservedSystemNames); if (empty($attributeGroupCode) || $isReservedSystemName) { - // in the following code sha1 is not used for security purposes - $attributeGroupCode = sha1(strtolower($groupName)); + // in the following code md5 is not used for security purposes + $attributeGroupCode = md5(strtolower($groupName)); } $this->setAttributeGroupCode($attributeGroupCode); } diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php index 986ab517ceca1..1584b922abaa9 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php @@ -68,9 +68,9 @@ public function attributeGroupCodeDataProvider() { return [ ['General Group', 'general-group'], - ['configurable', sha1('configurable')], - ['configurAble', sha1('configurable')], - ['///', sha1('///')], + ['configurable', md5('configurable')], + ['configurAble', md5('configurable')], + ['///', md5('///')], ]; } } From bfea663290be803d2ced87e55376790a27d47001 Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Wed, 13 Mar 2019 09:53:22 +0200 Subject: [PATCH 34/80] Currency misspelled in graphql attributes --- app/code/Magento/DirectoryGraphQl/etc/schema.graphqls | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls index f2bc576f95e8e..59c6a35e9a1ac 100644 --- a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls +++ b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls @@ -10,8 +10,10 @@ type Query { type Currency { base_currency_code: String base_currency_symbol: String + default_display_currecy_code: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_code`.") default_display_currency_code: String - default_display_currency_symbol: String + default_display_currecy_symbol: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_symbol`.") + default_display_currency_symbol available_currency_codes: [String] exchange_rates: [ExchangeRate] } From 6ebdde1f138cb5316b83dd437a5db329289ee8cb Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Wed, 13 Mar 2019 13:21:47 +0200 Subject: [PATCH 35/80] Currency misspelled in graphql attributes --- app/code/Magento/DirectoryGraphQl/etc/schema.graphqls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls index 59c6a35e9a1ac..8da1920f9a444 100644 --- a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls +++ b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls @@ -13,7 +13,7 @@ type Currency { default_display_currecy_code: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_code`.") default_display_currency_code: String default_display_currecy_symbol: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_symbol`.") - default_display_currency_symbol + default_display_currency_symbol: String available_currency_codes: [String] exchange_rates: [ExchangeRate] } From 1cf01787820058222c9d05cdd64088ef18073b0a Mon Sep 17 00:00:00 2001 From: AleksLi Date: Wed, 13 Mar 2019 12:15:37 +0100 Subject: [PATCH 36/80] GraphQL-432: Replaced the places are using getMaskedQuoteId as method. Added new class to handle that. --- .../GetAvailablePaymentMethodsTest.php | 23 +++++------- .../GraphQl/Quote/Customer/GetCartTest.php | 31 ++++++++-------- .../Customer/SetBillingAddressOnCartTest.php | 23 +++++------- .../Customer/SetPaymentMethodOnCartTest.php | 37 ++++++++++--------- .../Customer/SetShippingMethodsOnCartTest.php | 20 ++++------ .../Guest/GetAvailablePaymentMethodsTest.php | 23 +++++------- .../GraphQl/Quote/Guest/GetCartTest.php | 23 +++++------- .../Guest/SetBillingAddressOnCartTest.php | 33 +++++++++-------- .../Guest/SetPaymentMethodOnCartTest.php | 35 +++++++++--------- .../Guest/SetShippingMethodsOnCartTest.php | 20 ++++------ .../Quote/SetShippingAddressOnCartTest.php | 24 ++++++------ 11 files changed, 137 insertions(+), 155 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index 5695aab6854d4..777dd5508c16a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -8,6 +8,7 @@ namespace Magento\GraphQl\Quote\Customer; use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -24,6 +25,11 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract */ private $customerTokenService; + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -45,6 +51,7 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -53,10 +60,12 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetCartWithPaymentMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_item_with_items'); $query = << 'Bearer ' . $customerToken]; return $headerMap; } - - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php index fe9b7b3c49a7c..5407d1e90121d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php @@ -8,6 +8,7 @@ namespace Magento\GraphQl\Quote\Customer; use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -19,6 +20,11 @@ */ class GetCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -42,6 +48,7 @@ class GetCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -50,10 +57,12 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -74,10 +83,12 @@ public function testGetCart() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = $this->getCartQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -89,10 +100,12 @@ public function testGetGuestCart() /** * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetAnotherCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -136,18 +149,6 @@ private function getCartQuery( QUERY; } - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $username * @param string $password diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 1a93c011e80a8..2d7b2caf4363a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -8,6 +8,7 @@ namespace Magento\GraphQl\Quote\Customer; use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -19,6 +20,11 @@ */ class SetBillingAddressOnCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -42,6 +48,7 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -307,10 +314,12 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime() * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetBillingAddressToGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $reversedQuoteId * @param int $customerId diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php index bbc77b6c39740..97be79d79eef8 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -9,6 +9,7 @@ use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\OfflinePayments\Model\Checkmo; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -25,6 +26,11 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract */ private $customerTokenService; + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -46,6 +52,7 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -54,11 +61,13 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithVirtualProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_virtual_product'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -71,11 +80,13 @@ public function testSetPaymentWithVirtualProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -109,7 +120,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress() public function testSetNonExistingPaymentMethod() { $methodCode = 'noway'; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -118,11 +129,13 @@ public function testSetNonExistingPaymentMethod() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentMethodToGuestCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -136,11 +149,13 @@ public function testSetPaymentMethodToGuestCart() /** * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentMethodToAnotherCustomerCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -178,18 +193,6 @@ private function prepareMutationQuery( QUERY; } - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $reversedQuoteId * @param int $customerId diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php index 736ea69440753..c8d32ba796904 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php @@ -8,6 +8,7 @@ namespace Magento\GraphQl\Quote\Customer; use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -19,6 +20,11 @@ */ class SetShippingMethodsOnCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var CustomerTokenServiceInterface */ @@ -45,6 +51,7 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -161,19 +168,6 @@ private function prepareMutationQuery( QUERY; } - /** - * @param string $reversedQuoteId - * @return string - * @SuppressWarnings(PHPMD.UnusedPrivateMethod) - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $reversedQuoteId * @param int $customerId diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php index a5a08aaf39fb1..084401cdf8915 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -10,6 +10,7 @@ use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -18,6 +19,11 @@ */ class GetAvailablePaymentMethodsTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -39,6 +45,7 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -46,10 +53,12 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetCartWithPaymentMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php index b1d5e475c793e..8aa449906618b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php @@ -11,6 +11,7 @@ use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -19,6 +20,11 @@ */ class GetCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -42,6 +48,7 @@ class GetCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -73,10 +80,12 @@ public function testGetCart() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -119,18 +128,6 @@ private function getCartQuery( QUERY; } - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $reversedQuoteId * @param int $customerId diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 880d6aa0f406f..7b7f673d04935 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\Quote\Guest; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -18,6 +19,11 @@ */ class SetBillingAddressOnCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -36,6 +42,7 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -43,10 +50,12 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetNewBillingAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $query = <<getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = <<assertResponseFields($addressResponse, $assertionMap); } - - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index 7484b2af7569d..22592d78d5d09 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -11,6 +11,7 @@ use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -19,6 +20,11 @@ */ class SetPaymentMethodOnCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -40,6 +46,7 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -47,11 +54,13 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithVirtualProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_virtual_product'); $this->unAssignCustomerFromQuote('test_order_with_virtual_product'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -65,11 +74,13 @@ public function testSetPaymentWithVirtualProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $this->unAssignCustomerFromQuote('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -89,7 +100,7 @@ public function testSetPaymentWithSimpleProduct() public function testSetPaymentWithSimpleProductWithoutAddress() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query); @@ -103,7 +114,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress() public function testSetNonExistingPaymentMethod() { $methodCode = 'noway'; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $this->unAssignCustomerFromQuote('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -112,11 +123,13 @@ public function testSetNonExistingPaymentMethod() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @throws \Exception + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentMethodToCustomerCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -169,16 +182,4 @@ private function unAssignCustomerFromQuote( $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } - - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index f159cb6f6151e..07825922d718b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -10,6 +10,7 @@ use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -18,6 +19,11 @@ */ class SetShippingMethodsOnCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReversedQuoteId + */ + private $getMaskedQuoteIdByReversedQuoteId; + /** * @var QuoteResource */ @@ -39,6 +45,7 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReversedQuoteId->execute(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -151,17 +158,4 @@ private function prepareMutationQuery( QUERY; } - - /** - * @param string $reversedQuoteId - * @return string - * @SuppressWarnings(PHPMD.UnusedPrivateMethod) - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php index 9352111de8543..dcbf7220f24ec 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php @@ -24,38 +24,38 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract { /** - * @var QuoteResource + * @var CustomerTokenServiceInterface */ - private $quoteResource; + private $customerTokenService; /** - * @var QuoteFactory + * @var GetMaskedQuoteIdByReversedQuoteId */ - private $quoteFactory; + private $getMaskedQuoteIdByReversedQuoteId; /** - * @var QuoteIdToMaskedQuoteIdInterface + * @var QuoteResource */ - private $quoteIdToMaskedId; + private $quoteResource; /** - * @var GetMaskedQuoteIdByReversedQuoteId + * @var QuoteFactory */ - private $getMaskedQuoteIdByReversedQuoteId; + private $quoteFactory; /** - * @var CustomerTokenServiceInterface + * @var QuoteIdToMaskedQuoteIdInterface */ - private $customerTokenService; + private $quoteIdToMaskedId; protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); - $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** From 2d5f881ce37685bc6b1b34a778fb6ac4aa83f548 Mon Sep 17 00:00:00 2001 From: Yuliya Labudova Date: Wed, 13 Mar 2019 14:38:37 +0300 Subject: [PATCH 37/80] MAGETWO-44165: [FT] Magento\Catalog\Test\TestCase\Product\ProductTypeSwitchingOnCreationTest fails - Migrate tests to mftf. --- .../Test/AdminCreateAndSwitchProductType.xml | 109 +++++++++++++++++- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml index e79f7f75cce3f..50c17cfc4b9ab 100755 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml @@ -53,9 +53,6 @@ - - - @@ -83,4 +80,110 @@ + + + + + + <description value="After selecting a simple product when adding Admin should be switch to configurable implicitly"/> + <severity value="CRITICAL"/> + <testCaseId value="MAGETWO-29398"/> + <group value="catalog"/> + <group value="mtf_migrated"/> + </annotations> + <before> + <createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/> + <createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1"> + <requiredEntity createDataKey="createConfigProductAttribute"/> + </createData> + </before> + <after> + <deleteData stepKey="deleteAttribute" createDataKey="createConfigProductAttribute"/> + </after> + <actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="openProductFillForm"> + <argument name="productType" value="simple"/> + </actionGroup> + <actionGroup ref="fillMainProductForm" stepKey="fillProductForm"> + <argument name="product" value="_defaultProduct"/> + </actionGroup> + <comment before="createConfiguration" stepKey="beforeCreateConfiguration" userInput="Adding Configuration to Product"/> + <actionGroup ref="generateConfigurationsByAttributeCode" stepKey="createConfiguration" after="fillProductForm"> + <argument name="attributeCode" value="$$createConfigProductAttribute.attribute_code$$"/> + </actionGroup> + <actionGroup ref="saveConfiguredProduct" stepKey="saveProductForm"/> + <see selector="{{AdminProductGridSection.productGridCell('2', 'Type')}}" userInput="Configurable Product" stepKey="seeProductTypeInGrid"/> + <actionGroup ref="VerifyOptionInProductStorefront" stepKey="verifyConfigurableOption" after="AssertProductInStorefrontProductPage"> + <argument name="attributeCode" value="$createConfigProductAttribute.default_frontend_label$"/> + <argument name="optionName" value="$createConfigProductAttributeOption1.option[store_labels][1][label]$"/> + </actionGroup> + </test> + <test name="AdminCreateDownloadableProductSwitchToConfigurableTest"> + <annotations> + <features value="Catalog"/> + <stories value="Product Type Switching"/> + <title value="Admin should be able to switch a new product from downloadable to configurable"/> + <description value="After selecting a downloadable product when adding Admin should be switch to configurable implicitly"/> + <severity value="CRITICAL"/> + <testCaseId value="MAGETWO-29398"/> + <group value="catalog"/> + <group value="mtf_migrated"/> + </annotations> + <before> + <createData entity="_defaultCategory" stepKey="createPreReqCategory"/> + <createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/> + <createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1"> + <requiredEntity createDataKey="createConfigProductAttribute"/> + </createData> + </before> + <after> + <actionGroup ref="GoToProductCatalogPage" stepKey="goToProductCatalogPage"/> + <actionGroup ref="deleteProductUsingProductGrid" stepKey="deleteConfigurableProduct"> + <argument name="product" value="_defaultProduct"/> + </actionGroup> + <actionGroup ref="resetProductGridToDefaultView" stepKey="resetSearch"/> + <deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/> + <deleteData stepKey="deleteAttribute" createDataKey="createConfigProductAttribute"/> + <actionGroup ref="logout" stepKey="logout"/> + </after> + + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/> + <!-- Open Dropdown and select downloadable product option --> + <comment stepKey="beforeOpenProductFillForm" userInput="Selecting Product from the Add Product Dropdown"/> + <actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="openProductFillForm"> + <argument name="productType" value="downloadable"/> + </actionGroup> + + <scrollTo selector="{{AdminProductDownloadableSection.sectionHeader}}" stepKey="scrollToDownloadableInfo" /> + <wait stepKey="2" time="3"/> + <uncheckOption selector="{{AdminProductDownloadableSection.isDownloadableProduct}}" stepKey="checkIsDownloadable"/> + + <!-- Fill form for Downloadable Product Type --> + <comment stepKey="beforeFillProductForm" userInput="Filling Product Form"/> + <actionGroup ref="fillMainProductForm" stepKey="fillProductForm"> + <argument name="product" value="_defaultProduct"/> + </actionGroup> + <actionGroup ref="SetProductUrlKey" stepKey="setProductUrl"> + <argument name="product" value="_defaultProduct"/> + </actionGroup> + <comment before="createConfiguration" stepKey="beforeCreateConfiguration" userInput="Adding Configuration to Product"/> + <actionGroup ref="generateConfigurationsByAttributeCode" stepKey="createConfiguration"> + <argument name="attributeCode" value="$$createConfigProductAttribute.attribute_code$$"/> + </actionGroup> + <actionGroup ref="saveConfiguredProduct" stepKey="saveProductForm"/> + <!-- Check that product was added with implicit type change --> + <comment stepKey="beforeVerify" userInput="Verify Product Type Assigned Correctly"/> + <actionGroup ref="GoToProductCatalogPage" stepKey="goToProductCatalogPage"/> + <actionGroup ref="resetProductGridToDefaultView" stepKey="resetSearch"/> + <actionGroup ref="filterProductGridByName" stepKey="searchForProduct"> + <argument name="product" value="_defaultProduct"/> + </actionGroup> + <see selector="{{AdminProductGridSection.productGridCell('2', 'Type')}}" userInput="Configurable Product" stepKey="seeProductTypeInGrid"/> + <actionGroup ref="AssertProductInStorefrontProductPage" stepKey="AssertProductInStorefrontProductPage"> + <argument name="product" value="_defaultProduct"/> + </actionGroup> + <actionGroup ref="VerifyOptionInProductStorefront" stepKey="verifyConfigurableOption"> + <argument name="attributeCode" value="$createConfigProductAttribute.default_frontend_label$"/> + <argument name="optionName" value="$createConfigProductAttributeOption1.option[store_labels][1][label]$"/> + </actionGroup> + </test> </tests> From 06fe10916fcc622bd081c1bd83179b02696e9d62 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi <horytsky@adobe.com> Date: Wed, 13 Mar 2019 08:21:53 -0500 Subject: [PATCH 38/80] MAGETWO-98643: [Magento Cloud] Translated Arabic URL's are returning 404's --- .../UrlRewrite/Model/Storage/DbStorage.php | 109 +++++++++++++----- .../Model/UrlFinderInterfaceTest.php | 71 ++++++++++++ .../UrlRewrite/_files/url_rewrites.php | 42 +++++++ .../_files/url_rewrites_rollback.php | 20 ++++ 4 files changed, 210 insertions(+), 32 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/UrlRewrite/Model/UrlFinderInterfaceTest.php create mode 100644 dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites.php create mode 100644 dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites_rollback.php diff --git a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php index d8ceb16d71fdc..2ac1bdd712114 100644 --- a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php +++ b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php @@ -105,42 +105,18 @@ protected function doFindOneByData(array $data) $result = null; $requestPath = $data[UrlRewrite::REQUEST_PATH]; - - $data[UrlRewrite::REQUEST_PATH] = [ + $decodedRequestPath = urldecode($requestPath); + $data[UrlRewrite::REQUEST_PATH] = array_unique([ rtrim($requestPath, '/'), rtrim($requestPath, '/') . '/', - ]; + rtrim($decodedRequestPath, '/'), + rtrim($decodedRequestPath, '/') . '/', + ]); $resultsFromDb = $this->connection->fetchAll($this->prepareSelect($data)); - - if (count($resultsFromDb) === 1) { - $resultFromDb = current($resultsFromDb); - $redirectTypes = [OptionProvider::TEMPORARY, OptionProvider::PERMANENT]; - - // If request path matches the DB value or it's redirect - we can return result from DB - $canReturnResultFromDb = ($resultFromDb[UrlRewrite::REQUEST_PATH] === $requestPath - || in_array((int)$resultFromDb[UrlRewrite::REDIRECT_TYPE], $redirectTypes, true)); - - // Otherwise return 301 redirect to request path from DB results - $result = $canReturnResultFromDb ? $resultFromDb : [ - UrlRewrite::ENTITY_TYPE => 'custom', - UrlRewrite::ENTITY_ID => '0', - UrlRewrite::REQUEST_PATH => $requestPath, - UrlRewrite::TARGET_PATH => $resultFromDb[UrlRewrite::REQUEST_PATH], - UrlRewrite::REDIRECT_TYPE => OptionProvider::PERMANENT, - UrlRewrite::STORE_ID => $resultFromDb[UrlRewrite::STORE_ID], - UrlRewrite::DESCRIPTION => null, - UrlRewrite::IS_AUTOGENERATED => '0', - UrlRewrite::METADATA => null, - ]; - } else { - // If we have 2 results - return the row that matches request path - foreach ($resultsFromDb as $resultFromDb) { - if ($resultFromDb[UrlRewrite::REQUEST_PATH] === $requestPath) { - $result = $resultFromDb; - break; - } - } + if ($resultsFromDb) { + $urlRewrite = $this->extractMostRelevantUrlRewrite($requestPath, $resultsFromDb); + $result = $this->prepareUrlRewrite($requestPath, $urlRewrite); } return $result; @@ -149,6 +125,75 @@ protected function doFindOneByData(array $data) return $this->connection->fetchRow($this->prepareSelect($data)); } + /** + * Extract most relevant url rewrite from url rewrites list + * + * @param string $requestPath + * @param array $urlRewrites + * @return array|null + */ + private function extractMostRelevantUrlRewrite(string $requestPath, array $urlRewrites): ?array + { + $prioritizedUrlRewrites = []; + foreach ($urlRewrites as $urlRewrite) { + switch (true) { + case $urlRewrite[UrlRewrite::REQUEST_PATH] === $requestPath: + $priority = 1; + break; + case $urlRewrite[UrlRewrite::REQUEST_PATH] === urldecode($requestPath): + $priority = 2; + break; + case rtrim($urlRewrite[UrlRewrite::REQUEST_PATH], '/') === rtrim($requestPath, '/'): + $priority = 3; + break; + case rtrim($urlRewrite[UrlRewrite::REQUEST_PATH], '/') === rtrim(urldecode($requestPath), '/'): + $priority = 4; + break; + default: + $priority = 5; + break; + } + $prioritizedUrlRewrites[$priority] = $urlRewrite; + } + ksort($prioritizedUrlRewrites); + + return array_shift($prioritizedUrlRewrites); + } + + /** + * Prepare url rewrite + * + * If request path matches the DB value or it's redirect - we can return result from DB + * Otherwise return 301 redirect to request path from DB results + * + * @param string $requestPath + * @param array $urlRewrite + * @return array + */ + private function prepareUrlRewrite(string $requestPath, array $urlRewrite): array + { + $redirectTypes = [OptionProvider::TEMPORARY, OptionProvider::PERMANENT]; + $canReturnResultFromDb = ( + in_array($urlRewrite[UrlRewrite::REQUEST_PATH], [$requestPath, urldecode($requestPath)], true) + || in_array((int) $urlRewrite[UrlRewrite::REDIRECT_TYPE], $redirectTypes, true) + ); + if (!$canReturnResultFromDb) { + $urlRewrite = [ + UrlRewrite::ENTITY_TYPE => 'custom', + UrlRewrite::ENTITY_ID => '0', + UrlRewrite::REQUEST_PATH => $requestPath, + UrlRewrite::TARGET_PATH => $urlRewrite[UrlRewrite::REQUEST_PATH], + UrlRewrite::REDIRECT_TYPE => OptionProvider::PERMANENT, + UrlRewrite::STORE_ID => $urlRewrite[UrlRewrite::STORE_ID], + UrlRewrite::DESCRIPTION => null, + UrlRewrite::IS_AUTOGENERATED => '0', + UrlRewrite::METADATA => null, + ]; + } + + return $urlRewrite; + } + /** * Delete old URLs from DB. * diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/UrlFinderInterfaceTest.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/UrlFinderInterfaceTest.php new file mode 100644 index 0000000000000..b6055f14e79d2 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/Model/UrlFinderInterfaceTest.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\UrlRewrite\Model; + +use Magento\TestFramework\Helper\Bootstrap; +use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; + +/** + * @magentoDataFixture Magento/UrlRewrite/_files/url_rewrites.php + */ +class UrlFinderInterfaceTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var UrlFinderInterface + */ + private $urlFinder; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->urlFinder = Bootstrap::getObjectManager()->create(UrlFinderInterface::class); + } + + /** + * @dataProvider findOneDataProvider + * @param string $requestPath + * @param string $targetPath + * @param int $redirectType + */ + public function testFindOneByData(string $requestPath, string $targetPath, int $redirectType) + { + $data = [ + UrlRewrite::REQUEST_PATH => $requestPath, + ]; + $urlRewrite = $this->urlFinder->findOneByData($data); + $this->assertEquals($targetPath, $urlRewrite->getTargetPath()); + $this->assertEquals($redirectType, $urlRewrite->getRedirectType()); + } + + /** + * @return array + */ + public function findOneDataProvider(): array + { + return [ + ['string', 'test_page1', 0], + ['string/', 'string', 301], + ['string_permanent', 'test_page1', 301], + ['string_permanent/', 'test_page1', 301], + ['string_temporary', 'test_page1', 302], + ['string_temporary/', 'test_page1', 302], + ['строка', 'test_page1', 0], + ['строка/', 'строка', 301], + [urlencode('строка'), 'test_page2', 0], + [urlencode('строка') . '/', urlencode('строка'), 301], + ['другая_строка', 'test_page1', 302], + ['другая_строка/', 'test_page1', 302], + [urlencode('другая_строка'), 'test_page1', 302], + [urlencode('другая_строка') . '/', 'test_page1', 302], + ['السلسلة', 'test_page1', 0], + [urlencode('السلسلة'), 'test_page1', 0], + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites.php new file mode 100644 index 0000000000000..9edc6507308ee --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +$rewritesData = [ + [ + 'string', 'test_page1', 0 + ], + [ + 'string_permanent', 'test_page1', \Magento\UrlRewrite\Model\OptionProvider::PERMANENT + ], + [ + 'string_temporary', 'test_page1', \Magento\UrlRewrite\Model\OptionProvider::TEMPORARY + ], + [ + 'строка', 'test_page1', 0 + ], + [ + urlencode('строка'), 'test_page2', 0 + ], + [ + 'другая_строка', 'test_page1', \Magento\UrlRewrite\Model\OptionProvider::TEMPORARY + ], + [ + 'السلسلة', 'test_page1', 0 + ], +]; + +$rewriteResource = $objectManager->create(\Magento\UrlRewrite\Model\ResourceModel\UrlRewrite::class); +foreach ($rewritesData as $rewriteData) { + list ($requestPath, $targetPath, $redirectType) = $rewriteData; + $rewrite = $objectManager->create(\Magento\UrlRewrite\Model\UrlRewrite::class); + $rewrite->setEntityType('custom') + ->setRequestPath($requestPath) + ->setTargetPath($targetPath) + ->setRedirectType($redirectType); + $rewriteResource->save($rewrite); +} diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites_rollback.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites_rollback.php new file mode 100644 index 0000000000000..a98f947d614e0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrites_rollback.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +$registry = $objectManager->get(\Magento\Framework\Registry::class); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +$urlRewriteCollection = $objectManager->create(\Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection::class); +$collection = $urlRewriteCollection + ->addFieldToFilter('target_path', ['test_page1', 'test_page2']) + ->load() + ->walk('delete'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); From cb9d6757f4cdf89cc5c1e970663b8eeb30606e40 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi <horytsky@adobe.com> Date: Wed, 13 Mar 2019 12:55:52 -0500 Subject: [PATCH 39/80] MAGETWO-98665: [Magento cloud] Media directories not sorted --- app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php | 3 ++- .../Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php index b2ef78bab9909..ca563bd9d8f61 100644 --- a/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php @@ -270,7 +270,8 @@ public function getDirsCollection($path) $collection = $this->getCollection($path) ->setCollectDirs(true) ->setCollectFiles(false) - ->setCollectRecursively(false); + ->setCollectRecursively(false) + ->setOrder('basename', \Magento\Framework\Data\Collection\Filesystem::SORT_ORDER_ASC); $conditions = $this->getConditionsForExcludeDirs(); diff --git a/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php b/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php index 309f08a54aab6..7bec1e3601461 100644 --- a/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php +++ b/app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php @@ -417,6 +417,10 @@ protected function generalTestGetDirsCollection($path, $collectionArray = [], $e ->method('setCollectRecursively') ->with(false) ->willReturnSelf(); + $storageCollectionMock->expects($this->once()) + ->method('setOrder') + ->with('basename', \Magento\Framework\Data\Collection\Filesystem::SORT_ORDER_ASC) + ->willReturnSelf(); $storageCollectionMock->expects($this->once()) ->method('getIterator') ->willReturn(new \ArrayIterator($collectionArray)); From 72574016f8ca169c45a5e3beda7456201699d5f8 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Wed, 13 Mar 2019 18:18:43 -0500 Subject: [PATCH 40/80] GraphQL-432: Test coverage: 'reversed quote id to masked cart id' --- .../GetAvailablePaymentMethodsTest.php | 42 ++++------------- .../GraphQl/Quote/Customer/GetCartTest.php | 27 +++++------ .../Customer/SetBillingAddressOnCartTest.php | 20 ++++----- .../Customer/SetPaymentMethodOnCartTest.php | 40 +++++++---------- .../Customer/SetShippingAddressOnCartTest.php | 6 +-- .../Customer/SetShippingMethodsOnCartTest.php | 26 ++++++----- .../GetMaskedQuoteIdByReservedOrderId.php | 13 +++--- .../Guest/GetAvailablePaymentMethodsTest.php | 44 +++++------------- .../GraphQl/Quote/Guest/GetCartTest.php | 18 ++++---- .../Guest/SetBillingAddressOnCartTest.php | 16 +++---- .../Guest/SetPaymentMethodOnCartTest.php | 34 +++++++------- .../Guest/SetShippingAddressOnCartTest.php | 45 ++++++++++--------- .../Guest/SetShippingMethodsOnCartTest.php | 20 ++++++--- 13 files changed, 154 insertions(+), 197 deletions(-) rename app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php => dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php (81%) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index a7287ada093b8..74921348f449e 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -7,10 +7,8 @@ namespace Magento\GraphQl\Quote\Customer; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -25,19 +23,9 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract private $customerTokenService; /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; + private $getMaskedQuoteIdByReservedOrderId; /** * @inheritdoc @@ -45,9 +33,7 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } @@ -56,7 +42,7 @@ protected function setUp() */ public function testGetCartWithPaymentMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -76,7 +62,7 @@ public function testGetCartWithPaymentMethods() */ public function testGetPaymentMethodsFromGuestCart() { - $guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId( + $guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId->execute( 'test_order_with_virtual_product_without_address' ); $query = $this->getQuery($guestQuoteMaskedId); @@ -93,7 +79,7 @@ public function testGetPaymentMethodsFromGuestCart() */ public function testGetPaymentMethodsFromAnotherCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -108,7 +94,7 @@ public function testGetPaymentMethodsFromAnotherCustomerCart() */ public function testGetPaymentMethodsIfPaymentsAreNotSet() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -158,16 +144,4 @@ private function getHeaderMap(string $username = 'customer@example.com', string $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; return $headerMap; } - - /** - * @param string $reservedOrderId - * @return string - */ - private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php index 4b1509eef354e..cc90f1aa1f219 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\Quote\Customer; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; @@ -19,6 +20,11 @@ */ class GetCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReservedOrderId + */ + private $getMaskedQuoteIdByReservedOrderId; + /** * @var QuoteResource */ @@ -42,6 +48,7 @@ class GetCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -53,7 +60,7 @@ protected function setUp() */ public function testGetCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -77,7 +84,9 @@ public function testGetCart() */ public function testGetGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = $this->getCartQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -92,7 +101,7 @@ public function testGetGuestCart() */ public function testGetAnotherCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -156,18 +165,6 @@ private function getCartQuery( QUERY; } - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $username * @param string $password diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index bae50fd292833..5183063e0c16f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -7,8 +7,8 @@ namespace Magento\GraphQl\Quote\Customer; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -21,9 +21,9 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract { /** - * @var GetMaskedQuoteIdByReversedQuoteId + * @var GetMaskedQuoteIdByReservedOrderId */ - private $getMaskedQuoteIdByReversedQuoteId; + private $getMaskedQuoteIdByReservedOrderId; /** * @var QuoteResource @@ -48,7 +48,7 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -314,12 +314,12 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime() * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetBillingAddressToGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = <<<QUERY mutation { @@ -489,16 +489,16 @@ private function getHeaderMap(string $username = 'customer@example.com', string } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @param int $customerId * @return string */ private function assignQuoteToCustomer( - string $reversedQuoteId = 'test_order_with_simple_product_without_address', + string $reversedOrderId = 'test_order_with_simple_product_without_address', int $customerId = 1 ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId($customerId); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php index e111021094421..5321f6967f99b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -7,9 +7,9 @@ namespace Magento\GraphQl\Quote\Customer; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\OfflinePayments\Model\Checkmo; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -22,14 +22,14 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract { /** - * @var CustomerTokenServiceInterface + * @var GetMaskedQuoteIdByReservedOrderId */ - private $customerTokenService; + private $getMaskedQuoteIdByReservedOrderId; /** - * @var GetMaskedQuoteIdByReversedQuoteId + * @var CustomerTokenServiceInterface */ - private $getMaskedQuoteIdByReversedQuoteId; + private $customerTokenService; /** * @var QuoteResource @@ -52,7 +52,7 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -61,13 +61,11 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithVirtualProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_virtual_product'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_virtual_product'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -80,13 +78,11 @@ public function testSetPaymentWithVirtualProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -120,7 +116,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress() public function testSetNonExistingPaymentMethod() { $methodCode = 'noway'; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -129,13 +125,13 @@ public function testSetNonExistingPaymentMethod() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentMethodToGuestCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -149,13 +145,11 @@ public function testSetPaymentMethodToGuestCart() /** * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentMethodToAnotherCustomerCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -192,7 +186,7 @@ public function testPaymentMethodOnNonExistentCart() public function testReSetPayment() { /** @var \Magento\Quote\Model\Quote $quote */ - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1_with_payment'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_with_payment'); $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -231,16 +225,16 @@ private function prepareMutationQuery( } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @param int $customerId * @return string */ private function assignQuoteToCustomer( - string $reversedQuoteId, + string $reversedOrderId, int $customerId ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId($customerId); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php index ae184b8930c07..4d4c61b3b4e5b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php @@ -513,16 +513,16 @@ private function getHeaderMap(string $username = 'customer@example.com', string } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @param int $customerId * @return string */ private function assignQuoteToCustomer( - string $reversedQuoteId = 'test_order_with_simple_product_without_address', + string $reversedOrderId = 'test_order_with_simple_product_without_address', int $customerId = 1 ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId($customerId); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php index c8d32ba796904..b5634f51cb366 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingMethodsOnCartTest.php @@ -8,7 +8,6 @@ namespace Magento\GraphQl\Quote\Customer; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -20,11 +19,6 @@ */ class SetShippingMethodsOnCartTest extends GraphQlAbstract { - /** - * @var GetMaskedQuoteIdByReversedQuoteId - */ - private $getMaskedQuoteIdByReversedQuoteId; - /** * @var CustomerTokenServiceInterface */ @@ -51,7 +45,6 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -169,17 +162,30 @@ private function prepareMutationQuery( } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId + * @return string + * @SuppressWarnings(PHPMD.UnusedPrivateMethod) + */ + private function getMaskedQuoteIdByReservedOrderId(string $reversedOrderId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } + + /** + * @param string $reversedOrderId * @param int $customerId * @return string * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ private function assignQuoteToCustomer( - string $reversedQuoteId, + string $reversedOrderId, int $customerId ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId($customerId); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php similarity index 81% rename from app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php index 60466170fc562..88462b8dbda3b 100644 --- a/app/code/Magento/QuoteGraphQl/Model/GetMaskedQuoteIdByReversedQuoteId.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php @@ -5,13 +5,16 @@ */ declare(strict_types=1); -namespace Magento\QuoteGraphQl\Model; +namespace Magento\GraphQl\Quote; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\QuoteFactory; -class GetMaskedQuoteIdByReversedQuoteId +/** + * Get masked quote id by reserved order id + */ +class GetMaskedQuoteIdByReservedOrderId { /** * @var QuoteFactory @@ -44,14 +47,14 @@ public function __construct( } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @return string * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function execute(string $reversedQuoteId): string + public function execute(string $reversedOrderId): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php index c4dd9af490c99..7da7480ca390a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -7,9 +7,7 @@ namespace Magento\GraphQl\Quote\Guest; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -19,19 +17,9 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract { /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; + private $getMaskedQuoteIdByReservedOrderId; /** * @inheritdoc @@ -39,9 +27,7 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); } /** @@ -49,7 +35,9 @@ protected function setUp() */ public function testGetCartWithPaymentMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); @@ -75,7 +63,7 @@ public function testGetCartWithPaymentMethods() */ public function testGetPaymentMethodsFromCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -90,7 +78,9 @@ public function testGetPaymentMethodsFromCustomerCart() */ public function testGetPaymentMethodsIfPaymentsAreNotSet() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); @@ -126,16 +116,4 @@ private function getQuery( } QUERY; } - - /** - * @param string $reservedOrderId - * @return string - */ - private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php index 33c20e784930e..847a7129750ff 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php @@ -7,11 +7,11 @@ namespace Magento\GraphQl\Quote\Guest; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -21,9 +21,9 @@ class GetCartTest extends GraphQlAbstract { /** - * @var GetMaskedQuoteIdByReversedQuoteId + * @var GetMaskedQuoteIdByReservedOrderId */ - private $getMaskedQuoteIdByReversedQuoteId; + private $getMaskedQuoteIdByReservedOrderId; /** * @var QuoteResource @@ -48,7 +48,7 @@ class GetCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -80,12 +80,10 @@ public function testGetCart() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testGetCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -147,15 +145,15 @@ private function getCartQuery( } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @param int $customerId * @return string */ private function unAssignCustomerFromQuote( - string $reversedQuoteId + string $reversedOrderId ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId(0); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index b19caeeefbeef..25227c7f7a7a0 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -7,7 +7,7 @@ namespace Magento\GraphQl\Quote\Guest; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; @@ -20,9 +20,9 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract { /** - * @var GetMaskedQuoteIdByReversedQuoteId + * @var GetMaskedQuoteIdByReservedOrderId */ - private $getMaskedQuoteIdByReversedQuoteId; + private $getMaskedQuoteIdByReservedOrderId; /** * @var QuoteResource @@ -42,7 +42,7 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -55,7 +55,7 @@ protected function setUp() */ public function testSetNewBillingAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_simple_product_without_address'); $query = <<<QUERY mutation { @@ -113,7 +113,7 @@ public function testSetNewBillingAddress() */ public function testSetNewBillingAddressWithUseForShippingParameter() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_simple_product_without_address'); $query = <<<QUERY mutation { @@ -189,7 +189,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter() */ public function testSetBillingAddressToCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $query = <<<QUERY mutation { @@ -234,7 +234,7 @@ public function testSetBillingAddressToCustomerCart() */ public function testSetBillingAddressFromAddressBook() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_simple_product_without_address'); $query = <<<QUERY mutation { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index 5d33a5d2edf8b..cd8cc59487343 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -7,11 +7,11 @@ namespace Magento\GraphQl\Quote\Guest; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\OfflinePayments\Model\Checkmo; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -21,9 +21,9 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract { /** - * @var GetMaskedQuoteIdByReversedQuoteId + * @var GetMaskedQuoteIdByReservedOrderId */ - private $getMaskedQuoteIdByReversedQuoteId; + private $getMaskedQuoteIdByReservedOrderId; /** * @var QuoteResource @@ -46,7 +46,7 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -54,13 +54,11 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithVirtualProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_virtual_product'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_virtual_product'); $this->unAssignCustomerFromQuote('test_order_with_virtual_product'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -74,13 +72,11 @@ public function testSetPaymentWithVirtualProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $this->unAssignCustomerFromQuote('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -100,7 +96,9 @@ public function testSetPaymentWithSimpleProduct() public function testSetPaymentWithSimpleProductWithoutAddress() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query); @@ -114,7 +112,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress() public function testSetNonExistingPaymentMethod() { $methodCode = 'noway'; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $this->unAssignCustomerFromQuote('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -123,13 +121,11 @@ public function testSetNonExistingPaymentMethod() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @throws \Exception - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSetPaymentMethodToCustomerCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -164,7 +160,7 @@ public function testSetPaymentOnNonExistentCart() public function testReSetPayment() { /** @var \Magento\Quote\Model\Quote $quote */ - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1_with_payment'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_with_payment'); $this->unAssignCustomerFromQuote('test_order_1_with_payment'); $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -206,15 +202,15 @@ private function prepareMutationQuery( } /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @param int $customerId * @return string */ private function unAssignCustomerFromQuote( - string $reversedQuoteId + string $reversedOrderId ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId(0); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php index 33aeb2b902a8f..5c6e0e9cec55e 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php @@ -8,6 +8,7 @@ namespace Magento\GraphQl\Quote\Guest; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Multishipping\Helper\Data; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; @@ -21,6 +22,11 @@ */ class SetShippingAddressOnCartTest extends GraphQlAbstract { + /** + * @var GetMaskedQuoteIdByReservedOrderId + */ + private $getMaskedQuoteIdByReservedOrderId; + /** * @var QuoteResource */ @@ -39,6 +45,7 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -49,7 +56,9 @@ protected function setUp() */ public function testSetNewShippingAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = <<<QUERY mutation { @@ -109,7 +118,9 @@ public function testSetNewShippingAddress() */ public function testSetNewShippingAddressOnQuoteWithVirtualProducts() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_virtual_product_without_address' + ); $query = <<<QUERY mutation { @@ -152,7 +163,9 @@ public function testSetNewShippingAddressOnQuoteWithVirtualProducts() */ public function testSetShippingAddressFromAddressBook() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = <<<QUERY mutation { @@ -222,7 +235,9 @@ public function testSetShippingAddressToCustomerCart() */ public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message) { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = <<<QUERY mutation { @@ -272,7 +287,9 @@ public function dataProviderUpdateWithMissedRequiredParameters() */ public function testSetMultipleNewShippingAddresses() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( + 'test_order_with_simple_product_without_address' + ); $query = <<<QUERY mutation { @@ -345,28 +362,16 @@ private function assertNewShippingAddressFields(array $shippingAddressResponse): } /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - - /** - * @param string $reversedQuoteId + * @param string $reversedOrderId * @param int $customerId * @return string */ private function assignQuoteToCustomer( - string $reversedQuoteId = 'test_order_with_simple_product_without_address', + string $reversedOrderId = 'test_order_with_simple_product_without_address', int $customerId = 1 ): string { $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); $quote->setCustomerId($customerId); $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index 07825922d718b..bf08ce8adce6c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -10,7 +10,6 @@ use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; -use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -19,11 +18,6 @@ */ class SetShippingMethodsOnCartTest extends GraphQlAbstract { - /** - * @var GetMaskedQuoteIdByReversedQuoteId - */ - private $getMaskedQuoteIdByReversedQuoteId; - /** * @var QuoteResource */ @@ -45,7 +39,6 @@ class SetShippingMethodsOnCartTest extends GraphQlAbstract protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->getMaskedQuoteIdByReversedQuoteId->execute(GetMaskedQuoteIdByReversedQuoteId::class); $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); @@ -158,4 +151,17 @@ private function prepareMutationQuery( QUERY; } + + /** + * @param string $reversedOrderId + * @return string + * @SuppressWarnings(PHPMD.UnusedPrivateMethod) + */ + private function getMaskedQuoteIdByReservedOrderId(string $reversedOrderId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } } From 28d11bca2f3ec24fda1e6d9cc73f151bbaf2e9d5 Mon Sep 17 00:00:00 2001 From: Dmytro Yushkin <dyushkin@adobe.com> Date: Thu, 14 Mar 2019 08:30:24 -0500 Subject: [PATCH 41/80] MAGETWO-98617: Pager does not work on Newsletter Subscribers Admin page --- .../Grid/Massaction/AbstractMassaction.php | 28 +++-- .../Unit/Block/Widget/Grid/MassactionTest.php | 56 ---------- .../Block/Widget/Grid/MassactionTest.php | 52 --------- .../Block/Adminhtml/Subscriber/GridTest.php | 103 ++++++++++++++++++ 4 files changed, 116 insertions(+), 123 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php b/app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php index 9890a10a4ceb0..891b2a3ada724 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php @@ -282,25 +282,23 @@ public function getGridIdsJson() if (!$this->getUseSelectAll()) { return ''; } - /** @var \Magento\Framework\Data\Collection $allIdsCollection */ - $allIdsCollection = clone $this->getParentBlock()->getCollection(); - if ($this->getMassactionIdField()) { - $massActionIdField = $this->getMassactionIdField(); + /** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */ + $collection = clone $this->getParentBlock()->getCollection(); + + if ($collection instanceof AbstractDb) { + $idsSelect = clone $collection->getSelect(); + $idsSelect->reset(\Magento\Framework\DB\Select::ORDER); + $idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT); + $idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET); + $idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS); + $idsSelect->columns($this->getMassactionIdField(), 'main_table'); + $idList = $collection->getConnection()->fetchCol($idsSelect); } else { - $massActionIdField = $this->getParentBlock()->getMassactionIdField(); + $idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField()); } - if ($allIdsCollection instanceof AbstractDb) { - $allIdsCollection->getSelect()->limit(); - $allIdsCollection->clear(); - } - - $gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField); - if (!empty($gridIds)) { - return join(",", $gridIds); - } - return ''; + return implode(',', $idList); } /** diff --git a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php index e8143b5f6b43a..e62b73f39241d 100644 --- a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php +++ b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php @@ -269,62 +269,6 @@ public function testGetGridIdsJsonWithoutUseSelectAll() $this->assertEmpty($this->_block->getGridIdsJson()); } - /** - * @param array $items - * @param string $result - * - * @dataProvider dataProviderGetGridIdsJsonWithUseSelectAll - */ - public function testGetGridIdsJsonWithUseSelectAll(array $items, $result) - { - $this->_block->setUseSelectAll(true); - - if ($this->_block->getMassactionIdField()) { - $massActionIdField = $this->_block->getMassactionIdField(); - } else { - $massActionIdField = $this->_block->getParentBlock()->getMassactionIdField(); - } - - $collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->_gridMock->expects($this->once()) - ->method('getCollection') - ->willReturn($collectionMock); - $collectionMock->expects($this->once()) - ->method('setPageSize') - ->with(0) - ->willReturnSelf(); - $collectionMock->expects($this->once()) - ->method('getColumnValues') - ->with($massActionIdField) - ->willReturn($items); - - $this->assertEquals($result, $this->_block->getGridIdsJson()); - } - - /** - * @return array - */ - public function dataProviderGetGridIdsJsonWithUseSelectAll() - { - return [ - [ - [], - '', - ], - [ - [1], - '1', - ], - [ - [1, 2, 3], - '1,2,3', - ], - ]; - } - /** * @param string $itemId * @param array|\Magento\Framework\DataObject $item diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Grid/MassactionTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Grid/MassactionTest.php index 8aeee9cf12494..e11c5ce5d9cf3 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Grid/MassactionTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Grid/MassactionTest.php @@ -87,41 +87,6 @@ public function testMassactionDefaultValues() $this->assertFalse($blockEmpty->isAvailable()); } - public function testGetJavaScript() - { - $this->loadLayout(); - - $javascript = $this->_block->getJavaScript(); - - $expectedItemFirst = '#"option_id1":{"label":"Option One",' . - '"url":"http:\\\/\\\/localhost\\\/index\.php\\\/(?:key\\\/([\w\d]+)\\\/)?",' . - '"complete":"Test","id":"option_id1"}#'; - $this->assertRegExp($expectedItemFirst, $javascript); - - $expectedItemSecond = '#"option_id2":{"label":"Option Two",' . - '"url":"http:\\\/\\\/localhost\\\/index\.php\\\/(?:key\\\/([\w\d]+)\\\/)?",' . - '"confirm":"Are you sure\?","id":"option_id2"}#'; - $this->assertRegExp($expectedItemSecond, $javascript); - } - - public function testGetJavaScriptWithAddedItem() - { - $this->loadLayout(); - - $input = [ - 'id' => 'option_id3', - 'label' => 'Option Three', - 'url' => '*/*/option3', - 'block_name' => 'admin.test.grid.massaction.option3', - ]; - $expected = '#"option_id3":{"id":"option_id3","label":"Option Three",' . - '"url":"http:\\\/\\\/localhost\\\/index\.php\\\/(?:key\\\/([\w\d]+)\\\/)?",' . - '"block_name":"admin.test.grid.massaction.option3"}#'; - - $this->_block->addItem($input['id'], $input); - $this->assertRegExp($expected, $this->_block->getJavaScript()); - } - /** * @param string $mageMode * @param int $expectedCount @@ -213,21 +178,4 @@ public function getItemsDataProvider() ] ]; } - - public function testGridContainsMassactionColumn() - { - $this->loadLayout(); - $this->_layout->getBlock('admin.test.grid')->toHtml(); - - $gridMassactionColumn = $this->_layout->getBlock('admin.test.grid') - ->getColumnSet() - ->getChildBlock('massaction'); - - $this->assertNotNull($gridMassactionColumn, 'Massaction column does not exist in the grid column set'); - $this->assertInstanceOf( - \Magento\Backend\Block\Widget\Grid\Column::class, - $gridMassactionColumn, - 'Massaction column is not an instance of \Magento\Backend\Block\Widget\Column' - ); - } } diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php new file mode 100644 index 0000000000000..ea361a643dee0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php @@ -0,0 +1,103 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Newsletter\Block\Adminhtml\Subscriber; + +/** + * @magentoAppArea adminhtml + * @magentoDbIsolation enabled + * + * @see \Magento\Newsletter\Block\Adminhtml\Subscriber\Grid + */ +class GridTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var null|\Magento\Framework\ObjectManagerInterface + */ + private $objectManager = null; + /** + * @var null|\Magento\Framework\View\LayoutInterface + */ + private $layout = null; + + /** + * Set up layout. + */ + protected function setUp() + { + parent::setUp(); + + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + + $this->layout = $this->objectManager->create(\Magento\Framework\View\LayoutInterface::class); + $this->layout->getUpdate()->load('newsletter_subscriber_grid'); + $this->layout->generateXml(); + $this->layout->generateElements(); + } + + /** + * Check if mass action block exists. + */ + public function testMassActionBlockExists() + { + $this->assertNotFalse( + $this->getMassActionBlock(), + 'Mass action block does not exist in the grid, or it name was changed.' + ); + } + + /** + * Check if mass action id field is correct. + */ + public function testMassActionFieldIdIsCorrect() + { + $this->assertEquals( + 'subscriber_id', + $this->getMassActionBlock()->getMassactionIdField(), + 'Mass action id field is incorrect.' + ); + } + + /** + * Check if function returns correct result. + * + * @magentoDataFixture Magento/Newsletter/_files/subscribers.php + */ + public function testMassActionBlockContainsCorrectIdList() + { + $this->assertEquals( + implode(',', $this->getAllSubscriberIdList()), + $this->getMassActionBlock()->getGridIdsJson(), + 'Function returns incorrect result.' + ); + } + + /** + * Retrieve mass action block. + * + * @return bool|\Magento\Backend\Block\Widget\Grid\Massaction + */ + private function getMassActionBlock() + { + return $this->layout->getBlock('adminhtml.newslettrer.subscriber.grid.massaction'); + } + + /** + * Retrieve list of id of all subscribers. + * + * @return array + */ + private function getAllSubscriberIdList() + { + /** @var \Magento\Framework\App\ResourceConnection $resourceConnection */ + $resourceConnection = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class); + $select = $resourceConnection->getConnection() + ->select() + ->from($resourceConnection->getTableName('newsletter_subscriber')) + ->columns(['subscriber_id' => 'subscriber_id']); + + return $resourceConnection->getConnection()->fetchCol($select); + } +} From c8ed1e8ce498174df804b578665a5bcfd4c9e850 Mon Sep 17 00:00:00 2001 From: RomanKis <roman.kis.y@gmail.com> Date: Fri, 15 Mar 2019 18:21:11 +0200 Subject: [PATCH 42/80] #21734 Error in JS validation rule --- .../Magento/Ui/view/base/web/js/lib/validation/rules.js | 6 +++--- lib/web/mage/validation.js | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js index d765f842a0895..97b47f77beeab 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js @@ -920,12 +920,12 @@ define([ ], 'validate-per-page-value-list': [ function (value) { - var isValid = utils.isEmpty(value), + var isValid = true, values = value.split(','), i; - if (isValid) { - return true; + if (utils.isEmpty(value)) { + return isValid; } for (i = 0; i < values.length; i++) { diff --git a/lib/web/mage/validation.js b/lib/web/mage/validation.js index dfa35473176b9..a57191fd4aff4 100644 --- a/lib/web/mage/validation.js +++ b/lib/web/mage/validation.js @@ -1431,10 +1431,14 @@ ], 'validate-per-page-value-list': [ function (v) { - var isValid = !$.mage.isEmpty(v), + var isValid = true, values = v.split(','), i; + if ($.mage.isEmpty(v)) { + return isValid; + } + for (i = 0; i < values.length; i++) { if (!/^[0-9]+$/.test(values[i])) { isValid = false; From 3e90069c0f65e2e672379b82bd3684145ede9820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ca=C3=A7ador?= <samuelmoreira27@gmail.com> Date: Fri, 15 Mar 2019 16:47:36 +0000 Subject: [PATCH 43/80] Multishipping checkout agreements now are the same as default checkout agreements --- .../multishipping_checkout_overview.xml | 2 +- .../templates/multishipping_agreements.phtml | 49 ------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml b/app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml index 3f742de0177da..122160f1a10cd 100644 --- a/app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml +++ b/app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml @@ -8,7 +8,7 @@ <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="checkout_overview"> - <block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::multishipping_agreements.phtml"/> + <block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/> </referenceBlock> </body> </page> diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml deleted file mode 100644 index 3400770f5cee8..0000000000000 --- a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -?> -<?php -/** - * @var $block \Magento\CheckoutAgreements\Block\Agreements - */ -?> -<?php if (!$block->getAgreements()) { - return; -} ?> -<ol id="checkout-agreements" class="agreements checkout items"> - <?php /** @var \Magento\CheckoutAgreements\Api\Data\AgreementInterface $agreement */ ?> - <?php foreach ($block->getAgreements() as $agreement): ?> - <li class="item"> - <div class="checkout-agreement-item-content"<?= ($agreement->getContentHeight() ? ' style="height:' . $agreement->getContentHeight() . '"' : '') ?>> - <?php if ($agreement->getIsHtml()):?> - <?= /* @escapeNotVerified */ $agreement->getContent() ?> - <?php else:?> - <?= nl2br($block->escapeHtml($agreement->getContent())) ?> - <?php endif; ?> - </div> - <?php if($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_MANUAL): ?> - <div id="checkout-agreements-form-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>" class="field choice agree required"> - <input type="checkbox" - id="agreement-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>" - name="agreement[<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>]" - value="1" - title="<?= $block->escapeHtml($agreement->getCheckboxText()) ?>" - class="checkbox" - data-validate="{required:true}"/> - <label class="label" for="agreement-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>"> - <span><?= $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span> - </label> - </div> - <?php elseif($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO): ?> - <div id="checkout-agreements-form-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>" class="field choice agree"> - <span><?= $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span> - </div> - <?php endif; ?> - </li> - <?php endforeach ?> -</ol> From 96ca3d488bb010959414e391160364ad2264e22b Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun <i.gryshkun@gmail.com> Date: Sat, 16 Mar 2019 08:31:53 +0200 Subject: [PATCH 44/80] While adding the product to Cart when the requested Qty is zero or less then zero, one was unexpectedly added --- .../Model/Cart/AddSimpleProductToCart.php | 5 +++++ .../GraphQl/Quote/AddSimpleProductToCartTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index 1b32866ed883c..6868ce3f7f1ff 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -67,6 +67,11 @@ public function execute(Quote $cart, array $cartItemData): void { $sku = $this->extractSku($cartItemData); $qty = $this->extractQty($cartItemData); + if ($qty <= 0) { + throw new GraphQlInputException( + __('Please enter a number greater than 0 in this field.') + ); + } $customizableOptions = $this->extractCustomizableOptions($cartItemData); try { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php index 1e92a2e497bed..d9ab8db62a195 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php @@ -59,6 +59,22 @@ public function testAddSimpleProductToCart() self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']); } + /** + * @magentoApiDataFixture Magento/Catalog/_files/products.php + * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php + * @expectedException \Exception + * @expectedExceptionMessage Please enter a number greater than 0 in this field. + */ + public function testAddSimpleProductToCartWithNegativeQty() + { + $sku = 'simple'; + $qty = -2; + $maskedQuoteId = $this->getMaskedQuoteId(); + + $query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty); + $this->graphQlQuery($query); + } + /** * @return string */ From b5803c581bf0debfc7e7b45be41cf3e869a4fc20 Mon Sep 17 00:00:00 2001 From: Harniuk Bohdan <bohar@smile.fr> Date: Sat, 16 Mar 2019 16:44:06 +0200 Subject: [PATCH 45/80] magento/graphql-ce#482: [Test Coverage] 'SetBillingAddressOnCart' functionality --- .../Customer/SetBillingAddressOnCartTest.php | 50 +++++++++++++++++++ .../Guest/SetBillingAddressOnCartTest.php | 49 ++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 67a086311d71a..02cd428767ccc 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -423,6 +423,39 @@ public function testSetBillingAddressOnNonExistentCart() $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @dataProvider dataProviderSetWithoutRequiredParameters + * @param string $input + * @param string $message + * @throws \Exception + */ + public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message) + { + $maskedQuoteId = $this->assignQuoteToCustomer(); + $input = str_replace('cart_id_value', $maskedQuoteId, $input); + + $query = <<<QUERY +mutation { + setBillingAddressOnCart( + input: { + {$input} + } + ) { + cart { + billing_address { + city + } + } + } +} +QUERY; + + $this->expectExceptionMessage($message); + $this->graphQlQuery($query); + } + /** * Verify the all the whitelisted fields for a New Address Object * @@ -506,4 +539,21 @@ private function assignQuoteToCustomer( $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } + + /** + * @return array + */ + public function dataProviderSetWithoutRequiredParameters() + { + return [ + 'missed_billing_address' => [ + 'cart_id: "cart_id_value"', + 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided.', + ], + 'missed_cart_id' => [ + 'billing_address: {}', + 'Required parameter "cart_id" is missing' + ] + ]; + } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 27de0d12e413d..de07b80b39592 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -263,6 +263,38 @@ public function testSetBillingAddressOnNonExistentCart() $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @dataProvider dataProviderSetWithoutRequiredParameters + * @param string $input + * @param string $message + * @throws \Exception + */ + public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message) + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $input = str_replace('cart_id_value', $maskedQuoteId, $input); + + $query = <<<QUERY +mutation { + setBillingAddressOnCart( + input: { + {$input} + } + ) { + cart { + billing_address { + city + } + } + } +} +QUERY; + + $this->expectExceptionMessage($message); + $this->graphQlQuery($query); + } + /** * Verify the all the whitelisted fields for a New Address Object * @@ -297,4 +329,21 @@ private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): str return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } + + /** + * @return array + */ + public function dataProviderSetWithoutRequiredParameters() + { + return [ + 'missed_billing_address' => [ + 'cart_id: "cart_id_value"', + 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided.', + ], + 'missed_cart_id' => [ + 'billing_address: {}', + 'Required parameter "cart_id" is missing' + ] + ]; + } } From 7d998a75d37f1098ab0528e7d5d50736584941cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ca=C3=A7ador?= <samuelmoreira27@gmail.com> Date: Sat, 16 Mar 2019 17:26:49 +0000 Subject: [PATCH 46/80] Restore multishipping_agreements file for backward compatibility --- .../templates/multishipping_agreements.phtml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml new file mode 100644 index 0000000000000..2d0667ee27cf8 --- /dev/null +++ b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +// @codingStandardsIgnoreFile + +?> +<?php +/** + * @var $block \Magento\CheckoutAgreements\Block\Agreements + */ +?> +<?php if (!$block->getAgreements()) { + return; +} ?> +<ol id="checkout-agreements" class="agreements checkout items"> + <?php /** @var \Magento\CheckoutAgreements\Api\Data\AgreementInterface $agreement */ ?> + <?php foreach ($block->getAgreements() as $agreement): ?> + <li class="item"> + <div class="checkout-agreement-item-content"<?= ($agreement->getContentHeight() ? ' style="height:' . $agreement->getContentHeight() . '"' : '') ?>> + <?php if ($agreement->getIsHtml()):?> + <?= /* @escapeNotVerified */ $agreement->getContent() ?> + <?php else:?> + <?= nl2br($block->escapeHtml($agreement->getContent())) ?> + <?php endif; ?> + </div> + <?php if($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_MANUAL): ?> + <div id="checkout-agreements-form-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>" class="field choice agree required"> + <input type="checkbox" + id="agreement-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>" + name="agreement[<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>]" + value="1" + title="<?= $block->escapeHtml($agreement->getCheckboxText()) ?>" + class="checkbox" + data-validate="{required:true}"/> + <label class="label" for="agreement-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>"> + <span><?= $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span> + </label> + </div> + <?php elseif($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO): ?> + <div id="checkout-agreements-form-<?= /* @escapeNotVerified */ $agreement->getAgreementId() ?>" class="field choice agree"> + <span><?= $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span> + </div> + <?php endif; ?> + </li> + <?php endforeach ?> +</ol> \ No newline at end of file From 65634f65e57771932f59cade74b3d6030ce8af06 Mon Sep 17 00:00:00 2001 From: Jeroen <jeroen@reachdigital.nl> Date: Mon, 18 Mar 2019 15:13:13 +0100 Subject: [PATCH 47/80] Refactor \Order\Shipment\AddTrack Controller to use ResultInterface --- .../Adminhtml/Order/Shipment/AddTrack.php | 83 ++++++++++++++----- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php index fa83db490e380..8abc74b50a00e 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php @@ -1,12 +1,23 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment; use Magento\Backend\App\Action; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Sales\Api\Data\ShipmentTrackInterfaceFactory; +use Magento\Sales\Api\ShipmentRepositoryInterface; +use Magento\Sales\Model\Order\Shipment\TrackFactory; +use Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader; class AddTrack extends \Magento\Backend\App\Action { @@ -18,56 +29,84 @@ class AddTrack extends \Magento\Backend\App\Action const ADMIN_RESOURCE = 'Magento_Sales::shipment'; /** - * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader + * @var ShipmentLoader */ protected $shipmentLoader; + /** + * @var ShipmentRepositoryInterface + */ + private $shipmentRepository; + + /** + * @var TrackFactory + */ + private $trackFactory; + + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param Action\Context $context - * @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader + * @param ShipmentLoader $shipmentLoader + * @param ShipmentRepositoryInterface|null $shipmentRepository + * @param TrackFactory|null $trackFactory + * @param SerializerInterface|null $serializer */ public function __construct( Action\Context $context, - \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader + ShipmentLoader $shipmentLoader, + ShipmentRepositoryInterface $shipmentRepository = null, + TrackFactory $trackFactory = null, + SerializerInterface $serializer = null ) { - $this->shipmentLoader = $shipmentLoader; parent::__construct($context); + + $this->shipmentLoader = $shipmentLoader; + $this->shipmentRepository = $shipmentRepository ?: ObjectManager::getInstance() + ->get(ShipmentRepositoryInterface::class); + $this->trackFactory = $trackFactory ?: ObjectManager::getInstance() + ->get(ShipmentTrackInterfaceFactory::class); + $this->serializer = $serializer ?: ObjectManager::getInstance() + ->get(SerializerInterface::class); } /** - * Add new tracking number action + * Add new tracking number action. * - * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @return ResultInterface */ - public function execute() + public function execute(): ResultInterface { try { $carrier = $this->getRequest()->getPost('carrier'); $number = $this->getRequest()->getPost('number'); $title = $this->getRequest()->getPost('title'); + if (empty($carrier)) { - throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a carrier.')); + throw new LocalizedException(__('Please specify a carrier.')); } if (empty($number)) { - throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a tracking number.')); + throw new LocalizedException(__('Please enter a tracking number.')); } + $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment')); $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); $shipment = $this->shipmentLoader->load(); if ($shipment) { - $track = $this->_objectManager->create( - \Magento\Sales\Model\Order\Shipment\Track::class - )->setNumber( + $track = $this->trackFactory->create()->setNumber( $number )->setCarrierCode( $carrier )->setTitle( $title ); - $shipment->addTrack($track)->save(); + $shipment->addTrack($track); + $this->shipmentRepository->save($shipment); $this->_view->loadLayout(); $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments')); @@ -78,16 +117,18 @@ public function execute() 'message' => __('We can\'t initialize shipment for adding tracking number.'), ]; } - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $response = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['error' => true, 'message' => __('Cannot add tracking number.')]; } - if (is_array($response)) { - $response = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($response); - $this->getResponse()->representJson($response); - } else { - $this->getResponse()->setBody($response); + + if (\is_array($response)) { + $response = $this->serializer->serialize($response); + + return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setJsonData($response); } + + return $this->resultFactory->create(ResultFactory::TYPE_RAW)->setContents($response); } } From 8b0318efede13c8844616a90c5bf67906a835ecf Mon Sep 17 00:00:00 2001 From: Tomash Khamlai <tomash.khamlai@gmail.com> Date: Mon, 18 Mar 2019 17:14:49 +0200 Subject: [PATCH 48/80] When setting `background` for labels explicitly the labels in admin will overlap the `::before` pseudo-element. I suggest to remove explicit setting for `label` element or replace `@color-white` to `transparent`. In some cases developers try to hide elements by setting white background and higher z-index for the element with white background. But the proper way of hiding elements is to override templates config or remove elements by JavaScript. --- .../adminhtml/Magento/backend/web/css/source/forms/_fields.less | 1 - 1 file changed, 1 deletion(-) diff --git a/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less b/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less index d8fd1db5ced47..5698afdaac7ae 100644 --- a/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less +++ b/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less @@ -545,7 +545,6 @@ & > .admin__field-label { #mix-grid .column(@field-label-grid__column, @field-grid__columns); cursor: pointer; - background: @color-white; left: 0; position: absolute; top: 0; From f4be1612bd4ba6d492cf920e7fdb9514fd5ebe56 Mon Sep 17 00:00:00 2001 From: Dmytro Cheshun <d.cheshun@atwix.com> Date: Mon, 18 Mar 2019 20:59:08 +0200 Subject: [PATCH 49/80] Fix phpcs issue: restore new line at the end of file --- .../view/frontend/templates/multishipping_agreements.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml index 2d0667ee27cf8..3400770f5cee8 100644 --- a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml +++ b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml @@ -46,4 +46,4 @@ <?php endif; ?> </li> <?php endforeach ?> -</ol> \ No newline at end of file +</ol> From 9b83593fab1f5dcbf351a8ae2fb6e88c815cecb8 Mon Sep 17 00:00:00 2001 From: Dmytro Cheshun <d.cheshun@atwix.com> Date: Mon, 18 Mar 2019 21:01:44 +0200 Subject: [PATCH 50/80] Add deprecated tag for legacy template --- .../view/frontend/templates/multishipping_agreements.phtml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml index 3400770f5cee8..33227f0cdce3c 100644 --- a/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml +++ b/app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ +// @deprecated // @codingStandardsIgnoreFile ?> From f5653ab878565e22b56e1c303127b2c7b8209e46 Mon Sep 17 00:00:00 2001 From: Dmytro Yushkin <dyushkin@adobe.com> Date: Mon, 18 Mar 2019 15:13:22 -0500 Subject: [PATCH 51/80] MAGETWO-98617: Pager does not work on Newsletter Subscribers Admin page - Added strict type declaration --- .../Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php index ea361a643dee0..48d3356525f49 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Subscriber/GridTest.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Newsletter\Block\Adminhtml\Subscriber; /** From b030da0d92eeb455b03059807b66a9de29d2a1bf Mon Sep 17 00:00:00 2001 From: RomanKis <roman.kis.y@gmail.com> Date: Tue, 19 Mar 2019 09:48:02 +0200 Subject: [PATCH 52/80] #21734 Error in JS validation rule --- app/code/Magento/Catalog/etc/adminhtml/system.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/etc/adminhtml/system.xml b/app/code/Magento/Catalog/etc/adminhtml/system.xml index 7a05601fcd666..1d563244f1432 100644 --- a/app/code/Magento/Catalog/etc/adminhtml/system.xml +++ b/app/code/Magento/Catalog/etc/adminhtml/system.xml @@ -59,7 +59,7 @@ <field id="grid_per_page_values" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Products per Page on Grid Allowed Values</label> <comment>Comma-separated.</comment> - <validate>validate-per-page-value-list</validate> + <validate>validate-per-page-value-list required-entry</validate> </field> <field id="grid_per_page" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Products per Page on Grid Default Value</label> @@ -69,7 +69,7 @@ <field id="list_per_page_values" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Products per Page on List Allowed Values</label> <comment>Comma-separated.</comment> - <validate>validate-per-page-value-list</validate> + <validate>validate-per-page-value-list required-entry</validate> </field> <field id="list_per_page" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Products per Page on List Default Value</label> From 24f4d9ad2e0448fc532346bdab55ace29692848c Mon Sep 17 00:00:00 2001 From: nmalevanec <mikola.malevanec@transoftgroup.com> Date: Wed, 20 Mar 2019 14:11:18 +0200 Subject: [PATCH 53/80] Fix static and unit tests. --- .../Adminhtml/Order/Shipment/AddTrack.php | 14 +- .../Adminhtml/Order/Shipment/AddTrackTest.php | 145 +++++++++++------- 2 files changed, 99 insertions(+), 60 deletions(-) diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php index 8abc74b50a00e..4ec7117783aab 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php @@ -8,18 +8,20 @@ namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Serialize\SerializerInterface; use Magento\Sales\Api\Data\ShipmentTrackInterfaceFactory; use Magento\Sales\Api\ShipmentRepositoryInterface; -use Magento\Sales\Model\Order\Shipment\TrackFactory; use Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader; -class AddTrack extends \Magento\Backend\App\Action +/** + * Add new tracking number to shipment controller. + */ +class AddTrack extends Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session @@ -39,7 +41,7 @@ class AddTrack extends \Magento\Backend\App\Action private $shipmentRepository; /** - * @var TrackFactory + * @var ShipmentTrackInterfaceFactory */ private $trackFactory; @@ -52,14 +54,14 @@ class AddTrack extends \Magento\Backend\App\Action * @param Action\Context $context * @param ShipmentLoader $shipmentLoader * @param ShipmentRepositoryInterface|null $shipmentRepository - * @param TrackFactory|null $trackFactory + * @param ShipmentTrackInterfaceFactory|null $trackFactory * @param SerializerInterface|null $serializer */ public function __construct( Action\Context $context, ShipmentLoader $shipmentLoader, ShipmentRepositoryInterface $shipmentRepository = null, - TrackFactory $trackFactory = null, + ShipmentTrackInterfaceFactory $trackFactory = null, SerializerInterface $serializer = null ) { parent::__construct($context); diff --git a/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/AddTrackTest.php b/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/AddTrackTest.php index cf3bf68e10416..1c9cdb1fa7d5b 100644 --- a/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/AddTrackTest.php +++ b/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/AddTrackTest.php @@ -6,127 +6,162 @@ namespace Magento\Shipping\Test\Unit\Controller\Adminhtml\Order\Shipment; -use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\Request\Http; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\App\ViewInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Framework\View\Element\BlockInterface; +use Magento\Framework\View\LayoutInterface; +use Magento\Framework\View\Page\Config; +use Magento\Framework\View\Page\Title; +use Magento\Framework\View\Result\Page; +use Magento\Sales\Api\Data\ShipmentTrackInterfaceFactory; +use Magento\Sales\Model\Order\Shipment; +use Magento\Sales\Model\Order\Shipment\Track; +use Magento\Shipping\Controller\Adminhtml\Order\Shipment\AddTrack; +use Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader; /** - * Class AddTrackTest + * Class AddTrackTest covers AddTrack controller. * - * @package Magento\Shipping\Controller\Adminhtml\Order\Shipment * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class AddTrackTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader|\PHPUnit_Framework_MockObject_MockObject + * @var ShipmentLoader|\PHPUnit_Framework_MockObject_MockObject */ - protected $shipmentLoader; + private $shipmentLoader; /** - * @var \Magento\Shipping\Controller\Adminhtml\Order\Shipment\AddTrack + * @var AddTrack */ - protected $controller; + private $controller; /** - * @var Action\Context|\PHPUnit_Framework_MockObject_MockObject + * @var Context|\PHPUnit_Framework_MockObject_MockObject */ - protected $context; + private $context; /** - * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject + * @var Http|\PHPUnit_Framework_MockObject_MockObject */ - protected $request; + private $request; /** - * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $response; + private $response; /** - * @var \Magento\Framework\ObjectManager\ObjectManager|\PHPUnit_Framework_MockObject_MockObject + * @var ViewInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $objectManager; + private $view; /** - * @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Page|\PHPUnit_Framework_MockObject_MockObject */ - protected $view; + private $resultPageMock; /** - * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + * @var Config|\PHPUnit_Framework_MockObject_MockObject */ - protected $resultPageMock; + private $pageConfigMock; /** - * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject + * @var Title|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageConfigMock; + private $pageTitleMock; /** - * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject + * @var ShipmentTrackInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageTitleMock; + private $trackFactory; + /** + * @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $rawResult; + + /** + * @inheritdoc + */ protected function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $this->shipmentLoader = $this->getMockBuilder( - \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::class + ShipmentLoader::class ) ->disableOriginalConstructor() ->setMethods(['setShipmentId', 'setOrderId', 'setShipment', 'setTracking', 'load']) ->getMock(); $this->context = $this->createPartialMock( - \Magento\Backend\App\Action\Context::class, + Context::class, [ 'getRequest', 'getResponse', 'getRedirect', 'getObjectManager', 'getTitle', - 'getView' + 'getView', + 'getResultFactory' ] ); $this->response = $this->createPartialMock( - \Magento\Framework\App\ResponseInterface::class, + ResponseInterface::class, ['setRedirect', 'sendResponse', 'setBody'] ); - $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) + $this->request = $this->getMockBuilder(Http::class) ->disableOriginalConstructor()->getMock(); - $this->objectManager = $this->createPartialMock( - \Magento\Framework\ObjectManager\ObjectManager::class, - ['create', 'get'] - ); - $this->view = $this->createMock(\Magento\Framework\App\ViewInterface::class); - $this->resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class) + $this->view = $this->createMock(ViewInterface::class); + $this->resultPageMock = $this->getMockBuilder(Page::class) ->disableOriginalConstructor() ->getMock(); - $this->pageConfigMock = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class) + $this->pageConfigMock = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); - $this->pageTitleMock = $this->getMockBuilder(\Magento\Framework\View\Page\Title::class) + $this->pageTitleMock = $this->getMockBuilder(Title::class) ->disableOriginalConstructor() ->getMock(); + $this->trackFactory = $this->getMockBuilder(ShipmentTrackInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMockForAbstractClass(); + $this->rawResult = $this->getMockBuilder(ResultInterface::class) + ->disableOriginalConstructor() + ->setMethods(['setContents']) + ->getMockForAbstractClass(); + $resultFactory = $this->getMockBuilder(ResultFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMockForAbstractClass(); $this->context->expects($this->once()) ->method('getRequest') ->will($this->returnValue($this->request)); $this->context->expects($this->once()) ->method('getResponse') ->will($this->returnValue($this->response)); - $this->context->expects($this->once()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManager)); $this->context->expects($this->once()) ->method('getView') ->will($this->returnValue($this->view)); + $resultFactory->expects($this->once()) + ->method('create') + ->willReturn($this->rawResult); + $this->context->expects($this->once()) + ->method('getResultFactory') + ->willReturn($resultFactory); $this->controller = $objectManagerHelper->getObject( - \Magento\Shipping\Controller\Adminhtml\Order\Shipment\AddTrack::class, + AddTrack::class, [ 'context' => $this->context, 'shipmentLoader' => $this->shipmentLoader, 'request' => $this->request, 'response' => $this->response, - 'view' => $this->view + 'view' => $this->view, + 'trackFactory' => $this->trackFactory, ] ); } @@ -144,7 +179,7 @@ public function testExecute() $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->createPartialMock( - \Magento\Sales\Model\Order\Shipment::class, + Shipment::class, ['addTrack', '__wakeup', 'save'] ); $this->request->expects($this->any()) @@ -152,8 +187,10 @@ public function testExecute() ->will( $this->returnValueMap( [ - ['order_id', null, $orderId], ['shipment_id', null, $shipmentId], - ['shipment', null, $shipmentData], ['tracking', null, $tracking], + ['order_id', null, $orderId], + ['shipment_id', null, $shipmentId], + ['shipment', null, $shipmentData], + ['tracking', null, $tracking], ] ) ); @@ -183,14 +220,13 @@ public function testExecute() $this->shipmentLoader->expects($this->once()) ->method('load') ->will($this->returnValue($shipment)); - $track = $this->getMockBuilder(\Magento\Sales\Model\Order\Shipment\Track::class) + $track = $this->getMockBuilder(Track::class) ->disableOriginalConstructor() ->setMethods(['__wakeup', 'setNumber', 'setCarrierCode', 'setTitle']) ->getMock(); - $this->objectManager->expects($this->atLeastOnce()) + $this->trackFactory->expects($this->once()) ->method('create') - ->with(\Magento\Sales\Model\Order\Shipment\Track::class) - ->will($this->returnValue($track)); + ->willReturn($track); $track->expects($this->once()) ->method('setNumber') ->with($number) @@ -206,8 +242,8 @@ public function testExecute() $this->view->expects($this->once()) ->method('loadLayout') ->will($this->returnSelf()); - $layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class); - $menuBlock = $this->createPartialMock(\Magento\Framework\View\Element\BlockInterface::class, ['toHtml']); + $layout = $this->createMock(LayoutInterface::class); + $menuBlock = $this->createPartialMock(BlockInterface::class, ['toHtml']); $html = 'html string'; $this->view->expects($this->once()) ->method('getLayout') @@ -235,9 +271,10 @@ public function testExecute() $this->pageConfigMock->expects($this->any()) ->method('getTitle') ->willReturn($this->pageTitleMock); - $this->response->expects($this->once()) - ->method('setBody') - ->with($html); - $this->assertNull($this->controller->execute()); + $this->rawResult->expects($this->once()) + ->method('setContents') + ->with($html) + ->willReturnSelf(); + $this->assertInstanceOf(ResultInterface::class, $this->controller->execute()); } } From 6f8d99c750e7aeab547a1d6f34e2d9f7df0be505 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky <firster@atwix.com> Date: Wed, 20 Mar 2019 18:04:53 +0200 Subject: [PATCH 54/80] 281 - [Shipping methods] Support of UPS shipping method 1. Test coverage for UPS "Ground" method --- .../Ups/SetUpsShippingMethodsOnCartTest.php | 147 ++++++++++++++++++ .../Ups/_files/enable_ups_shipping_method.php | 20 +++ .../enable_ups_shipping_method_rollback.php | 16 ++ 3 files changed, 183 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php create mode 100644 dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php new file mode 100644 index 0000000000000..ed2e73946b528 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -0,0 +1,147 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\GraphQl\Ups; + +use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\TestCase\GraphQlAbstract; + +/** + * Test for setting offline shipping methods on cart + */ +class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract +{ + /** + * Defines carrier code for "UPS" shipping method + */ + const CARRIER_CODE = 'ups'; + + /** + * Defines method code for the "Ground" UPS shipping + */ + const CARRIER_METHOD_CODE_GROUND = 'GND'; + + /** + * @var QuoteFactory + */ + private $quoteFactory; + + /** + * @var CustomerTokenServiceInterface + */ + private $customerTokenService; + + /** + * @var QuoteResource + */ + private $quoteResource; + + /** + * @var QuoteIdToMaskedQuoteIdInterface + */ + private $quoteIdToMaskedId; + + /** + * @inheritdoc + */ + protected function setUp() + { + $objectManager = Bootstrap::getObjectManager(); + $this->quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php + */ + public function testSetUpsShippingMethod() + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id'); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); + $shippingAddressId = (int)$quote->getShippingAddress()->getId(); + + $query = $this->getAddUpsShippingMethodQuery( + $maskedQuoteId, + $shippingAddressId, + self::CARRIER_CODE, + self::CARRIER_METHOD_CODE_GROUND + ); + + $response = $this->sendRequestWithToken($query); + $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; + $expectedResult = [ + 'carrier_code' => self::CARRIER_CODE, + 'method_code' => self::CARRIER_METHOD_CODE_GROUND, + 'label' => 'United Parcel Service - Ground', + ]; + self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); + } + + /** + * Generates query for setting the specified shipping method on cart + * + * @param int $shippingAddressId + * @param string $maskedQuoteId + * @param string $carrierCode + * @param string $methodCode + * @return string + */ + private function getAddUpsShippingMethodQuery( + string $maskedQuoteId, + int $shippingAddressId, + string $carrierCode, + string $methodCode + ): string { + return <<<QUERY +mutation { + setShippingMethodsOnCart(input: { + cart_id: "$maskedQuoteId" + shipping_methods: [ + { + cart_address_id: $shippingAddressId + carrier_code: "$carrierCode" + method_code: "$methodCode" + } + ] + }) { + cart { + shipping_addresses { + selected_shipping_method { + carrier_code + method_code + label + } + } + } + } +} +QUERY; + } + + /** + * Sends a GraphQL request with using a bearer token + * + * @param string $query + * @return array + * @throws \Magento\Framework\Exception\AuthenticationException + */ + private function sendRequestWithToken(string $query): array + { + $customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + + return $this->graphQlQuery($query, [], '', $headerMap); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php b/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php new file mode 100644 index 0000000000000..5c6c60866fafb --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Framework\App\Config\Storage\Writer; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Config\ScopeConfigInterface; + +$objectManager = Bootstrap::getObjectManager(); +/** @var Writer $configWriter */ +$configWriter = $objectManager->get(WriterInterface::class); + +$configWriter->save('carriers/ups/active', 1); + +$scopeConfig = $objectManager->get(ScopeConfigInterface::class); +$scopeConfig->clean(); diff --git a/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php b/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php new file mode 100644 index 0000000000000..6d7894879f97b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php @@ -0,0 +1,16 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Framework\App\Config\Storage\Writer; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); +/** @var Writer $configWriter */ +$configWriter = $objectManager->create(WriterInterface::class); + +$configWriter->delete('carriers/ups/active'); From 30a2a80802afe5df8c81e948f2c1db4e2ce969b9 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky <firster@atwix.com> Date: Wed, 20 Mar 2019 18:58:51 +0200 Subject: [PATCH 55/80] magento/graphql-ce#281: [Shipping methods] Support of UPS shipping method --- .../Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index ed2e73946b528..af85b616be696 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -15,7 +15,7 @@ use Magento\TestFramework\TestCase\GraphQlAbstract; /** - * Test for setting offline shipping methods on cart + * Test for setting "UPS" shipping method on cart */ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract { From ef3cc3634fcf4d03030e50e8627a23ccd718b60e Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun <i.gryshkun@gmail.com> Date: Thu, 21 Mar 2019 08:12:17 +0200 Subject: [PATCH 56/80] Missing key model in Wishlist value data --- .../Model/Resolver/WishlistResolver.php | 5 ++++ .../Magento/GraphQl/Wishlist/WishlistTest.php | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php index e3a788af2ea7e..792928ab61aaf 100644 --- a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php +++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php @@ -13,6 +13,7 @@ use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel; use Magento\Wishlist\Model\Wishlist; use Magento\Wishlist\Model\WishlistFactory; +use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; /** * Fetches the Wishlist data according to the GraphQL schema @@ -51,6 +52,10 @@ public function resolve( ) { $customerId = $context->getUserId(); + /* Guest checking */ + if (!$customerId && 0 === $customerId) { + throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist')); + } /** @var Wishlist $wishlist */ $wishlist = $this->wishlistFactory->create(); $this->wishlistResource->load($wishlist, $customerId, 'customer_id'); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/WishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/WishlistTest.php index d570fc09b7714..4aac5d9445934 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/WishlistTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/WishlistTest.php @@ -93,6 +93,36 @@ public function testGetCustomerWishlist(): void $this->assertEquals($wishlistItemProduct->getName(), $response['wishlist']['items'][0]['product']['name']); } + /** + * @expectedException \Exception + * @expectedExceptionMessage The current user cannot perform operations on wishlist + */ + public function testGetGuestWishlist() + { + $query = + <<<QUERY +{ + wishlist { + items_count + name + sharing_code + updated_at + items { + id + qty + description + added_at + product { + sku + name + } + } + } +} +QUERY; + $this->graphQlQuery($query); + } + /** * @param string $email * @param string $password From a8d9be1c4f617a3ff0312f433f080b67b41ed3b6 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky <p.bystritsky@yandex.ru> Date: Thu, 21 Mar 2019 16:04:29 +0200 Subject: [PATCH 57/80] ENGCOM-4357: Static tests fix. --- .../Model/Products/AdaptUrlRewritesToVisibilityAttribute.php | 3 ++- .../ProcessUrlRewriteOnChangeVisibilityObserverTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php index cf1a7ec76f016..f5851cf1e11b1 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php @@ -92,7 +92,8 @@ public function execute(array $productIds, int $visibility): void } catch (UrlAlreadyExistsException $e) { throw new UrlAlreadyExistsException( __( - 'Can not change the visibility of the product with SKU equals "%1". URL key "%2" for specified store already exists.', + 'Can not change the visibility of the product with SKU equals "%1". ' + . 'URL key "%2" for specified store already exists.', $product->getSku(), $product->getUrlKey() ), diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php index af9979309078f..d3f0e9fa2a5ab 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php @@ -160,7 +160,8 @@ public function testErrorOnDuplicatedUrlKey() $productIds[] = $this->productRepository->get($sku)->getId(); } $this->expectException(UrlAlreadyExistsException::class); - $this->expectExceptionMessage('Can not change the visibility of the product with SKU equals "product2". URL key "product-1" for specified store already exists.'); + $this->expectExceptionMessage('Can not change the visibility of the product with SKU equals "product2". ' + . 'URL key "product-1" for specified store already exists.'); $this->eventManager->dispatch( 'catalog_product_attribute_update_before', From b7e67007bcf62a1cd41a2d8039cb72709eb311ee Mon Sep 17 00:00:00 2001 From: Veronika Kurochkina <veronika_kurochkina@epam.com> Date: Thu, 21 Mar 2019 19:01:36 +0300 Subject: [PATCH 58/80] MAGETWO-51459: [FT] CreateCategoryEntityTest fail when system message about indexers update is displayed - Skip flaky MFTF test AdminCreateCustomProductAttributeWithDropdownFieldTest --- .../AdminCreateCustomProductAttributeWithDropdownFieldTest.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCustomProductAttributeWithDropdownFieldTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCustomProductAttributeWithDropdownFieldTest.xml index 5b6a0b7f2ab3e..288941e487646 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCustomProductAttributeWithDropdownFieldTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCustomProductAttributeWithDropdownFieldTest.xml @@ -16,6 +16,9 @@ <severity value="CRITICAL"/> <testCaseId value="MC-10905"/> <group value="mtf_migrated"/> + <skip> + <issueId value="MC-15474"/> + </skip> </annotations> <before> From dd80c0c53d3b2993a9de918665dc63606cfbc5eb Mon Sep 17 00:00:00 2001 From: Jeroen <jeroen@reachdigital.nl> Date: Thu, 21 Mar 2019 17:26:51 +0100 Subject: [PATCH 59/80] Remove strict return type --- .../Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php index 4ec7117783aab..c417a202321b2 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddTrack.php @@ -80,7 +80,7 @@ public function __construct( * * @return ResultInterface */ - public function execute(): ResultInterface + public function execute() { try { $carrier = $this->getRequest()->getPost('carrier'); From b96435f8d213f5de0eb8352e2e4fd1d1e117895f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Deg=C3=B3rski?= <kamil.degorski@snow.dog> Date: Thu, 21 Mar 2019 20:00:07 +0100 Subject: [PATCH 60/80] magento/magento2#21001 - fix unit tests, by passing currency to number formatter, then it behaves as was expected in test. --- .../Framework/Locale/Test/Unit/FormatTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php index 1141f451c13a5..526702afb87be 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php @@ -68,15 +68,17 @@ protected function setUp() /** * @param string $localeCode + * @param string $currencyCode * @param array $expectedResult * @dataProvider getPriceFormatDataProvider */ - public function testGetPriceFormat($localeCode, array $expectedResult): void + public function testGetPriceFormat($localeCode, $currencyCode, array $expectedResult): void { $this->scope->expects($this->once()) ->method('getCurrentCurrency') ->willReturn($this->currency); + $this->currency->method('getCode')->willReturn($currencyCode); $result = $this->formatModel->getPriceFormat($localeCode); $intersection = array_intersect_assoc($result, $expectedResult); $this->assertCount(count($expectedResult), $intersection); @@ -89,17 +91,17 @@ public function testGetPriceFormat($localeCode, array $expectedResult): void public function getPriceFormatDataProvider(): array { return [ - ['en_US', ['decimalSymbol' => '.', 'groupSymbol' => ',']], - ['de_DE', ['decimalSymbol' => ',', 'groupSymbol' => '.']], - ['de_CH', ['decimalSymbol' => '.', 'groupSymbol' => '\'']], - ['uk_UA', ['decimalSymbol' => ',', 'groupSymbol' => ' ']] + ['en_US', 'USD', ['decimalSymbol' => '.', 'groupSymbol' => ',']], + ['de_DE', 'EUR', ['decimalSymbol' => ',', 'groupSymbol' => '.']], + ['de_CH', 'CHF', ['decimalSymbol' => '.', 'groupSymbol' => '’']], + ['uk_UA', 'UAH', ['decimalSymbol' => ',', 'groupSymbol' => ' ']] ]; } /** * - * @param mixed $value - * @param float $expected + * @param mixed $value + * @param float $expected * @dataProvider provideNumbers */ public function testGetNumber($value, $expected): void From e0248ea3ce6416c9fea185a958278dd7bda1a951 Mon Sep 17 00:00:00 2001 From: AlexandrKozyr <kozyr1av@gmail.com> Date: Thu, 21 Mar 2019 22:14:48 +0000 Subject: [PATCH 61/80] [+] added tests for SetPaymentMethodOnCart functionality --- .../Model/Resolver/SetPaymentMethodOnCart.php | 4 +- .../Customer/SetPaymentMethodOnCartTest.php | 48 +++++++++++++++++++ .../Guest/SetPaymentMethodOnCartTest.php | 47 ++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php index a93c8032c996a..d1dcb4a48a76b 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php @@ -60,12 +60,12 @@ public function __construct( public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) { - throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); + throw new GraphQlInputException(__('Required parameter "cart_id" is missing.')); } $maskedCartId = $args['input']['cart_id']; if (!isset($args['input']['payment_method']['code']) || empty($args['input']['payment_method']['code'])) { - throw new GraphQlInputException(__('Required parameter "payment_method" is missing')); + throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.')); } $paymentMethodCode = $args['input']['payment_method']['code']; diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php index c7da2144adb9e..dc970c3ab5893 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -171,6 +171,54 @@ public function testPaymentMethodOnNonExistentCart() $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @param string $input + * @param string $message + * @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters + */ + public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message) + { + $query = <<<QUERY +mutation { + setPaymentMethodOnCart( + input: { + {$input} + } + ) { + cart { + items { + qty + } + } + } +} +QUERY; + $this->expectExceptionMessage($message); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + /** + * @return array + */ + public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array + { + return [ + 'missed_cart_id' => [ + 'payment_method: {code: "'.Checkmo::PAYMENT_METHOD_CHECKMO_CODE.'"}', + 'Required parameter "cart_id" is missing.' + ], + 'missed_payment_method' => [ + 'cart_id: "test"', + 'Required parameter "code" for "payment_method" is missing.' + ], + 'missed_payment_method_code' => [ + 'cart_id: "test",payment_method: {code: ""}', + 'Required parameter "code" for "payment_method" is missing.' + ], + ]; + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php */ diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index 182bbaf618505..6b6bf04b837dd 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -126,6 +126,53 @@ public function testSetPaymentMethodToCustomerCart() $this->graphQlQuery($query); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @param string $input + * @param string $message + * @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters + */ + public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message) + { + $query = <<<QUERY +mutation { + setPaymentMethodOnCart( + input: { + {$input} + } + ) { + cart { + items { + qty + } + } + } +} +QUERY; + $this->expectExceptionMessage($message); + $this->graphQlQuery($query); + } + /** + * @return array + */ + public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array + { + return [ + 'missed_cart_id' => [ + 'payment_method: {code: "'.Checkmo::PAYMENT_METHOD_CHECKMO_CODE.'"}', + 'Required parameter "cart_id" is missing.' + ], + 'missed_payment_method' => [ + 'cart_id: "test"', + 'Required parameter "code" for "payment_method" is missing.' + ], + 'missed_payment_method_code' => [ + 'cart_id: "test",payment_method: {code: ""}', + 'Required parameter "code" for "payment_method" is missing.' + ], + ]; + } + /** * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" From 8d7b964943eae2996e9542dbfcef87e1044df825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Deg=C3=B3rski?= <kamil.degorski@snow.dog> Date: Thu, 21 Mar 2019 23:58:25 +0100 Subject: [PATCH 62/80] magento/magento2#21001 - fix unit tests, by passing currency to number formatter, then it behaves as was expected in test. --- lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php index 526702afb87be..d5297b1d0c613 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php @@ -93,7 +93,7 @@ public function getPriceFormatDataProvider(): array return [ ['en_US', 'USD', ['decimalSymbol' => '.', 'groupSymbol' => ',']], ['de_DE', 'EUR', ['decimalSymbol' => ',', 'groupSymbol' => '.']], - ['de_CH', 'CHF', ['decimalSymbol' => '.', 'groupSymbol' => '’']], + ['de_CH', 'CHF', ['decimalSymbol' => '.', 'groupSymbol' => '\'']], ['uk_UA', 'UAH', ['decimalSymbol' => ',', 'groupSymbol' => ' ']] ]; } From 57c4db41be4281541fc0745bcfd4f6cbca64ef86 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky <p.bystritsky@yandex.ru> Date: Fri, 22 Mar 2019 10:32:50 +0200 Subject: [PATCH 63/80] ENGCOM-4302: Backward compatibility fix. --- .../Model/ResourceModel/Order/Collection.php | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php index 33dfdcffc9a48..f5e73e2cdff27 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php @@ -769,7 +769,7 @@ public function addOrdersCount() */ public function addRevenueToSelect($convertCurrency = false) { - $expr = $this->getTotalsExpression( + $expr = $this->getTotalsExpressionWithDiscountRefunded( !$convertCurrency, $this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0), @@ -792,7 +792,7 @@ public function addSumAvgTotals($storeId = 0) /** * calculate average and total amount */ - $expr = $this->getTotalsExpression( + $expr = $this->getTotalsExpressionWithDiscountRefunded( $storeId, $this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0), $this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0), @@ -810,16 +810,40 @@ public function addSumAvgTotals($storeId = 0) } /** - * Get SQL expression for totals + * Get SQL expression for totals. * * @param int $storeId * @param string $baseSubtotalRefunded * @param string $baseSubtotalCanceled - * @param string $baseDiscountRefunded * @param string $baseDiscountCanceled * @return string + * @deprecated + * @see getTotalsExpressionWithDiscountRefunded */ protected function getTotalsExpression( + $storeId, + $baseSubtotalRefunded, + $baseSubtotalCanceled, + $baseDiscountCanceled + ) { + $template = ($storeId != 0) + ? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)' + : '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) ' + . ' * main_table.base_to_global_rate)'; + return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled); + } + + /** + * Get SQL expression for totals with discount refunded. + * + * @param int $storeId + * @param string $baseSubtotalRefunded + * @param string $baseSubtotalCanceled + * @param string $baseDiscountRefunded + * @param string $baseDiscountCanceled + * @return string + */ + private function getTotalsExpressionWithDiscountRefunded( $storeId, $baseSubtotalRefunded, $baseSubtotalCanceled, From 3be8ecad58e10017f63f1bb727352719c5814f02 Mon Sep 17 00:00:00 2001 From: Dmytro Cheshun <d.cheshun@atwix.com> Date: Fri, 22 Mar 2019 13:40:26 +0200 Subject: [PATCH 64/80] Exclude htaccess form gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8a15fbacaf638..8ec1104f25535 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ atlassian* !/pub/media/import/.htaccess /pub/media/logo/* /pub/media/custom_options/* +!/pub/media/custom_options/.htaccess /pub/media/theme/* /pub/media/theme_customization/* !/pub/media/theme_customization/.htaccess From 6fba6865685a41753fce0631bc9461e6632df8c9 Mon Sep 17 00:00:00 2001 From: nmalevanec <mikola.malevanec@transoftgroup.com> Date: Fri, 22 Mar 2019 14:09:49 +0200 Subject: [PATCH 65/80] Fix functional test. --- app/code/Magento/Multishipping/view/frontend/web/js/overview.js | 2 +- .../Test/Page/MultishippingCheckoutOverview.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Multishipping/view/frontend/web/js/overview.js b/app/code/Magento/Multishipping/view/frontend/web/js/overview.js index 9b867cd7217b1..3a6d73e304974 100644 --- a/app/code/Magento/Multishipping/view/frontend/web/js/overview.js +++ b/app/code/Magento/Multishipping/view/frontend/web/js/overview.js @@ -15,7 +15,7 @@ define([ opacity: 0.5, // CSS opacity for the 'Place Order' button when it's clicked and then disabled. pleaseWaitLoader: 'span.please-wait', // 'Submitting order information...' Ajax loader. placeOrderSubmit: 'button[type="submit"]', // The 'Place Order' button. - agreements: '#checkout-agreements' // Container for all of the checkout agreements and terms/conditions + agreements: '.checkout-agreements' // Container for all of the checkout agreements and terms/conditions }, /** diff --git a/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Page/MultishippingCheckoutOverview.xml b/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Page/MultishippingCheckoutOverview.xml index d304d305a7265..a266b09278ddb 100644 --- a/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Page/MultishippingCheckoutOverview.xml +++ b/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Page/MultishippingCheckoutOverview.xml @@ -7,6 +7,6 @@ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd"> <page name="MultishippingCheckoutOverview" mca="multishipping/checkout/overview" module="Magento_Checkout"> - <block name="agreementReview" class="Magento\CheckoutAgreements\Test\Block\Multishipping\MultishippingAgreementReview" locator="#checkout-agreements" strategy="css selector"/> + <block name="agreementReview" class="Magento\CheckoutAgreements\Test\Block\Multishipping\MultishippingAgreementReview" locator=".checkout-agreements" strategy="css selector"/> </page> </config> From c58655ee7a12d38ac37440c19e716568fe92a662 Mon Sep 17 00:00:00 2001 From: Yuliya Labudova <Yuliya_Labudova@epam.com> Date: Fri, 22 Mar 2019 15:36:22 +0300 Subject: [PATCH 66/80] MAGETWO-44165: Magento\Catalog\Test\TestCase\Product\ProductTypeSwitchingOnCreationTest fails - Fix comments --- .../Mftf/Test/AdminCreateAndSwitchProductType.xml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml index 50c17cfc4b9ab..3a40bd6661ffe 100755 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml @@ -87,6 +87,7 @@ <title value="Admin should be able to switch a new product from simple to configurable"/> <description value="After selecting a simple product when adding Admin should be switch to configurable implicitly"/> <severity value="CRITICAL"/> + <useCaseId value="MAGETWO-44165"/> <testCaseId value="MAGETWO-29398"/> <group value="catalog"/> <group value="mtf_migrated"/> @@ -103,6 +104,8 @@ <actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="openProductFillForm"> <argument name="productType" value="simple"/> </actionGroup> + <!-- Create configurable product from simple product page--> + <comment userInput="Create configurable product" stepKey="commentCreateProduct"/> <actionGroup ref="fillMainProductForm" stepKey="fillProductForm"> <argument name="product" value="_defaultProduct"/> </actionGroup> @@ -112,6 +115,8 @@ </actionGroup> <actionGroup ref="saveConfiguredProduct" stepKey="saveProductForm"/> <see selector="{{AdminProductGridSection.productGridCell('2', 'Type')}}" userInput="Configurable Product" stepKey="seeProductTypeInGrid"/> + <!-- Verify product on store front --> + <comment userInput="Verify product on store front" stepKey="commentVerifyProductGrid"/> <actionGroup ref="VerifyOptionInProductStorefront" stepKey="verifyConfigurableOption" after="AssertProductInStorefrontProductPage"> <argument name="attributeCode" value="$createConfigProductAttribute.default_frontend_label$"/> <argument name="optionName" value="$createConfigProductAttributeOption1.option[store_labels][1][label]$"/> @@ -124,6 +129,7 @@ <title value="Admin should be able to switch a new product from downloadable to configurable"/> <description value="After selecting a downloadable product when adding Admin should be switch to configurable implicitly"/> <severity value="CRITICAL"/> + <useCaseId value="MAGETWO-44165"/> <testCaseId value="MAGETWO-29398"/> <group value="catalog"/> <group value="mtf_migrated"/> @@ -145,18 +151,16 @@ <deleteData stepKey="deleteAttribute" createDataKey="createConfigProductAttribute"/> <actionGroup ref="logout" stepKey="logout"/> </after> - + <!-- Create configurable product from downloadable product page--> + <comment userInput="Create configurable product" stepKey="commentCreateProduct"/> <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/> <!-- Open Dropdown and select downloadable product option --> <comment stepKey="beforeOpenProductFillForm" userInput="Selecting Product from the Add Product Dropdown"/> <actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="openProductFillForm"> <argument name="productType" value="downloadable"/> </actionGroup> - <scrollTo selector="{{AdminProductDownloadableSection.sectionHeader}}" stepKey="scrollToDownloadableInfo" /> - <wait stepKey="2" time="3"/> <uncheckOption selector="{{AdminProductDownloadableSection.isDownloadableProduct}}" stepKey="checkIsDownloadable"/> - <!-- Fill form for Downloadable Product Type --> <comment stepKey="beforeFillProductForm" userInput="Filling Product Form"/> <actionGroup ref="fillMainProductForm" stepKey="fillProductForm"> @@ -178,7 +182,7 @@ <argument name="product" value="_defaultProduct"/> </actionGroup> <see selector="{{AdminProductGridSection.productGridCell('2', 'Type')}}" userInput="Configurable Product" stepKey="seeProductTypeInGrid"/> - <actionGroup ref="AssertProductInStorefrontProductPage" stepKey="AssertProductInStorefrontProductPage"> + <actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefrontProductPage"> <argument name="product" value="_defaultProduct"/> </actionGroup> <actionGroup ref="VerifyOptionInProductStorefront" stepKey="verifyConfigurableOption"> From 3825545a5dfa1ddc7ae2193ff03e4e54e0c12f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Deg=C3=B3rski?= <kamil.degorski@snow.dog> Date: Fri, 22 Mar 2019 16:06:48 +0100 Subject: [PATCH 67/80] magento/magento2#21001 - make swiss group sympbol icu version dependent --- lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php index d5297b1d0c613..73a029a5a1411 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php @@ -90,10 +90,11 @@ public function testGetPriceFormat($localeCode, $currencyCode, array $expectedRe */ public function getPriceFormatDataProvider(): array { + $swissGroupSymbol = INTL_ICU_VERSION >= 59.1 ? '’' : '\''; return [ ['en_US', 'USD', ['decimalSymbol' => '.', 'groupSymbol' => ',']], ['de_DE', 'EUR', ['decimalSymbol' => ',', 'groupSymbol' => '.']], - ['de_CH', 'CHF', ['decimalSymbol' => '.', 'groupSymbol' => '\'']], + ['de_CH', 'CHF', ['decimalSymbol' => '.', 'groupSymbol' => $swissGroupSymbol]], ['uk_UA', 'UAH', ['decimalSymbol' => ',', 'groupSymbol' => ' ']] ]; } From 6e80c692bdd0e7af35e4aee738923edf083559d3 Mon Sep 17 00:00:00 2001 From: Javier Villanueva <javier@medialounge.co.uk> Date: Fri, 22 Mar 2019 15:54:05 +0000 Subject: [PATCH 68/80] Trigger contentUpdate on reviews load --- app/code/Magento/Review/view/frontend/web/js/process-reviews.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Review/view/frontend/web/js/process-reviews.js b/app/code/Magento/Review/view/frontend/web/js/process-reviews.js index d1c40959e3ec2..88c61fa38af34 100644 --- a/app/code/Magento/Review/view/frontend/web/js/process-reviews.js +++ b/app/code/Magento/Review/view/frontend/web/js/process-reviews.js @@ -20,7 +20,7 @@ define([ showLoader: false, loaderContext: $('.product.data.items') }).done(function (data) { - $('#product-review-container').html(data); + $('#product-review-container').html(data).trigger('contentUpdated'); $('[data-role="product-review"] .pages a').each(function (index, element) { $(element).click(function (event) { //eslint-disable-line max-nested-callbacks processReviews($(element).attr('href'), true); From 44ddbab42b47a16bf3f1491a5658c2ba255c81cf Mon Sep 17 00:00:00 2001 From: nmalevanec <mikola.malevanec@transoftgroup.com> Date: Mon, 25 Mar 2019 11:28:02 +0200 Subject: [PATCH 69/80] Fix functional test. --- .../tests/app/Magento/Review/Test/TestCase/NavigateMenuTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Review/Test/TestCase/NavigateMenuTest.xml b/dev/tests/functional/tests/app/Magento/Review/Test/TestCase/NavigateMenuTest.xml index 8445a21604cdd..4d96ebd2edbe3 100644 --- a/dev/tests/functional/tests/app/Magento/Review/Test/TestCase/NavigateMenuTest.xml +++ b/dev/tests/functional/tests/app/Magento/Review/Test/TestCase/NavigateMenuTest.xml @@ -8,7 +8,7 @@ <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> <testCase name="Magento\Backend\Test\TestCase\NavigateMenuTest"> <variation name="NavigateMenuTest70"> - <data name="menuItem" xsi:type="string">Marketing > Reviews</data> + <data name="menuItem" xsi:type="string">Marketing > All Reviews</data> <data name="pageTitle" xsi:type="string">Reviews</data> <constraint name="Magento\Backend\Test\Constraint\AssertBackendPageIsAvailable"/> </variation> From 6f2c98b7b19368f7d5e4a19f9b0bff1d5b5f430a Mon Sep 17 00:00:00 2001 From: Ivan Gerchak <ivang@ven.com> Date: Mon, 25 Mar 2019 12:40:52 +0200 Subject: [PATCH 70/80] Change event "mouseup" to "mousedown" --- lib/web/mage/gallery/gallery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/mage/gallery/gallery.js b/lib/web/mage/gallery/gallery.js index db98a1cc39a30..c20329c0ce63d 100644 --- a/lib/web/mage/gallery/gallery.js +++ b/lib/web/mage/gallery/gallery.js @@ -141,7 +141,7 @@ define([ this.setupBreakpoints(); this.initFullscreenSettings(); - this.settings.$element.on('mouseup', '.fotorama__stage__frame', function () { + this.settings.$element.on('mousedown', '.fotorama__stage__frame', function () { if ( !$(this).parents('.fotorama__shadows--left, .fotorama__shadows--right').length && !$(this).hasClass('fotorama-video-container') From 59771c40c1a2aa857d3b64b0905aa67c1705a1c9 Mon Sep 17 00:00:00 2001 From: nmalevanec <mikola.malevanec@transoftgroup.com> Date: Mon, 25 Mar 2019 14:58:00 +0200 Subject: [PATCH 71/80] Fix static tests. --- .../Magento/Quote/Model/QuoteManagement.php | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index e1058c98271c1..2fcfd2dfadabb 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -532,28 +532,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) ); $this->quoteRepository->save($quote); } catch (\Exception $e) { - try { - if (!empty($this->addressesToSync)) { - foreach ($this->addressesToSync as $addressId) { - $this->addressRepository->deleteById($addressId); - } - } - $this->eventManager->dispatch( - 'sales_model_service_quote_submit_failure', - [ - 'order' => $order, - 'quote' => $quote, - 'exception' => $e, - ] - ); - } catch (\Exception $consecutiveException) { - $message = sprintf( - "An exception occurred on 'sales_model_service_quote_submit_failure' event: %s", - $consecutiveException->getMessage() - ); - - throw new \Exception($message, 0, $e); - } + $this->rollbackAddresses($quote, $order, $e); throw $e; } return $order; @@ -620,4 +599,41 @@ protected function _prepareCustomerQuote($quote) $shipping->setIsDefaultBilling(true); } } + + /** + * Remove related to order and quote addresses and submit exception to further processing. + * + * @param Quote $quote + * @param \Magento\Sales\Api\Data\OrderInterface $order + * @param \Exception $e + * @throws \Exception + */ + private function rollbackAddresses( + QuoteEntity $quote, + \Magento\Sales\Api\Data\OrderInterface $order, + \Exception $e + ): void { + try { + if (!empty($this->addressesToSync)) { + foreach ($this->addressesToSync as $addressId) { + $this->addressRepository->deleteById($addressId); + } + } + $this->eventManager->dispatch( + 'sales_model_service_quote_submit_failure', + [ + 'order' => $order, + 'quote' => $quote, + 'exception' => $e, + ] + ); + } catch (\Exception $consecutiveException) { + $message = sprintf( + "An exception occurred on 'sales_model_service_quote_submit_failure' event: %s", + $consecutiveException->getMessage() + ); + + throw new \Exception($message, 0, $e); + } + } } From b7dd71842d576faabf07c10b4cbac6436ee6aca9 Mon Sep 17 00:00:00 2001 From: Yuliya Labudova <Yuliya_Labudova@epam.com> Date: Mon, 25 Mar 2019 17:39:01 +0300 Subject: [PATCH 72/80] MAGETWO-44165: Magento\Catalog\Test\TestCase\Product\ProductTypeSwitchingOnCreationTest fails - Skip tests till the next MSI release --- .../Test/Mftf/Test/AdminCreateAndSwitchProductType.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml index 3a40bd6661ffe..93df31a7d89e5 100755 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCreateAndSwitchProductType.xml @@ -53,6 +53,9 @@ <testCaseId value="MC-10930"/> <group value="catalog"/> <group value="mtf_migrated"/> + <skip> + <issueId value="MSI-2110"/> + </skip> </annotations> <before> <createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/> @@ -91,6 +94,9 @@ <testCaseId value="MAGETWO-29398"/> <group value="catalog"/> <group value="mtf_migrated"/> + <skip> + <issueId value="MSI-2110"/> + </skip> </annotations> <before> <createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/> @@ -133,6 +139,9 @@ <testCaseId value="MAGETWO-29398"/> <group value="catalog"/> <group value="mtf_migrated"/> + <skip> + <issueId value="MSI-2110"/> + </skip> </annotations> <before> <createData entity="_defaultCategory" stepKey="createPreReqCategory"/> From 73088cdba04c5783165c0f2a7c20bae78c370ec2 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Mon, 25 Mar 2019 13:17:47 -0500 Subject: [PATCH 73/80] GraphQL-281: [Shipping methods] Support of UPS shipping method --- .../Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php index af85b616be696..463f2c4af101f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php @@ -83,8 +83,8 @@ public function testSetUpsShippingMethod() $addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; $expectedResult = [ 'carrier_code' => self::CARRIER_CODE, - 'method_code' => self::CARRIER_METHOD_CODE_GROUND, - 'label' => 'United Parcel Service - Ground', + 'method_code' => self::CARRIER_METHOD_CODE_GROUND, + 'label' => 'United Parcel Service - Ground', ]; self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult); } From 5aa062cb4801d4311ddcde2c59b63c2f4dc16e49 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Mon, 25 Mar 2019 13:33:16 -0500 Subject: [PATCH 74/80] GraphQL-483: [Test Coverage] 'SetPaymentMethodOnCart' functionality --- .../GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php | 4 ++-- .../GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php index dc970c3ab5893..51c48f5041dd9 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -205,7 +205,7 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array { return [ 'missed_cart_id' => [ - 'payment_method: {code: "'.Checkmo::PAYMENT_METHOD_CHECKMO_CODE.'"}', + 'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}', 'Required parameter "cart_id" is missing.' ], 'missed_payment_method' => [ @@ -213,7 +213,7 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array 'Required parameter "code" for "payment_method" is missing.' ], 'missed_payment_method_code' => [ - 'cart_id: "test",payment_method: {code: ""}', + 'cart_id: "test", payment_method: {code: ""}', 'Required parameter "code" for "payment_method" is missing.' ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index 6b6bf04b837dd..017b85ba17b93 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -159,7 +159,7 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array { return [ 'missed_cart_id' => [ - 'payment_method: {code: "'.Checkmo::PAYMENT_METHOD_CHECKMO_CODE.'"}', + 'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}', 'Required parameter "cart_id" is missing.' ], 'missed_payment_method' => [ @@ -167,7 +167,7 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array 'Required parameter "code" for "payment_method" is missing.' ], 'missed_payment_method_code' => [ - 'cart_id: "test",payment_method: {code: ""}', + 'cart_id: "test", payment_method: {code: ""}', 'Required parameter "code" for "payment_method" is missing.' ], ]; From 18cafdc0aaee73fe6320e0ad8e736d563d40ca51 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Mon, 25 Mar 2019 15:55:34 -0500 Subject: [PATCH 75/80] GraphQL-482: [Test Coverage] 'SetBillingAddressOnCart' functionality --- .../GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php | 3 ++- .../GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 02cd428767ccc..f79e6b8211b00 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -548,7 +548,8 @@ public function dataProviderSetWithoutRequiredParameters() return [ 'missed_billing_address' => [ 'cart_id: "cart_id_value"', - 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided.', + 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' + . 'was not provided.', ], 'missed_cart_id' => [ 'billing_address: {}', diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index de07b80b39592..81969cf610f74 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -338,7 +338,8 @@ public function dataProviderSetWithoutRequiredParameters() return [ 'missed_billing_address' => [ 'cart_id: "cart_id_value"', - 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided.', + 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' + . 'was not provided.', ], 'missed_cart_id' => [ 'billing_address: {}', From 594e5563d671eb34409b7da35e80f4d35bf7ced9 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Mon, 25 Mar 2019 16:41:47 -0500 Subject: [PATCH 76/80] GraphQL-482: [Test Coverage] 'SetBillingAddressOnCart' functionality --- .../GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php | 2 +- .../Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index f79e6b8211b00..55a32f7cdf653 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -549,7 +549,7 @@ public function dataProviderSetWithoutRequiredParameters() 'missed_billing_address' => [ 'cart_id: "cart_id_value"', 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' - . 'was not provided.', + . ' was not provided.', ], 'missed_cart_id' => [ 'billing_address: {}', diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 81969cf610f74..a2f092b9e0e1d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -339,7 +339,7 @@ public function dataProviderSetWithoutRequiredParameters() 'missed_billing_address' => [ 'cart_id: "cart_id_value"', 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' - . 'was not provided.', + . ' was not provided.', ], 'missed_cart_id' => [ 'billing_address: {}', From 4285ac5799fc8b7a3d9d15571839c5d92583c2f7 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Tue, 26 Mar 2019 22:43:29 -0500 Subject: [PATCH 77/80] GraphQL-538: Api-functional tests fixture refactoring --- .../GetAvailablePaymentMethodsTest.php | 68 ++++--- .../GraphQl/Quote/Customer/GetCartTest.php | 80 +++----- .../Customer/SetBillingAddressOnCartTest.php | 86 ++++---- .../Customer/SetPaymentMethodOnCartTest.php | 184 +++++++++-------- .../Customer/SetShippingAddressOnCartTest.php | 64 ++++-- .../Guest/GetAvailablePaymentMethodsTest.php | 59 +++--- .../GraphQl/Quote/Guest/GetCartTest.php | 91 +++------ .../Guest/SetBillingAddressOnCartTest.php | 103 +++++----- .../Guest/SetPaymentMethodOnCartTest.php | 186 ++++++++---------- .../Guest/SetShippingAddressOnCartTest.php | 100 ++++------ .../SetOfflineShippingMethodsOnCartTest.php | 6 +- .../Quote/_files/add_simple_product.php | 28 +++ .../Quote/_files/add_virtual_product.php | 28 +++ .../_files/customer/create_empty_cart.php | 29 +++ .../customer/create_empty_cart_rollback.php | 28 +++ .../disable_all_active_payment_methods.php | 1 + ...le_all_active_payment_methods_rollback.php | 1 + .../_files/enable_offline_payment_methods.php | 24 +++ ...nable_offline_payment_methods_rollback.php | 20 ++ .../enable_offline_shipping_methods.php | 1 + ...able_offline_shipping_methods_rollback.php | 1 + .../Quote/_files/guest/create_empty_cart.php | 24 +++ .../guest/create_empty_cart_rollback.php | 28 +++ .../Quote/_files/make_cart_inactive.php | 23 +++ .../_files/set_checkmo_payment_method.php | 33 ++++ .../Quote/_files/set_new_shipping_address.php | 43 ++++ 26 files changed, 792 insertions(+), 547 deletions(-) rename dev/tests/api-functional/testsuite/Magento/GraphQl/{OfflineShipping => Quote}/SetOfflineShippingMethodsOnCartTest.php (96%) create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_virtual_product.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart_rollback.php rename dev/tests/integration/testsuite/Magento/{Payment => GraphQl/Quote}/_files/disable_all_active_payment_methods.php (93%) rename dev/tests/integration/testsuite/Magento/{Payment => GraphQl/Quote}/_files/disable_all_active_payment_methods_rollback.php (92%) create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods_rollback.php rename dev/tests/integration/testsuite/Magento/{OfflineShipping => GraphQl/Quote}/_files/enable_offline_shipping_methods.php (89%) rename dev/tests/integration/testsuite/Magento/{OfflineShipping => GraphQl/Quote}/_files/enable_offline_shipping_methods_rollback.php (86%) create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/make_cart_inactive.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php create mode 100644 dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index 74921348f449e..9c988f6bf5f71 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -38,48 +38,56 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testGetCartWithPaymentMethods() + public function testGetAvailablePaymentMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response); + self::assertArrayHasKey('available_payment_methods', $response['cart']); + self::assertCount(1, $response['cart']['available_payment_methods']); + self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); - self::assertGreaterThan( - 0, - count($response['cart']['available_payment_methods']), - 'There are no available payment methods for customer cart!' - ); } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testGetPaymentMethodsFromGuestCart() + public function testGetAvailablePaymentMethodsFromGuestCart() { - $guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_virtual_product_without_address' - ); - $query = $this->getQuery($guestQuoteMaskedId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( - "The current user cannot perform operations on cart \"$guestQuoteMaskedId\"" + "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testGetPaymentMethodsFromAnotherCustomerCart() + public function testGetAvailablePaymentMethodsFromAnotherCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -89,24 +97,31 @@ public function testGetPaymentMethodsFromAnotherCustomerCart() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php - * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php */ - public function testGetPaymentMethodsIfPaymentsAreNotSet() + public function testGetAvailablePaymentMethodsIfPaymentsAreNotPresent() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); - self::assertEquals(0, count($response['cart']['available_payment_methods'])); + self::assertArrayHasKey('cart', $response); + self::assertArrayHasKey('available_payment_methods', $response['cart']); + self::assertEmpty($response['cart']['available_payment_methods']); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php + * * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ - public function testGetPaymentMethodsOfNonExistentCart() + public function testGetAvailablePaymentMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = $this->getQuery($maskedQuoteId); @@ -118,9 +133,8 @@ public function testGetPaymentMethodsOfNonExistentCart() * @param string $maskedQuoteId * @return string */ - private function getQuery( - string $maskedQuoteId - ): string { + private function getQuery(string $maskedQuoteId): string + { return <<<QUERY { cart(cart_id: "$maskedQuoteId") { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php index cc90f1aa1f219..d2615b4135b01 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php @@ -9,9 +9,6 @@ use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -25,21 +22,6 @@ class GetCartTest extends GraphQlAbstract */ private $getMaskedQuoteIdByReservedOrderId; - /** - * @var QuoteResource - */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - /** * @var CustomerTokenServiceInterface */ @@ -49,19 +31,21 @@ protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php */ public function testGetCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); @@ -70,24 +54,23 @@ public function testGetCart() self::assertCount(2, $response['cart']['items']); self::assertNotEmpty($response['cart']['items'][0]['id']); - self::assertEquals($response['cart']['items'][0]['qty'], 2); - self::assertEquals($response['cart']['items'][0]['product']['sku'], 'simple'); + self::assertEquals(2, $response['cart']['items'][0]['qty']); + self::assertEquals('simple', $response['cart']['items'][0]['product']['sku']); self::assertNotEmpty($response['cart']['items'][1]['id']); - self::assertEquals($response['cart']['items'][1]['qty'], 1); - self::assertEquals($response['cart']['items'][1]['product']['sku'], 'simple_one'); + self::assertEquals(2, $response['cart']['items'][1]['qty']); + self::assertEquals('virtual-product', $response['cart']['items'][1]['product']['sku']); } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php */ public function testGetGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" @@ -96,13 +79,14 @@ public function testGetGuestCart() } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ public function testGetAnotherCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" @@ -112,33 +96,30 @@ public function testGetAnotherCustomerCart() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php + * * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ public function testGetNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $query = $this->getCartQuery($maskedQuoteId); + $query = $this->getQuery($maskedQuoteId); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php + * * @expectedException \Exception * @expectedExceptionMessage Current user does not have an active cart. */ public function testGetInactiveCart() { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id'); - $quote->setCustomerId(1); - $quote->setIsActive(false); - $this->quoteResource->save($quote); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); - - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } @@ -147,12 +128,11 @@ public function testGetInactiveCart() * @param string $maskedQuoteId * @return string */ - private function getCartQuery( - string $maskedQuoteId - ) : string { + private function getQuery(string $maskedQuoteId): string + { return <<<QUERY { - cart(cart_id: "$maskedQuoteId") { + cart(cart_id: "{$maskedQuoteId}") { items { id qty diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index a601f65ef72b7..0099d25ed81f4 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -56,12 +56,14 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetNewBillingAddress() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -113,12 +115,14 @@ public function testSetNewBillingAddress() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetNewBillingAddressWithUseForShippingParameter() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -188,13 +192,15 @@ public function testSetNewBillingAddressWithUseForShippingParameter() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetBillingAddressFromAddressBook() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -234,14 +240,17 @@ public function testSetBillingAddressFromAddressBook() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception * @expectedExceptionMessage Could not find a address with ID "100" */ public function testSetNotExistedBillingAddressFromAddressBook() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -265,13 +274,15 @@ public function testSetNotExistedBillingAddressFromAddressBook() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetNewBillingAddressAndFromAddressBookAtSameTime() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -311,15 +322,16 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime() } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetBillingAddressToGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -347,6 +359,7 @@ public function testSetBillingAddressToGuestCart() } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php @@ -381,9 +394,11 @@ public function testSetBillingAddressToAnotherCustomerCart() } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * * @expectedException \Exception * @expectedExceptionMessage Current customer does not have permission to address with ID "1" */ @@ -433,8 +448,11 @@ public function testSetBillingAddressOnNonExistentCart() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @dataProvider dataProviderSetWithoutRequiredParameters * @param string $input * @param string $message @@ -442,7 +460,7 @@ public function testSetBillingAddressOnNonExistentCart() */ public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message) { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $input = str_replace('cart_id_value', $maskedQuoteId, $input); $query = <<<QUERY @@ -465,6 +483,24 @@ public function testSetBillingAddressWithoutRequiredParameters(string $input, st $this->graphQlQuery($query); } + /** + * @return array + */ + public function dataProviderSetWithoutRequiredParameters(): array + { + return [ + 'missed_billing_address' => [ + 'cart_id: "cart_id_value"', + 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' + . ' was not provided.', + ], + 'missed_cart_id' => [ + 'billing_address: {}', + 'Required parameter "cart_id" is missing' + ] + ]; + } + /** * Verify the all the whitelisted fields for a New Address Object * @@ -536,22 +572,4 @@ private function assignQuoteToCustomer( $this->quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } - - /** - * @return array - */ - public function dataProviderSetWithoutRequiredParameters() - { - return [ - 'missed_billing_address' => [ - 'cart_id: "cart_id_value"', - 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' - . ' was not provided.', - ], - 'missed_cart_id' => [ - 'billing_address: {}', - 'Required parameter "cart_id" is missing' - ] - ]; - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php index 56a9592cbd4a2..ffc52c753b80a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -9,10 +9,8 @@ use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; +use Magento\OfflinePayments\Model\Cashondelivery; use Magento\OfflinePayments\Model\Checkmo; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -31,21 +29,6 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract */ private $customerTokenService; - /** - * @var QuoteResource - */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - /** * @inheritdoc */ @@ -53,21 +36,22 @@ protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testSetPaymentWithVirtualProduct() + public function testSetPaymentOnCartWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_virtual_product'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('setPaymentMethodOnCart', $response); @@ -77,14 +61,35 @@ public function testSetPaymentWithVirtualProduct() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * + * @expectedException \Exception + * @expectedExceptionMessage The shipping address is missing. Set the address and try again. + */ + public function testSetPaymentOnCartWithSimpleProductAndWithoutAddress() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + + $query = $this->getQuery($maskedQuoteId, $methodCode); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php */ - public function testSetPaymentWithSimpleProduct() + public function testSetPaymentOnCartWithVirtualProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('setPaymentMethodOnCart', $response); @@ -95,96 +100,93 @@ public function testSetPaymentWithSimpleProduct() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * * @expectedException \Exception - * @expectedExceptionMessage The shipping address is missing. Set the address and try again. + * @expectedExceptionMessage The requested Payment Method is not available. */ - public function testSetPaymentWithSimpleProductWithoutAddress() + public function testSetNonExistentPaymentMethod() { - $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1); + $methodCode = 'noway'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * * @expectedException \Exception - * @expectedExceptionMessage The requested Payment Method is not available. + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ - public function testSetNonExistingPaymentMethod() + public function testSetPaymentOnNonExistentCart() { - $methodCode = 'noway'; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); - - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $maskedQuoteId = 'non_existent_masked_id'; + $query = <<<QUERY +{ + cart(cart_id: "$maskedQuoteId") { + items { + id + } + } +} +QUERY; $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetPaymentMethodToGuestCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetPaymentMethodToAnotherCustomerCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer2@search.example.com')); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @expectedException \Exception - * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" - */ - public function testPaymentMethodOnNonExistentCart() - { - $maskedQuoteId = 'non_existent_masked_id'; - $query = <<<QUERY -{ - cart(cart_id: "$maskedQuoteId") { - items { - id - } - } -} -QUERY; - $this->graphQlQuery($query, [], '', $this->getHeaderMap()); - } - - /** - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @param string $input * @param string $message + * @throws \Exception * @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters */ public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message) @@ -207,6 +209,7 @@ public function testSetPaymentMethodWithoutRequiredParameters(string $input, str $this->expectExceptionMessage($message); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } + /** * @return array */ @@ -229,19 +232,26 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php */ public function testReSetPayment() { - /** @var \Magento\Quote\Model\Quote $quote */ - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_with_payment'); - $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + + $methodCode = Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE; + $query = $this->getQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('setPaymentMethodOnCart', $response); self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); } @@ -250,7 +260,7 @@ public function testReSetPayment() * @param string $methodCode * @return string */ - private function prepareMutationQuery( + private function getQuery( string $maskedQuoteId, string $methodCode ) : string { @@ -272,22 +282,6 @@ private function prepareMutationQuery( QUERY; } - /** - * @param string $reversedOrderId - * @param int $customerId - * @return string - */ - private function assignQuoteToCustomer( - string $reversedOrderId, - int $customerId - ): string { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); - $quote->setCustomerId($customerId); - $this->quoteResource->save($quote); - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - /** * @param string $username * @param string $password diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php index 4d4c61b3b4e5b..efd86ca5e56c8 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\Quote\Customer; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; @@ -34,6 +35,11 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract */ private $quoteIdToMaskedId; + /** + * @var GetMaskedQuoteIdByReservedOrderId + */ + private $getMaskedQuoteIdByReservedOrderId; + /** * @var CustomerTokenServiceInterface */ @@ -45,16 +51,19 @@ protected function setUp() $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ - public function testSetNewShippingAddress() + public function testSetNewShippingAddressOnCartWithSimpleProduct() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -108,14 +117,17 @@ public function testSetNewShippingAddress() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php + * * @expectedException \Exception * @expectedExceptionMessage The Cart includes virtual product(s) only, so a shipping address is not used. */ - public function testSetNewShippingAddressOnQuoteWithVirtualProducts() + public function testSetNewShippingAddressOnCartWithVirtualProduct() { - $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_virtual_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -152,13 +164,15 @@ public function testSetNewShippingAddressOnQuoteWithVirtualProducts() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetShippingAddressFromAddressBook() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -196,14 +210,17 @@ public function testSetShippingAddressFromAddressBook() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception * @expectedExceptionMessage Could not find a address with ID "100" */ public function testSetNonExistentShippingAddressFromAddressBook() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -229,13 +246,15 @@ public function testSetNonExistentShippingAddressFromAddressBook() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetNewShippingAddressAndFromAddressBookAtSameTime() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -276,9 +295,11 @@ public function testSetNewShippingAddressAndFromAddressBookAtSameTime() } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * * @expectedException \Exception * @expectedExceptionMessage Current customer does not have permission to address with ID "1" */ @@ -311,9 +332,11 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress() } /** + * @security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * * @expectedException \Exception */ public function testSetShippingAddressToAnotherCustomerCart() @@ -343,13 +366,15 @@ public function testSetShippingAddressToAnotherCustomerCart() $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer2@search.example.com')); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @dataProvider dataProviderUpdateWithMissedRequiredParameters * @param string $input * @param string $message @@ -357,7 +382,7 @@ public function testSetShippingAddressToAnotherCustomerCart() */ public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message) { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -386,7 +411,7 @@ public function testSetNewShippingAddressWithMissedRequiredParameters(string $in /** * @return array */ - public function dataProviderUpdateWithMissedRequiredParameters() + public function dataProviderUpdateWithMissedRequiredParameters(): array { return [ 'shipping_addresses' => [ @@ -402,13 +427,16 @@ public function dataProviderUpdateWithMissedRequiredParameters() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception * @expectedExceptionMessage You cannot specify multiple shipping addresses. */ public function testSetMultipleNewShippingAddresses() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php index 7da7480ca390a..8989b1b2c074e 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -31,39 +31,36 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testGetCartWithPaymentMethods() + public function testGetAvailablePaymentMethods() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); self::assertArrayHasKey('cart', $response); + self::assertArrayHasKey('available_payment_methods', $response['cart']); + self::assertCount(1, $response['cart']['available_payment_methods']); self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); - - self::assertEquals('free', $response['cart']['available_payment_methods'][1]['code']); - self::assertEquals( - 'No Payment Information Required', - $response['cart']['available_payment_methods'][1]['title'] - ); - self::assertGreaterThan( - 0, - count($response['cart']['available_payment_methods']), - 'There are no available payment methods for guest cart!' - ); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testGetPaymentMethodsFromCustomerCart() + public function testGetAvailablePaymentMethodsFromCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( @@ -73,25 +70,28 @@ public function testGetPaymentMethodsFromCustomerCart() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php - * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php */ - public function testGetPaymentMethodsIfPaymentsAreNotSet() + public function testGetAvailablePaymentMethodsIfPaymentsAreNotPresent() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); - self::assertEquals(0, count($response['cart']['available_payment_methods'])); + self::assertArrayHasKey('cart', $response); + self::assertArrayHasKey('available_payment_methods', $response['cart']); + self::assertEmpty($response['cart']['available_payment_methods']); } /** * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ - public function testGetPaymentMethodsOfNonExistentCart() + public function testGetAvailablePaymentMethodsOfNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = $this->getQuery($maskedQuoteId); @@ -102,9 +102,8 @@ public function testGetPaymentMethodsOfNonExistentCart() * @param string $maskedQuoteId * @return string */ - private function getQuery( - string $maskedQuoteId - ): string { + private function getQuery(string $maskedQuoteId): string + { return <<<QUERY { cart(cart_id: "$maskedQuoteId") { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php index 847a7129750ff..a7af18a5674ba 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php @@ -8,10 +8,6 @@ namespace Magento\GraphQl\Quote\Guest; use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; -use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -25,43 +21,23 @@ class GetCartTest extends GraphQlAbstract */ private $getMaskedQuoteIdByReservedOrderId; - /** - * @var QuoteResource - */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - - /** - * @var CustomerTokenServiceInterface - */ - private $customerTokenService; - protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); - $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php */ public function testGetCart() { - $maskedQuoteId = $this->unAssignCustomerFromQuote('test_order_item_with_items'); - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query); @@ -70,21 +46,23 @@ public function testGetCart() self::assertCount(2, $response['cart']['items']); self::assertNotEmpty($response['cart']['items'][0]['id']); - self::assertEquals($response['cart']['items'][0]['qty'], 2); - self::assertEquals($response['cart']['items'][0]['product']['sku'], 'simple'); + self::assertEquals(2, $response['cart']['items'][0]['qty']); + self::assertEquals('simple', $response['cart']['items'][0]['product']['sku']); self::assertNotEmpty($response['cart']['items'][1]['id']); - self::assertEquals($response['cart']['items'][1]['qty'], 1); - self::assertEquals($response['cart']['items'][1]['product']['sku'], 'simple_one'); + self::assertEquals(2, $response['cart']['items'][1]['qty']); + self::assertEquals('virtual-product', $response['cart']['items'][1]['product']['sku']); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ public function testGetCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items'); - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" @@ -99,25 +77,22 @@ public function testGetCustomerCart() public function testGetNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; - $query = $this->getCartQuery($maskedQuoteId); + $query = $this->getQuery($maskedQuoteId); $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php + * * @expectedException \Exception * @expectedExceptionMessage Current user does not have an active cart. */ public function testGetInactiveCart() { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id'); - $quote->setIsActive(false); - $this->quoteResource->save($quote); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); - - $query = $this->getCartQuery($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + $query = $this->getQuery($maskedQuoteId); $this->graphQlQuery($query); } @@ -126,12 +101,11 @@ public function testGetInactiveCart() * @param string $maskedQuoteId * @return string */ - private function getCartQuery( - string $maskedQuoteId - ) : string { + private function getQuery(string $maskedQuoteId): string + { return <<<QUERY { - cart(cart_id: "$maskedQuoteId") { + cart(cart_id: "{$maskedQuoteId}") { items { id qty @@ -143,19 +117,4 @@ private function getCartQuery( } QUERY; } - - /** - * @param string $reversedOrderId - * @param int $customerId - * @return string - */ - private function unAssignCustomerFromQuote( - string $reversedOrderId - ): string { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); - $quote->setCustomerId(0); - $this->quoteResource->save($quote); - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index a2f092b9e0e1d..f6c38ef43554b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -7,9 +7,7 @@ namespace Magento\GraphQl\Quote\Guest; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -19,34 +17,24 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract { /** - * @var QuoteResource + * @var GetMaskedQuoteIdByReservedOrderId */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; + private $getMaskedQuoteIdByReservedOrderId; protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetNewBillingAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -98,11 +86,13 @@ public function testSetNewBillingAddress() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ public function testSetNewBillingAddressWithUseForShippingParameter() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -172,11 +162,13 @@ public function testSetNewBillingAddressWithUseForShippingParameter() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ public function testSetBillingAddressToCustomerCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -215,13 +207,17 @@ public function testSetBillingAddressToCustomerCart() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @security + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception * @expectedExceptionMessage The current customer isn't authorized. */ public function testSetBillingAddressFromAddressBook() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -264,7 +260,10 @@ public function testSetBillingAddressOnNonExistentCart() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @dataProvider dataProviderSetWithoutRequiredParameters * @param string $input * @param string $message @@ -272,7 +271,7 @@ public function testSetBillingAddressOnNonExistentCart() */ public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message) { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $input = str_replace('cart_id_value', $maskedQuoteId, $input); $query = <<<QUERY @@ -295,6 +294,24 @@ public function testSetBillingAddressWithoutRequiredParameters(string $input, st $this->graphQlQuery($query); } + /** + * @return array + */ + public function dataProviderSetWithoutRequiredParameters(): array + { + return [ + 'missed_billing_address' => [ + 'cart_id: "cart_id_value"', + 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' + . ' was not provided.', + ], + 'missed_cart_id' => [ + 'billing_address: {}', + 'Required parameter "cart_id" is missing' + ] + ]; + } + /** * Verify the all the whitelisted fields for a New Address Object * @@ -317,34 +334,4 @@ private function assertNewAddressFields(array $addressResponse, string $addressT $this->assertResponseFields($addressResponse, $assertionMap); } - - /** - * @param string $reversedQuoteId - * @return string - */ - private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string - { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); - - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } - - /** - * @return array - */ - public function dataProviderSetWithoutRequiredParameters() - { - return [ - 'missed_billing_address' => [ - 'cart_id: "cart_id_value"', - 'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!' - . ' was not provided.', - ], - 'missed_cart_id' => [ - 'billing_address: {}', - 'Required parameter "cart_id" is missing' - ] - ]; - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index a347c99a9220a..b2a8f5078c5e9 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -8,10 +8,8 @@ namespace Magento\GraphQl\Quote\Guest; use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; +use Magento\OfflinePayments\Model\Cashondelivery; use Magento\OfflinePayments\Model\Checkmo; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -25,21 +23,6 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract */ private $getMaskedQuoteIdByReservedOrderId; - /** - * @var QuoteResource - */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - /** * @inheritdoc */ @@ -47,21 +30,20 @@ protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ - public function testSetPaymentWithVirtualProduct() + public function testSetPaymentOnCartWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_virtual_product'); - $this->unAssignCustomerFromQuote('test_order_with_virtual_product'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query); self::assertArrayHasKey('setPaymentMethodOnCart', $response); @@ -71,15 +53,33 @@ public function testSetPaymentWithVirtualProduct() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * + * @expectedException \Exception + * @expectedExceptionMessage The shipping address is missing. Set the address and try again. + */ + public function testSetPaymentOnCartWithSimpleProductAndWithoutAddress() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + + $query = $this->getQuery($maskedQuoteId, $methodCode); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php */ - public function testSetPaymentWithSimpleProduct() + public function testSetPaymentOnCartWithVirtualProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); - $this->unAssignCustomerFromQuote('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query); self::assertArrayHasKey('setPaymentMethodOnCart', $response); @@ -89,45 +89,56 @@ public function testSetPaymentWithSimpleProduct() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * * @expectedException \Exception - * @expectedExceptionMessage The shipping address is missing. Set the address and try again. + * @expectedExceptionMessage The requested Payment Method is not available. */ - public function testSetPaymentWithSimpleProductWithoutAddress() + public function testSetNonExistentPaymentMethod() { - $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $methodCode = 'noway'; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php * @expectedException \Exception - * @expectedExceptionMessage The requested Payment Method is not available. + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ - public function testSetNonExistingPaymentMethod() + public function testSetPaymentOnNonExistentCart() { - $methodCode = 'noway'; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); - $this->unAssignCustomerFromQuote('test_order_1'); - - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $maskedQuoteId = 'non_existent_masked_id'; + $query = <<<QUERY +{ + cart(cart_id: "$maskedQuoteId") { + items { + id + } + } +} +QUERY; $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @security + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ public function testSetPaymentMethodToCustomerCart() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $query = $this->getQuery($maskedQuoteId, $methodCode); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" @@ -136,10 +147,15 @@ public function testSetPaymentMethodToCustomerCart() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * * @param string $input * @param string $message * @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters + * @throws \Exception */ public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message) { @@ -161,6 +177,7 @@ public function testSetPaymentMethodWithoutRequiredParameters(string $input, str $this->expectExceptionMessage($message); $this->graphQlQuery($query); } + /** * @return array */ @@ -183,39 +200,25 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array } /** - * @expectedException \Exception - * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" - */ - public function testSetPaymentOnNonExistentCart() - { - $maskedQuoteId = 'non_existent_masked_id'; - $query = <<<QUERY -{ - cart(cart_id: "$maskedQuoteId") { - items { - id - } - } -} -QUERY; - $this->graphQlQuery($query); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php */ public function testReSetPayment() { - /** @var \Magento\Quote\Model\Quote $quote */ - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_with_payment'); - $this->unAssignCustomerFromQuote('test_order_1_with_payment'); - $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; - $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + + $methodCode = Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE; + $query = $this->getQuery($maskedQuoteId, $methodCode); $response = $this->graphQlQuery($query); self::assertArrayHasKey('setPaymentMethodOnCart', $response); self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); } @@ -224,20 +227,18 @@ public function testReSetPayment() * @param string $methodCode * @return string */ - private function prepareMutationQuery( + private function getQuery( string $maskedQuoteId, string $methodCode ) : string { return <<<QUERY mutation { - setPaymentMethodOnCart(input: - { - cart_id: "{$maskedQuoteId}", - payment_method: { - code: "{$methodCode}" - } - }) { - + setPaymentMethodOnCart(input: { + cart_id: "{$maskedQuoteId}", + payment_method: { + code: "{$methodCode}" + } + }) { cart { selected_payment_method { code @@ -247,19 +248,4 @@ private function prepareMutationQuery( } QUERY; } - - /** - * @param string $reversedOrderId - * @param int $customerId - * @return string - */ - private function unAssignCustomerFromQuote( - string $reversedOrderId - ): string { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); - $quote->setCustomerId(0); - $this->quoteResource->save($quote); - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php index 5c6e0e9cec55e..b6cea68db9b84 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php @@ -7,15 +7,9 @@ namespace Magento\GraphQl\Quote\Guest; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; -use Magento\Multishipping\Helper\Data; -use Magento\Quote\Model\QuoteFactory; -use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; -use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; -use Magento\TestFramework\ObjectManager; /** * Test for set shipping addresses on cart mutation @@ -27,38 +21,20 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract */ private $getMaskedQuoteIdByReservedOrderId; - /** - * @var QuoteResource - */ - private $quoteResource; - - /** - * @var QuoteFactory - */ - private $quoteFactory; - - /** - * @var QuoteIdToMaskedQuoteIdInterface - */ - private $quoteIdToMaskedId; - protected function setUp() { $objectManager = Bootstrap::getObjectManager(); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); - $this->quoteResource = $objectManager->get(QuoteResource::class); - $this->quoteFactory = $objectManager->get(QuoteFactory::class); - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php */ - public function testSetNewShippingAddress() + public function testSetNewShippingAddressOnCartWithSimpleProduct() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -112,15 +88,16 @@ public function testSetNewShippingAddress() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php + * * @expectedException \Exception * @expectedExceptionMessage The Cart includes virtual product(s) only, so a shipping address is not used. */ - public function testSetNewShippingAddressOnQuoteWithVirtualProducts() + public function testSetNewShippingAddressOnCartWithVirtualProduct() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_virtual_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -157,15 +134,17 @@ public function testSetNewShippingAddressOnQuoteWithVirtualProducts() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @security + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception * @expectedExceptionMessage The current customer isn't authorized. */ public function testSetShippingAddressFromAddressBook() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -191,13 +170,17 @@ public function testSetShippingAddressFromAddressBook() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @security * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception */ public function testSetShippingAddressToCustomerCart() { - $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -222,12 +205,14 @@ public function testSetShippingAddressToCustomerCart() $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @dataProvider dataProviderUpdateWithMissedRequiredParameters * @param string $input * @param string $message @@ -235,9 +220,7 @@ public function testSetShippingAddressToCustomerCart() */ public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message) { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -266,7 +249,7 @@ public function testSetNewShippingAddressWithMissedRequiredParameters(string $in /** * @return array */ - public function dataProviderUpdateWithMissedRequiredParameters() + public function dataProviderUpdateWithMissedRequiredParameters(): array { return [ 'shipping_addresses' => [ @@ -281,15 +264,16 @@ public function dataProviderUpdateWithMissedRequiredParameters() } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * * @expectedException \Exception * @expectedExceptionMessage You cannot specify multiple shipping addresses. */ public function testSetMultipleNewShippingAddresses() { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute( - 'test_order_with_simple_product_without_address' - ); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<<QUERY mutation { @@ -360,20 +344,4 @@ private function assertNewShippingAddressFields(array $shippingAddressResponse): $this->assertResponseFields($shippingAddressResponse, $assertionMap); } - - /** - * @param string $reversedOrderId - * @param int $customerId - * @return string - */ - private function assignQuoteToCustomer( - string $reversedOrderId = 'test_order_with_simple_product_without_address', - int $customerId = 1 - ): string { - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id'); - $quote->setCustomerId($customerId); - $this->quoteResource->save($quote); - return $this->quoteIdToMaskedId->execute((int)$quote->getId()); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/OfflineShipping/SetOfflineShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetOfflineShippingMethodsOnCartTest.php similarity index 96% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/OfflineShipping/SetOfflineShippingMethodsOnCartTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetOfflineShippingMethodsOnCartTest.php index 80acbbdb64230..cf32003340a66 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/OfflineShipping/SetOfflineShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetOfflineShippingMethodsOnCartTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\GraphQl\OfflineShipping; +namespace Magento\GraphQl\Quote; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Quote\Model\QuoteFactory; @@ -53,7 +53,7 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @magentoApiDataFixture Magento/OfflineShipping/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php * @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php * * @param string $carrierCode @@ -103,7 +103,7 @@ public function offlineShippingMethodDataProvider() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - * @magentoApiDataFixture Magento/OfflineShipping/_files/enable_offline_shipping_methods.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php */ public function testSetShippingMethodTwiceInOneRequest() { diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product.php new file mode 100644 index 0000000000000..d23381e33d436 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); + +$product = $productRepository->get('simple'); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$quote->addProduct($product, 2); +$cartRepository->save($quote); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_virtual_product.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_virtual_product.php new file mode 100644 index 0000000000000..f597d0bffa7ce --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_virtual_product.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); + +$product = $productRepository->get('virtual-product'); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$quote->addProduct($product, 2); +$cartRepository->save($quote); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart.php new file mode 100644 index 0000000000000..86174a7753f4e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart.php @@ -0,0 +1,29 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Quote\Api\CartManagementInterface; +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var CartManagementInterface $cartManagement */ +$cartManagement = Bootstrap::getObjectManager()->get(CartManagementInterface::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); +/** @var QuoteIdMaskFactory $quoteIdMaskFactory */ +$quoteIdMaskFactory = Bootstrap::getObjectManager()->get(QuoteIdMaskFactory::class); + +$cartId = $cartManagement->createEmptyCartForCustomer(1); +$cart = $cartRepository->get($cartId); +$cart->setReservedOrderId('test_quote'); +$cartRepository->save($cart); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $quoteIdMaskFactory->create(); +$quoteIdMask->setQuoteId($cartId) + ->save(); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart_rollback.php new file mode 100644 index 0000000000000..0d5d5f067e35a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/customer/create_empty_cart_rollback.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var QuoteIdMaskFactory $quoteIdMaskFactory */ +$quoteIdMaskFactory = Bootstrap::getObjectManager()->get(QuoteIdMaskFactory::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$quoteResource->delete($quote); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $quoteIdMaskFactory->create(); +$quoteIdMask->setQuoteId($quote->getId()) + ->delete(); diff --git a/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php similarity index 93% rename from dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php index ac811e67c580a..8e6d4b8f74b86 100644 --- a/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Config\Model\Config; diff --git a/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_all_active_payment_methods_rollback.php similarity index 92% rename from dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_all_active_payment_methods_rollback.php index 4a56888058e4d..092826d1fd3f7 100644 --- a/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/disable_all_active_payment_methods_rollback.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Framework\App\Config\ScopeConfigInterface; diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php new file mode 100644 index 0000000000000..9c15589ba82e5 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php @@ -0,0 +1,24 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 +declare(strict_types=1); + +use Magento\Framework\App\Config\Storage\Writer; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Config\ScopeConfigInterface; + +$objectManager = Bootstrap::getObjectManager(); +/** @var Writer $configWriter */ +$configWriter = $objectManager->get(WriterInterface::class); + +$configWriter->save('payment/banktransfer/active', 1); +$configWriter->save('payment/cashondelivery/active', 1); +$configWriter->save('payment/checkmo/active', 1); +$configWriter->save('payment/purchaseorder/active', 1); + +$scopeConfig = $objectManager->get(ScopeConfigInterface::class); +$scopeConfig->clean(); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods_rollback.php new file mode 100644 index 0000000000000..61b7ed9737ff9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_payment_methods_rollback.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 +declare(strict_types=1); + +use Magento\Framework\App\Config\Storage\Writer; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); +/** @var Writer $configWriter */ +$configWriter = $objectManager->create(WriterInterface::class); + +$configWriter->delete('payment/banktransfer/active'); +$configWriter->delete('payment/cashondelivery/active'); +$configWriter->delete('payment/checkmo/active'); +$configWriter->delete('payment/purchaseorder/active'); diff --git a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/enable_offline_shipping_methods.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php similarity index 89% rename from dev/tests/integration/testsuite/Magento/OfflineShipping/_files/enable_offline_shipping_methods.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php index 08694bf8c7d0b..ebc41da9b1b3c 100644 --- a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/enable_offline_shipping_methods.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Framework\App\Config\Storage\Writer; diff --git a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/enable_offline_shipping_methods_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_shipping_methods_rollback.php similarity index 86% rename from dev/tests/integration/testsuite/Magento/OfflineShipping/_files/enable_offline_shipping_methods_rollback.php rename to dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_shipping_methods_rollback.php index 31a16f42adfce..384ffbdf51f3c 100644 --- a/dev/tests/integration/testsuite/Magento/OfflineShipping/_files/enable_offline_shipping_methods_rollback.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/enable_offline_shipping_methods_rollback.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Framework\App\Config\Storage\Writer; diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart.php new file mode 100644 index 0000000000000..6a9ed898c3161 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart.php @@ -0,0 +1,24 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Api\GuestCartManagementInterface; +use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var GuestCartManagementInterface $guestCartManagement */ +$guestCartManagement = Bootstrap::getObjectManager()->get(GuestCartManagementInterface::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); +/** @var MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId */ +$maskedQuoteIdToQuoteId = Bootstrap::getObjectManager()->get(MaskedQuoteIdToQuoteIdInterface::class); + +$cartHash = $guestCartManagement->createEmptyCart(); +$cartId = $maskedQuoteIdToQuoteId->execute($cartHash); +$cart = $cartRepository->get($cartId); +$cart->setReservedOrderId('test_quote'); +$cartRepository->save($cart); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart_rollback.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart_rollback.php new file mode 100644 index 0000000000000..0d5d5f067e35a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/guest/create_empty_cart_rollback.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var QuoteIdMaskFactory $quoteIdMaskFactory */ +$quoteIdMaskFactory = Bootstrap::getObjectManager()->get(QuoteIdMaskFactory::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$quoteResource->delete($quote); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $quoteIdMaskFactory->create(); +$quoteIdMask->setQuoteId($quote->getId()) + ->delete(); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/make_cart_inactive.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/make_cart_inactive.php new file mode 100644 index 0000000000000..b5704f82879b2 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/make_cart_inactive.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var CartRepositoryInterface $cartRepository */ +$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$quote->setIsActive(false); +$cartRepository->save($quote); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php new file mode 100644 index 0000000000000..a973a982b1150 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\OfflinePayments\Model\Checkmo; +use Magento\Quote\Api\Data\PaymentInterface; +use Magento\Quote\Api\Data\PaymentInterfaceFactory; +use Magento\Quote\Api\PaymentMethodManagementInterface; +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var PaymentInterfaceFactory $paymentFactory */ +$paymentFactory = Bootstrap::getObjectManager()->get(PaymentInterfaceFactory::class); +/** @var PaymentMethodManagementInterface $paymentMethodManagement */ +$paymentMethodManagement = Bootstrap::getObjectManager()->get(PaymentMethodManagementInterface::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); + +$payment = $paymentFactory->create([ + 'data' => [ + PaymentInterface::KEY_METHOD => Checkmo::PAYMENT_METHOD_CHECKMO_CODE, + ] +]); +$paymentMethodManagement->set($quote->getId(), $payment); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php new file mode 100644 index 0000000000000..e17b9e61f82db --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Framework\Api\DataObjectHelper; +use Magento\Quote\Api\Data\AddressInterface; +use Magento\Quote\Api\Data\AddressInterfaceFactory; +use Magento\Quote\Model\QuoteFactory; +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; +use Magento\Quote\Model\ShippingAddressManagementInterface; +use Magento\TestFramework\Helper\Bootstrap; + +/** @var QuoteFactory $quoteFactory */ +$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); +/** @var QuoteResource $quoteResource */ +$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); +/** @var AddressInterfaceFactory $quoteAddressFactory */ +$quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressInterfaceFactory::class); +/** @var DataObjectHelper $dataObjectHelper */ +$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class); +/** @var ShippingAddressManagementInterface $shippingAddressManagement */ +$shippingAddressManagement = Bootstrap::getObjectManager()->get(ShippingAddressManagementInterface::class); + +$quoteAddressData = [ + AddressInterface::KEY_TELEPHONE => 3468676, + AddressInterface::KEY_POSTCODE => 75477, + AddressInterface::KEY_COUNTRY_ID => 'US', + AddressInterface::KEY_CITY => 'CityM', + AddressInterface::KEY_COMPANY => 'CompanyName', + AddressInterface::KEY_STREET => 'Green str, 67', + AddressInterface::KEY_LASTNAME => 'Smith', + AddressInterface::KEY_FIRSTNAME => 'John', + AddressInterface::KEY_REGION_ID => 1, +]; +$quoteAddress = $quoteAddressFactory->create(); +$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class); + +$quote = $quoteFactory->create(); +$quoteResource->load($quote, 'test_quote', 'reserved_order_id'); +$shippingAddressManagement->assign($quote->getId(), $quoteAddress); From 4ce46390de5d1236d5ec38f5912355d3abe9939a Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Tue, 26 Mar 2019 23:39:36 -0500 Subject: [PATCH 78/80] GraphQL-538: Api-functional tests fixture refactoring --- .../Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php index 88462b8dbda3b..c5a4e8af02a58 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetMaskedQuoteIdByReservedOrderId.php @@ -47,6 +47,8 @@ public function __construct( } /** + * Get masked quote id by reserved order id + * * @param string $reversedOrderId * @return string * @throws \Magento\Framework\Exception\NoSuchEntityException From 1a0dd445c4a3865a4c41225e827bfaa2feed204d Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Tue, 26 Mar 2019 23:47:31 -0500 Subject: [PATCH 79/80] GraphQL-538: Api-functional tests fixture refactoring --- .../Quote/Customer/GetAvailablePaymentMethodsTest.php | 4 ++-- .../Magento/GraphQl/Quote/Customer/GetCartTest.php | 4 ++-- .../GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php | 6 +++--- .../GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php | 4 ++-- .../GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php | 4 ++-- .../GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php | 2 +- .../testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php | 2 +- .../GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php | 4 ++-- .../GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php | 2 +- .../GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index 9c988f6bf5f71..f15b275b17f1a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -59,7 +59,7 @@ public function testGetAvailablePaymentMethods() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php @@ -78,7 +78,7 @@ public function testGetAvailablePaymentMethodsFromGuestCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php index d2615b4135b01..eb62b8c92f310 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php @@ -63,7 +63,7 @@ public function testGetCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php */ @@ -79,7 +79,7 @@ public function testGetGuestCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 0099d25ed81f4..129375debe068 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -322,7 +322,7 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php @@ -359,7 +359,7 @@ public function testSetBillingAddressToGuestCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php @@ -394,7 +394,7 @@ public function testSetBillingAddressToAnotherCustomerCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php index ffc52c753b80a..450a22dd6e9c7 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -139,7 +139,7 @@ public function testSetPaymentOnNonExistentCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php @@ -159,7 +159,7 @@ public function testSetPaymentMethodToGuestCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php index efd86ca5e56c8..5ff29d20b34d7 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php @@ -295,7 +295,7 @@ public function testSetNewShippingAddressAndFromAddressBookAtSameTime() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php @@ -332,7 +332,7 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php index 8989b1b2c074e..95136932e2969 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -51,7 +51,7 @@ public function testGetAvailablePaymentMethods() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php index a7af18a5674ba..6b1f540e4d47a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php @@ -55,7 +55,7 @@ public function testGetCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index f6c38ef43554b..3808ce38b9d7b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -162,7 +162,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ @@ -207,7 +207,7 @@ public function testSetBillingAddressToCustomerCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index b2a8f5078c5e9..8f37f00c3db7f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -126,7 +126,7 @@ public function testSetPaymentOnNonExistentCart() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php index b6cea68db9b84..e21d9ed64d491 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php @@ -134,7 +134,7 @@ public function testSetNewShippingAddressOnCartWithVirtualProduct() } /** - * @security + * _security * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php @@ -170,7 +170,7 @@ public function testSetShippingAddressFromAddressBook() } /** - * @security + * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php From 88fa9d62c1c1318a5ec58897c305904d41b1a8b9 Mon Sep 17 00:00:00 2001 From: Valerii Naida <vnayda@adobe.com> Date: Wed, 27 Mar 2019 00:52:09 -0500 Subject: [PATCH 80/80] GraphQL-538: Api-functional tests fixture refactoring --- .../GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php | 1 - .../GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index f15b275b17f1a..ba640bc3402ba 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -52,7 +52,6 @@ public function testGetAvailablePaymentMethods() self::assertArrayHasKey('cart', $response); self::assertArrayHasKey('available_payment_methods', $response['cart']); - self::assertCount(1, $response['cart']['available_payment_methods']); self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php index 95136932e2969..8271a76d88f12 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -44,7 +44,6 @@ public function testGetAvailablePaymentMethods() self::assertArrayHasKey('cart', $response); self::assertArrayHasKey('available_payment_methods', $response['cart']); - self::assertCount(1, $response['cart']['available_payment_methods']); self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']);