From a4c74d8fd1cb4a67faee123607dab819bea54f04 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 30 Mar 2020 10:32:44 +0200 Subject: [PATCH 01/66] Implement ActionInterface for Wishlist/Shared --- .../Wishlist/Controller/Shared/Allcart.php | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index 6300b14dcf515..8d160d270a6f0 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -3,55 +3,68 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + namespace Magento\Wishlist\Controller\Shared; -use Magento\Framework\App\Action\Context; -use Magento\Wishlist\Model\ItemCarrier; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\Result\Forward; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Wishlist\Model\ItemCarrier; -class Allcart extends \Magento\Framework\App\Action\Action +class Allcart implements HttpGetActionInterface { + /** + * @var ItemCarrier + */ + private $itemCarrier; + /** * @var WishlistProvider */ - protected $wishlistProvider; + private $wishlistProvider; /** - * @var \Magento\Wishlist\Model\ItemCarrier + * @var RequestInterface */ - protected $itemCarrier; + private $request; /** - * @param Context $context - * @param WishlistProvider $wishlistProvider - * @param ItemCarrier $itemCarrier + * @var ResultFactory */ + private $resultFactory; + public function __construct( - Context $context, - WishlistProvider $wishlistProvider, - ItemCarrier $itemCarrier + ItemCarrier $itemCarrier, + RequestInterface $request, + ResultFactory $resultFactory, + WishlistProvider $wishlistProvider ) { - $this->wishlistProvider = $wishlistProvider; $this->itemCarrier = $itemCarrier; - parent::__construct($context); + $this->request = $request; + $this->resultFactory = $resultFactory; + $this->wishlistProvider = $wishlistProvider; } /** * Add all items from wishlist to shopping cart * - * @return \Magento\Framework\Controller\ResultInterface + * @inheritDoc */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { - /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + /** @var Forward $resultForward */ $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); $resultForward->forward('noroute'); return $resultForward; } - $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty')); - /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->request->getParam('qty')); + /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($redirectUrl); return $resultRedirect; From 18e7519bb69cd05bb73a9c0afb8d4948850b9f9a Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 30 Mar 2020 10:56:02 +0200 Subject: [PATCH 02/66] Unit test for Wishlist/Shared Controller --- .../Unit/Controller/Shared/AllcartTest.php | 72 +++++++++---------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index d5ac5e9485424..4422c13a72e60 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -5,82 +5,86 @@ */ namespace Magento\Wishlist\Test\Unit\Controller\Shared; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Request\Http; +use Magento\Framework\Controller\Result\Forward; +use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; - -class AllcartTest extends \PHPUnit\Framework\TestCase +use Magento\Wishlist\Controller\Shared\Allcart; +use Magento\Wishlist\Controller\Shared\WishlistProvider; +use Magento\Wishlist\Model\ItemCarrier; +use Magento\Wishlist\Model\Wishlist; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +class AllcartTest extends TestCase { /** - * @var \Magento\Wishlist\Controller\Shared\Allcart + * @var Allcart */ protected $allcartController; /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager - */ - protected $objectManagerHelper; - - /** - * @var \Magento\Framework\App\Action\Context + * @var Context */ protected $context; /** - * @var \Magento\Wishlist\Controller\Shared\WishlistProvider|\PHPUnit\Framework\MockObject\MockObject + * @var WishlistProvider|MockObject */ protected $wishlistProviderMock; /** - * @var \Magento\Wishlist\Model\ItemCarrier|\PHPUnit\Framework\MockObject\MockObject + * @var ItemCarrier|MockObject */ protected $itemCarrierMock; /** - * @var \Magento\Wishlist\Model\Wishlist|\PHPUnit\Framework\MockObject\MockObject + * @var Wishlist|MockObject */ protected $wishlistMock; /** - * @var \Magento\Framework\App\Request\Http|\PHPUnit\Framework\MockObject\MockObject + * @var Http|MockObject */ protected $requestMock; /** - * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit\Framework\MockObject\MockObject + * @var ResultFactory|MockObject */ protected $resultFactoryMock; /** - * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit\Framework\MockObject\MockObject + * @var Redirect|MockObject */ protected $resultRedirectMock; /** - * @var \Magento\Framework\Controller\Result\Forward|\PHPUnit\Framework\MockObject\MockObject + * @var Forward|MockObject */ protected $resultForwardMock; protected function setUp() { - $this->wishlistProviderMock = $this->getMockBuilder(\Magento\Wishlist\Controller\Shared\WishlistProvider::class) + $this->wishlistProviderMock = $this->getMockBuilder(WishlistProvider::class) ->disableOriginalConstructor() ->getMock(); - $this->itemCarrierMock = $this->getMockBuilder(\Magento\Wishlist\Model\ItemCarrier::class) + $this->itemCarrierMock = $this->getMockBuilder(ItemCarrier::class) ->disableOriginalConstructor() ->getMock(); - $this->wishlistMock = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class) + $this->wishlistMock = $this->getMockBuilder(Wishlist::class) ->disableOriginalConstructor() ->getMock(); - $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) + $this->requestMock = $this->getMockBuilder(Http::class) ->disableOriginalConstructor() ->getMock(); - $this->resultFactoryMock = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class) + $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class) ->disableOriginalConstructor() ->getMock(); - $this->resultRedirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) + $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) ->disableOriginalConstructor() ->getMock(); - $this->resultForwardMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Forward::class) + $this->resultForwardMock = $this->getMockBuilder(Forward::class) ->disableOriginalConstructor() ->getMock(); @@ -93,21 +97,11 @@ protected function setUp() ] ); - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->context = $this->objectManagerHelper->getObject( - \Magento\Framework\App\Action\Context::class, - [ - 'request' => $this->requestMock, - 'resultFactory' => $this->resultFactoryMock - ] - ); - $this->allcartController = $this->objectManagerHelper->getObject( - \Magento\Wishlist\Controller\Shared\Allcart::class, - [ - 'context' => $this->context, - 'wishlistProvider' => $this->wishlistProviderMock, - 'itemCarrier' => $this->itemCarrierMock - ] + $this->allcartController = new Allcart( + $this->itemCarrierMock, + $this->requestMock, + $this->resultFactoryMock, + $this->wishlistProviderMock ); } From a002bf27f2a680bde1d13f82fb867a8bbb65a372 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 30 Mar 2020 11:05:56 +0200 Subject: [PATCH 03/66] PSR2 linted --- app/code/Magento/Wishlist/Controller/Shared/Allcart.php | 2 +- .../Wishlist/Test/Unit/Controller/Shared/AllcartTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index 8d160d270a6f0..89c1b88d9568e 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -15,7 +15,7 @@ use Magento\Framework\Controller\Result\Redirect; use Magento\Wishlist\Model\ItemCarrier; -class Allcart implements HttpGetActionInterface +class Allcart implements HttpGetActionInterface { /** * @var ItemCarrier diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index 4422c13a72e60..9b931290befbd 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Wishlist\Test\Unit\Controller\Shared; use Magento\Framework\App\Action\Context; From df2c759db53ef19d4f1d37bfdca6a02a76fde27c Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 30 Mar 2020 12:32:26 +0200 Subject: [PATCH 04/66] Implement ActionInterface for Wishlist/Shared/Cart + unit test --- .../Wishlist/Controller/Shared/Cart.php | 64 ++++++++++----- .../Test/Unit/Controller/Shared/CartTest.php | 81 ++++++++++--------- 2 files changed, 88 insertions(+), 57 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Cart.php b/app/code/Magento/Wishlist/Controller/Shared/Cart.php index 38f100602972a..77dc52e05f077 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Cart.php @@ -3,16 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + namespace Magento\Wishlist\Controller\Shared; use Magento\Catalog\Model\Product\Exception as ProductException; use Magento\Checkout\Helper\Cart as CartHelper; use Magento\Checkout\Model\Cart as CustomerCart; -use Magento\Framework\App\Action\Context as ActionContext; use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\Result\Redirect as ResultRedirect; use Magento\Framework\Escaper; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; +use Magento\Framework\App\Response\RedirectInterface; use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\Item\OptionFactory; use Magento\Wishlist\Model\ItemFactory; @@ -23,55 +29,73 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Cart extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface +class Cart implements HttpGetActionInterface { /** * @var CustomerCart */ - protected $cart; + private $cart; /** * @var OptionFactory */ - protected $optionFactory; + private $optionFactory; /** * @var ItemFactory */ - protected $itemFactory; + private $itemFactory; /** * @var CartHelper */ - protected $cartHelper; + private $cartHelper; /** * @var Escaper */ - protected $escaper; + private $escaper; + + /** + * @var RequestInterface + */ + private $request; + + /** + * @var RedirectInterface + */ + private $redirect; + + /** + * @var MessageManagerInterface + */ + private $messageManager; /** - * @param ActionContext $context - * @param CustomerCart $cart - * @param OptionFactory $optionFactory - * @param ItemFactory $itemFactory - * @param CartHelper $cartHelper - * @param Escaper $escaper + * @var ResultFactory */ + private $resultFactory; + public function __construct( - ActionContext $context, CustomerCart $cart, OptionFactory $optionFactory, ItemFactory $itemFactory, CartHelper $cartHelper, - Escaper $escaper + Escaper $escaper, + RequestInterface $request, + RedirectInterface $redirect, + MessageManagerInterface $messageManager, + ResultFactory $resultFactory ) { $this->cart = $cart; $this->optionFactory = $optionFactory; $this->itemFactory = $itemFactory; $this->cartHelper = $cartHelper; $this->escaper = $escaper; - parent::__construct($context); + $this->request = $request; + $this->redirect = $redirect; + $this->messageManager = $messageManager; + $this->resultFactory = $resultFactory; } /** @@ -80,17 +104,17 @@ public function __construct( * If Product has required options - redirect * to product view page with message about needed defined required options * - * @return \Magento\Framework\Controller\Result\Redirect + * @inheritDoc */ public function execute() { - $itemId = (int)$this->getRequest()->getParam('item'); + $itemId = (int)$this->request->getParam('item'); /* @var $item Item */ $item = $this->itemFactory->create() ->load($itemId); - $redirectUrl = $this->_redirect->getRefererUrl(); + $redirectUrl = $this->redirect->getRefererUrl(); try { /** @var OptionCollection $options */ @@ -120,7 +144,7 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, __('We can\'t add the item to the cart right now.')); } - /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + /** @var ResultRedirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($redirectUrl); return $resultRedirect; diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index eba5666114139..c495ea6651342 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -3,9 +3,11 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Wishlist\Test\Unit\Controller\Shared; use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Exception; use Magento\Checkout\Helper\Cart as CartHelper; use Magento\Checkout\Model\Cart; use Magento\Framework\App\Action\Context as ActionContext; @@ -23,80 +25,82 @@ use Magento\Wishlist\Model\Item\OptionFactory; use Magento\Wishlist\Model\ItemFactory; use Magento\Wishlist\Model\ResourceModel\Item\Option\Collection as OptionCollection; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class CartTest extends \PHPUnit\Framework\TestCase +class CartTest extends TestCase { - /** @var SharedCart|\PHPUnit\Framework\MockObject\MockObject */ + /** @var SharedCart|MockObject */ protected $model; - /** @var RequestInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var RequestInterface|MockObject */ protected $request; - /** @var ManagerInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ManagerInterface|MockObject */ protected $messageManager; - /** @var ActionContext|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ActionContext|MockObject */ protected $context; - /** @var Cart|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Cart|MockObject */ protected $cart; - /** @var CartHelper|\PHPUnit\Framework\MockObject\MockObject */ + /** @var CartHelper|MockObject */ protected $cartHelper; - /** @var Quote|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Quote|MockObject */ protected $quote; - /** @var OptionCollection|\PHPUnit\Framework\MockObject\MockObject */ + /** @var OptionCollection|MockObject */ protected $optionCollection; - /** @var OptionFactory|\PHPUnit\Framework\MockObject\MockObject */ + /** @var OptionFactory|MockObject */ protected $optionFactory; - /** @var Option|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Option|MockObject */ protected $option; - /** @var ItemFactory|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ItemFactory|MockObject */ protected $itemFactory; - /** @var Item|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Item|MockObject */ protected $item; - /** @var Escaper|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Escaper|MockObject */ protected $escaper; - /** @var RedirectInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var RedirectInterface|MockObject */ protected $redirect; - /** @var ResultFactory|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ResultFactory|MockObject */ protected $resultFactory; - /** @var Redirect|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Redirect|MockObject */ protected $resultRedirect; - /** @var Product|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Product|MockObject */ protected $product; protected function setUp() { - $this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class) + $this->request = $this->getMockBuilder(RequestInterface::class) ->getMockForAbstractClass(); - $this->redirect = $this->getMockBuilder(\Magento\Framework\App\Response\RedirectInterface::class) + $this->redirect = $this->getMockBuilder(RedirectInterface::class) ->getMockForAbstractClass(); - $this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class) + $this->messageManager = $this->getMockBuilder(ManagerInterface::class) ->getMockForAbstractClass(); - $this->resultRedirect = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) + $this->resultRedirect = $this->getMockBuilder(Redirect::class) ->disableOriginalConstructor() ->getMock(); - $this->resultFactory = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class) + $this->resultFactory = $this->getMockBuilder(ResultFactory::class) ->disableOriginalConstructor() ->getMock(); $this->resultFactory->expects($this->once()) @@ -104,7 +108,7 @@ protected function setUp() ->with(ResultFactory::TYPE_REDIRECT) ->willReturn($this->resultRedirect); - $this->context = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class) + $this->context = $this->getMockBuilder(ActionContext::class) ->disableOriginalConstructor() ->getMock(); $this->context->expects($this->any()) @@ -120,28 +124,28 @@ protected function setUp() ->method('getResultFactory') ->willReturn($this->resultFactory); - $this->cart = $this->getMockBuilder(\Magento\Checkout\Model\Cart::class) + $this->cart = $this->getMockBuilder(Cart::class) ->disableOriginalConstructor() ->getMock(); - $this->cartHelper = $this->getMockBuilder(\Magento\Checkout\Helper\Cart::class) + $this->cartHelper = $this->getMockBuilder(CartHelper::class) ->disableOriginalConstructor() ->getMock(); - $this->quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class) + $this->quote = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() ->setMethods(['getHasError']) ->getMock(); $this->optionCollection = $this->getMockBuilder( - \Magento\Wishlist\Model\ResourceModel\Item\Option\Collection::class + OptionCollection::class )->disableOriginalConstructor()->getMock(); - $this->option = $this->getMockBuilder(\Magento\Wishlist\Model\Item\Option::class) + $this->option = $this->getMockBuilder(Option::class) ->disableOriginalConstructor() ->getMock(); - $this->optionFactory = $this->getMockBuilder(\Magento\Wishlist\Model\Item\OptionFactory::class) + $this->optionFactory = $this->getMockBuilder(OptionFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); @@ -149,11 +153,11 @@ protected function setUp() ->method('create') ->willReturn($this->option); - $this->item = $this->getMockBuilder(\Magento\Wishlist\Model\Item::class) + $this->item = $this->getMockBuilder(Item::class) ->disableOriginalConstructor() ->getMock(); - $this->itemFactory = $this->getMockBuilder(\Magento\Wishlist\Model\ItemFactory::class) + $this->itemFactory = $this->getMockBuilder(ItemFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); @@ -161,21 +165,24 @@ protected function setUp() ->method('create') ->willReturn($this->item); - $this->escaper = $this->getMockBuilder(\Magento\Framework\Escaper::class) + $this->escaper = $this->getMockBuilder(Escaper::class) ->disableOriginalConstructor() ->getMock(); - $this->product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + $this->product = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() ->getMock(); $this->model = new SharedCart( - $this->context, $this->cart, $this->optionFactory, $this->itemFactory, $this->cartHelper, - $this->escaper + $this->escaper, + $this->request, + $this->redirect, + $this->messageManager, + $this->resultFactory ); } @@ -353,7 +360,7 @@ public function testExecuteProductException() $this->option->expects($this->once()) ->method('getCollection') - ->willThrowException(new \Magento\Catalog\Model\Product\Exception(__('LocalizedException'))); + ->willThrowException(new Exception(__('LocalizedException'))); $this->resultRedirect->expects($this->once()) ->method('setUrl') From 3ac458b2e4442d4b0fc3e7de672d7562c1c85607 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Wed, 13 May 2020 15:06:54 +0200 Subject: [PATCH 05/66] Static test fixes --- .../Magento/Wishlist/Controller/Shared/Allcart.php | 8 +++++++- app/code/Magento/Wishlist/Controller/Shared/Cart.php | 11 +++++++++++ .../Wishlist/Test/Unit/Controller/Shared/CartTest.php | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index 89c1b88d9568e..b6e93d7047c76 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -37,6 +37,12 @@ class Allcart implements HttpGetActionInterface */ private $resultFactory; + /** + * @param ItemCarrier $itemCarrier + * @param RequestInterface $request + * @param ResultFactory $resultFactory + * @param WishlistProvider $wishlistProvider + */ public function __construct( ItemCarrier $itemCarrier, RequestInterface $request, @@ -52,7 +58,7 @@ public function __construct( /** * Add all items from wishlist to shopping cart * - * @inheritDoc + * {@inheritDoc} */ public function execute() { diff --git a/app/code/Magento/Wishlist/Controller/Shared/Cart.php b/app/code/Magento/Wishlist/Controller/Shared/Cart.php index 77dc52e05f077..df023ffc01ddf 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Cart.php @@ -76,6 +76,17 @@ class Cart implements HttpGetActionInterface */ private $resultFactory; + /** + * @param CustomerCart $cart + * @param OptionFactory $optionFactory + * @param ItemFactory $itemFactory + * @param CartHelper $cartHelper + * @param Escaper $escaper + * @param RequestInterface $request + * @param RedirectInterface $redirect + * @param MessageManagerInterface $messageManager + * @param ResultFactory $resultFactory + */ public function __construct( CustomerCart $cart, OptionFactory $optionFactory, diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index c495ea6651342..43f82c1722bde 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -85,6 +85,7 @@ class CartTest extends TestCase /** @var Product|MockObject */ protected $product; + // phpcs:ignore Generic.Files.LineLength.TooLong protected function setUp() { $this->request = $this->getMockBuilder(RequestInterface::class) From f4744395fa245230386c65d00405dfba665dc868 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Wed, 13 May 2020 16:14:53 +0200 Subject: [PATCH 06/66] suppress ExcessiveMethodLength notice --- .../Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index 76ac73d837f77..0c284d1c917b9 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -86,7 +86,9 @@ class CartTest extends TestCase /** @var Product|MockObject */ protected $product; - // phpcs:ignore Generic.Files.LineLength.TooLong + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ protected function setUp(): void { $this->request = $this->getMockBuilder(RequestInterface::class) From 204d0c3528fabf95c0554731dc37351bbeb26cc9 Mon Sep 17 00:00:00 2001 From: Ynhockey Date: Thu, 4 Jun 2020 16:41:27 +0300 Subject: [PATCH 07/66] Grammar fixes in Registry.php --- lib/internal/Magento/Framework/Registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Registry.php b/lib/internal/Magento/Framework/Registry.php index d1bc227437d5f..b642ffd1f957f 100644 --- a/lib/internal/Magento/Framework/Registry.php +++ b/lib/internal/Magento/Framework/Registry.php @@ -9,7 +9,7 @@ * Registry model. Used to manage values in registry * * Registry usage as a shared service introduces temporal, hard to detect coupling into system. - * It's usage should be avoid. Use service classes or data providers instead. + * Its usage should be avoided. Use service classes or data providers instead. * * @api * @deprecated From eface05ef1d45660670c2b1bab2cb791235cd91c Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 5 Jun 2020 11:48:30 +0200 Subject: [PATCH 08/66] Use Variable for border-radius The border-radius was hard coded, so i changed it to: @button__border-radius --- app/design/frontend/Magento/blank/web/css/source/_extends.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/design/frontend/Magento/blank/web/css/source/_extends.less b/app/design/frontend/Magento/blank/web/css/source/_extends.less index 5bdaa4c3c35a3..690b89f42b419 100644 --- a/app/design/frontend/Magento/blank/web/css/source/_extends.less +++ b/app/design/frontend/Magento/blank/web/css/source/_extends.less @@ -1110,7 +1110,7 @@ .abs-shopping-cart-items { .action { &.continue { - border-radius: 3px; + border-radius: @button__border-radius; font-weight: @font-weight__bold; .lib-link-as-button(); .lib-button( From 2dfa2218604b370840935e65e982eac02f8afa68 Mon Sep 17 00:00:00 2001 From: Savvas Radevic Date: Fri, 19 Jun 2020 18:19:47 +0200 Subject: [PATCH 09/66] #28802: Fix typo retires => retries #28802: Fix typo retires => retries --- setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php index e864a81ffcc0e..4a3a02b37a6ab 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php @@ -40,7 +40,7 @@ class Session implements ConfigOptionsListInterface const INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS = 'session-save-redis-sentinel-servers'; const INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER = 'session-save-redis-sentinel-master'; const INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER = 'session-save-redis-sentinel-verify-master'; - const INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES = 'session-save-redis-sentinel-connect-retires'; + const INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES = 'session-save-redis-sentinel-connect-retries'; const CONFIG_PATH_SESSION_REDIS = 'session/redis'; const CONFIG_PATH_SESSION_REDIS_HOST = 'session/redis/host'; From 4a8536439280fe98692020ce570e64b32555764d Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Fri, 26 Jun 2020 11:57:18 +0200 Subject: [PATCH 10/66] added extend Action back, updated tests --- .../Magento/Wishlist/Controller/Shared/Allcart.php | 9 +++++++-- app/code/Magento/Wishlist/Controller/Shared/Cart.php | 11 ++++++++--- .../Test/Unit/Controller/Shared/AllcartTest.php | 12 ++++++++---- .../Test/Unit/Controller/Shared/CartTest.php | 1 + 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index b6e93d7047c76..17ee92e8c1307 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -8,14 +8,16 @@ namespace Magento\Wishlist\Controller\Shared; +use Magento\Framework\App\Action\Action; +use Magento\Framework\App\Action\Context; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\Result\Forward; use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultFactory; use Magento\Wishlist\Model\ItemCarrier; -class Allcart implements HttpGetActionInterface +class Allcart extends Action implements HttpGetActionInterface { /** * @var ItemCarrier @@ -38,12 +40,14 @@ class Allcart implements HttpGetActionInterface private $resultFactory; /** + * @param Context $context * @param ItemCarrier $itemCarrier * @param RequestInterface $request * @param ResultFactory $resultFactory * @param WishlistProvider $wishlistProvider */ public function __construct( + Context $context, ItemCarrier $itemCarrier, RequestInterface $request, ResultFactory $resultFactory, @@ -53,6 +57,7 @@ public function __construct( $this->request = $request; $this->resultFactory = $resultFactory; $this->wishlistProvider = $wishlistProvider; + parent::__construct($context); } /** diff --git a/app/code/Magento/Wishlist/Controller/Shared/Cart.php b/app/code/Magento/Wishlist/Controller/Shared/Cart.php index df023ffc01ddf..b6e7904ae412c 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Cart.php @@ -11,14 +11,16 @@ use Magento\Catalog\Model\Product\Exception as ProductException; use Magento\Checkout\Helper\Cart as CartHelper; use Magento\Checkout\Model\Cart as CustomerCart; +use Magento\Framework\App\Action\Action; +use Magento\Framework\App\Action\Context as ActionContext; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Controller\Result\Redirect as ResultRedirect; +use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Escaper; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; -use Magento\Framework\App\Response\RedirectInterface; use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\Item\OptionFactory; use Magento\Wishlist\Model\ItemFactory; @@ -29,7 +31,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Cart implements HttpGetActionInterface +class Cart extends Action implements HttpGetActionInterface { /** * @var CustomerCart @@ -77,6 +79,7 @@ class Cart implements HttpGetActionInterface private $resultFactory; /** + * @param ActionContext $context * @param CustomerCart $cart * @param OptionFactory $optionFactory * @param ItemFactory $itemFactory @@ -88,6 +91,7 @@ class Cart implements HttpGetActionInterface * @param ResultFactory $resultFactory */ public function __construct( + ActionContext $context, CustomerCart $cart, OptionFactory $optionFactory, ItemFactory $itemFactory, @@ -107,6 +111,7 @@ public function __construct( $this->redirect = $redirect; $this->messageManager = $messageManager; $this->resultFactory = $resultFactory; + parent::__construct($context); } /** diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index 239f65f50c424..e80404b55ffdb 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -27,14 +27,14 @@ class AllcartTest extends TestCase protected $allcartController; /** - * @var Context + * @var WishlistProvider|MockObject */ - protected $context; + protected $wishlistProviderMock; /** - * @var WishlistProvider|MockObject + * @var Context|MockObject */ - protected $wishlistProviderMock; + protected $contextMock; /** * @var ItemCarrier|MockObject @@ -74,6 +74,9 @@ protected function setUp(): void $this->itemCarrierMock = $this->getMockBuilder(ItemCarrier::class) ->disableOriginalConstructor() ->getMock(); + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); $this->wishlistMock = $this->getMockBuilder(Wishlist::class) ->disableOriginalConstructor() ->getMock(); @@ -100,6 +103,7 @@ protected function setUp(): void ); $this->allcartController = new Allcart( + $this->contextMock, $this->itemCarrierMock, $this->requestMock, $this->resultFactoryMock, diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index 0c284d1c917b9..c0181ab061529 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -178,6 +178,7 @@ protected function setUp(): void ->getMock(); $this->model = new SharedCart( + $this->context, $this->cart, $this->optionFactory, $this->itemFactory, From 979ab1f1c37e4e6534a0a9905e166218d792722f Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 29 Jun 2020 10:30:29 +0200 Subject: [PATCH 11/66] removed unnecessary properties --- .../Wishlist/Controller/Shared/Allcart.php | 19 +-------- .../Wishlist/Controller/Shared/Cart.php | 41 ++----------------- 2 files changed, 4 insertions(+), 56 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index 17ee92e8c1307..96b3102a6f443 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -11,7 +11,6 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Action\HttpGetActionInterface; -use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\Forward; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; @@ -29,33 +28,17 @@ class Allcart extends Action implements HttpGetActionInterface */ private $wishlistProvider; - /** - * @var RequestInterface - */ - private $request; - - /** - * @var ResultFactory - */ - private $resultFactory; - /** * @param Context $context * @param ItemCarrier $itemCarrier - * @param RequestInterface $request - * @param ResultFactory $resultFactory * @param WishlistProvider $wishlistProvider */ public function __construct( Context $context, ItemCarrier $itemCarrier, - RequestInterface $request, - ResultFactory $resultFactory, WishlistProvider $wishlistProvider ) { $this->itemCarrier = $itemCarrier; - $this->request = $request; - $this->resultFactory = $resultFactory; $this->wishlistProvider = $wishlistProvider; parent::__construct($context); } @@ -74,7 +57,7 @@ public function execute() $resultForward->forward('noroute'); return $resultForward; } - $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->request->getParam('qty')); + $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty')); /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($redirectUrl); diff --git a/app/code/Magento/Wishlist/Controller/Shared/Cart.php b/app/code/Magento/Wishlist/Controller/Shared/Cart.php index b6e7904ae412c..9fdadb917a920 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Cart.php @@ -14,13 +14,10 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context as ActionContext; use Magento\Framework\App\Action\HttpGetActionInterface; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Controller\Result\Redirect as ResultRedirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Escaper; use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\Item\OptionFactory; use Magento\Wishlist\Model\ItemFactory; @@ -58,26 +55,6 @@ class Cart extends Action implements HttpGetActionInterface */ private $escaper; - /** - * @var RequestInterface - */ - private $request; - - /** - * @var RedirectInterface - */ - private $redirect; - - /** - * @var MessageManagerInterface - */ - private $messageManager; - - /** - * @var ResultFactory - */ - private $resultFactory; - /** * @param ActionContext $context * @param CustomerCart $cart @@ -85,10 +62,6 @@ class Cart extends Action implements HttpGetActionInterface * @param ItemFactory $itemFactory * @param CartHelper $cartHelper * @param Escaper $escaper - * @param RequestInterface $request - * @param RedirectInterface $redirect - * @param MessageManagerInterface $messageManager - * @param ResultFactory $resultFactory */ public function __construct( ActionContext $context, @@ -96,21 +69,13 @@ public function __construct( OptionFactory $optionFactory, ItemFactory $itemFactory, CartHelper $cartHelper, - Escaper $escaper, - RequestInterface $request, - RedirectInterface $redirect, - MessageManagerInterface $messageManager, - ResultFactory $resultFactory + Escaper $escaper ) { $this->cart = $cart; $this->optionFactory = $optionFactory; $this->itemFactory = $itemFactory; $this->cartHelper = $cartHelper; $this->escaper = $escaper; - $this->request = $request; - $this->redirect = $redirect; - $this->messageManager = $messageManager; - $this->resultFactory = $resultFactory; parent::__construct($context); } @@ -124,13 +89,13 @@ public function __construct( */ public function execute() { - $itemId = (int)$this->request->getParam('item'); + $itemId = (int)$this->getRequest()->getParam('item'); /* @var $item Item */ $item = $this->itemFactory->create() ->load($itemId); - $redirectUrl = $this->redirect->getRefererUrl(); + $redirectUrl = $this->_redirect->getRefererUrl(); try { /** @var OptionCollection $options */ From 6d8f77c7ffe52075d0b5ff117b39100bd06e1474 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 29 Jun 2020 12:10:08 +0200 Subject: [PATCH 12/66] fixed tests --- .../Wishlist/Test/Unit/Controller/Shared/AllcartTest.php | 2 -- .../Wishlist/Test/Unit/Controller/Shared/CartTest.php | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index e80404b55ffdb..f44fdf1b6568b 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -105,8 +105,6 @@ protected function setUp(): void $this->allcartController = new Allcart( $this->contextMock, $this->itemCarrierMock, - $this->requestMock, - $this->resultFactoryMock, $this->wishlistProviderMock ); } diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index c0181ab061529..cee4b39ecfc2f 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -183,11 +183,7 @@ protected function setUp(): void $this->optionFactory, $this->itemFactory, $this->cartHelper, - $this->escaper, - $this->request, - $this->redirect, - $this->messageManager, - $this->resultFactory + $this->escaper ); } From 2616ba14c89b3cb85a88399bca245b7ea764f4e2 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Mon, 29 Jun 2020 12:29:13 +0200 Subject: [PATCH 13/66] fixed tests --- .../Unit/Controller/Shared/AllcartTest.php | 24 ------------------- .../Test/Unit/Controller/Shared/CartTest.php | 3 --- 2 files changed, 27 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index f44fdf1b6568b..6c96cefe8f92f 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -77,30 +77,6 @@ protected function setUp(): void $this->contextMock = $this->getMockBuilder(Context::class) ->disableOriginalConstructor() ->getMock(); - $this->wishlistMock = $this->getMockBuilder(Wishlist::class) - ->disableOriginalConstructor() - ->getMock(); - $this->requestMock = $this->getMockBuilder(Http::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultForwardMock = $this->getMockBuilder(Forward::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->resultFactoryMock->expects($this->any()) - ->method('create') - ->willReturnMap( - [ - [ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], - [ResultFactory::TYPE_FORWARD, [], $this->resultForwardMock] - ] - ); $this->allcartController = new Allcart( $this->contextMock, diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index cee4b39ecfc2f..da9c2d536830f 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -173,9 +173,6 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMock(); - $this->product = $this->getMockBuilder(Product::class) - ->disableOriginalConstructor() - ->getMock(); $this->model = new SharedCart( $this->context, From e2db162bb51e794809dbc402a7e52c21e7c43c04 Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Tue, 30 Jun 2020 15:23:49 +0200 Subject: [PATCH 14/66] reverted fixed tests --- .../Test/Unit/Controller/Shared/AllcartTest.php | 15 +++++++++++++++ .../Test/Unit/Controller/Shared/CartTest.php | 3 +++ 2 files changed, 18 insertions(+) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index 6c96cefe8f92f..4c2175a55ce9d 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -77,6 +77,21 @@ protected function setUp(): void $this->contextMock = $this->getMockBuilder(Context::class) ->disableOriginalConstructor() ->getMock(); + $this->wishlistMock = $this->getMockBuilder(Wishlist::class) + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock = $this->getMockBuilder(Http::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder(Forward::class) + ->disableOriginalConstructor() + ->getMock(); $this->allcartController = new Allcart( $this->contextMock, diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index da9c2d536830f..cee4b39ecfc2f 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -173,6 +173,9 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMock(); + $this->product = $this->getMockBuilder(Product::class) + ->disableOriginalConstructor() + ->getMock(); $this->model = new SharedCart( $this->context, From 2f080644f1f1f7cfed677a9eb3008932fcef9a2c Mon Sep 17 00:00:00 2001 From: Rudolf Vince Date: Tue, 30 Jun 2020 17:07:06 +0200 Subject: [PATCH 15/66] objectmanager added to test --- .../Unit/Controller/Shared/AllcartTest.php | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index 4c2175a55ce9d..5fa5eb748ac65 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -12,6 +12,7 @@ use Magento\Framework\Controller\Result\Forward; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Wishlist\Controller\Shared\Allcart; use Magento\Wishlist\Controller\Shared\WishlistProvider; use Magento\Wishlist\Model\ItemCarrier; @@ -26,6 +27,11 @@ class AllcartTest extends TestCase */ protected $allcartController; + /** + * @var ObjectManagerHelper + */ + protected $objectManagerHelper; + /** * @var WishlistProvider|MockObject */ @@ -34,7 +40,7 @@ class AllcartTest extends TestCase /** * @var Context|MockObject */ - protected $contextMock; + protected $context; /** * @var ItemCarrier|MockObject @@ -74,9 +80,6 @@ protected function setUp(): void $this->itemCarrierMock = $this->getMockBuilder(ItemCarrier::class) ->disableOriginalConstructor() ->getMock(); - $this->contextMock = $this->getMockBuilder(Context::class) - ->disableOriginalConstructor() - ->getMock(); $this->wishlistMock = $this->getMockBuilder(Wishlist::class) ->disableOriginalConstructor() ->getMock(); @@ -93,8 +96,26 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMock(); + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->willReturnMap( + [ + [ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], + [ResultFactory::TYPE_FORWARD, [], $this->resultForwardMock] + ] + ); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->context = $this->objectManagerHelper->getObject( + Context::class, + [ + 'request' => $this->requestMock, + 'resultFactory' => $this->resultFactoryMock + ] + ); + $this->allcartController = new Allcart( - $this->contextMock, + $this->context, $this->itemCarrierMock, $this->wishlistProviderMock ); From 21f9fa4e30295d3e2e5d3c548922aa7e57421dce Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Fri, 3 Jul 2020 12:02:18 +0300 Subject: [PATCH 16/66] impr --- .../Wishlist/Controller/Shared/Allcart.php | 20 +- .../Wishlist/Controller/Shared/Cart.php | 11 +- .../Unit/Controller/Shared/AllcartTest.php | 86 ++++----- .../Test/Unit/Controller/Shared/CartTest.php | 178 ++++++++---------- 4 files changed, 134 insertions(+), 161 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index 96b3102a6f443..c1e908cc0f49e 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -16,30 +16,33 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Wishlist\Model\ItemCarrier; +/** + * Wishlist Allcart Controller + */ class Allcart extends Action implements HttpGetActionInterface { /** - * @var ItemCarrier + * @var WishlistProvider */ - private $itemCarrier; + protected $wishlistProvider; /** - * @var WishlistProvider + * @var ItemCarrier */ - private $wishlistProvider; + protected $itemCarrier; /** * @param Context $context - * @param ItemCarrier $itemCarrier * @param WishlistProvider $wishlistProvider + * @param ItemCarrier $itemCarrier */ public function __construct( Context $context, - ItemCarrier $itemCarrier, - WishlistProvider $wishlistProvider + WishlistProvider $wishlistProvider, + ItemCarrier $itemCarrier ) { - $this->itemCarrier = $itemCarrier; $this->wishlistProvider = $wishlistProvider; + $this->itemCarrier = $itemCarrier; parent::__construct($context); } @@ -61,6 +64,7 @@ public function execute() /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($redirectUrl); + return $resultRedirect; } } diff --git a/app/code/Magento/Wishlist/Controller/Shared/Cart.php b/app/code/Magento/Wishlist/Controller/Shared/Cart.php index 9fdadb917a920..bee1e187be648 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Cart.php @@ -33,27 +33,27 @@ class Cart extends Action implements HttpGetActionInterface /** * @var CustomerCart */ - private $cart; + protected $cart; /** * @var OptionFactory */ - private $optionFactory; + protected $optionFactory; /** * @var ItemFactory */ - private $itemFactory; + protected $itemFactory; /** * @var CartHelper */ - private $cartHelper; + protected $cartHelper; /** * @var Escaper */ - private $escaper; + protected $escaper; /** * @param ActionContext $context @@ -128,6 +128,7 @@ public function execute() /** @var ResultRedirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($redirectUrl); + return $resultRedirect; } } diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php index 5fa5eb748ac65..d9339af8144f4 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + declare(strict_types=1); namespace Magento\Wishlist\Test\Unit\Controller\Shared; @@ -20,83 +21,60 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +/** + * Test for \Magento\Wishlist\Controller\Shared\Allcart. + */ class AllcartTest extends TestCase { /** * @var Allcart */ - protected $allcartController; - - /** - * @var ObjectManagerHelper - */ - protected $objectManagerHelper; + private $allcartController; /** * @var WishlistProvider|MockObject */ - protected $wishlistProviderMock; - - /** - * @var Context|MockObject - */ - protected $context; + private $wishlistProviderMock; /** * @var ItemCarrier|MockObject */ - protected $itemCarrierMock; + private $itemCarrierMock; /** * @var Wishlist|MockObject */ - protected $wishlistMock; + private $wishlistMock; /** * @var Http|MockObject */ - protected $requestMock; - - /** - * @var ResultFactory|MockObject - */ - protected $resultFactoryMock; + private $requestMock; /** * @var Redirect|MockObject */ - protected $resultRedirectMock; + private $resultRedirectMock; /** * @var Forward|MockObject */ - protected $resultForwardMock; + private $resultForwardMock; + /** + * @inheritDoc + */ protected function setUp(): void { - $this->wishlistProviderMock = $this->getMockBuilder(WishlistProvider::class) - ->disableOriginalConstructor() - ->getMock(); - $this->itemCarrierMock = $this->getMockBuilder(ItemCarrier::class) - ->disableOriginalConstructor() - ->getMock(); - $this->wishlistMock = $this->getMockBuilder(Wishlist::class) - ->disableOriginalConstructor() - ->getMock(); - $this->requestMock = $this->getMockBuilder(Http::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultForwardMock = $this->getMockBuilder(Forward::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->resultFactoryMock->expects($this->any()) + $this->wishlistProviderMock = $this->createMock(WishlistProvider::class); + $this->itemCarrierMock = $this->createMock(ItemCarrier::class); + $this->wishlistMock = $this->createMock(Wishlist::class); + $this->requestMock = $this->createMock(Http::class); + $resultFactoryMock = $this->createMock(ResultFactory::class); + $this->resultRedirectMock = $this->createMock(Redirect::class); + $this->resultForwardMock = $this->createMock(Forward::class); + + $resultFactoryMock->expects($this->any()) ->method('create') ->willReturnMap( [ @@ -105,19 +83,21 @@ protected function setUp(): void ] ); - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->context = $this->objectManagerHelper->getObject( + $objectManagerHelper = new ObjectManagerHelper($this); + $context = $objectManagerHelper->getObject( Context::class, [ 'request' => $this->requestMock, - 'resultFactory' => $this->resultFactoryMock + 'resultFactory' => $resultFactoryMock ] ); - - $this->allcartController = new Allcart( - $this->context, - $this->itemCarrierMock, - $this->wishlistProviderMock + $this->allcartController = $objectManagerHelper->getObject( + Allcart::class, + [ + 'context' => $context, + 'wishlistProvider' => $this->wishlistProviderMock, + 'itemCarrier' => $this->itemCarrierMock + ] ); } diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php index cee4b39ecfc2f..e6a127457a6c6 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Shared/CartTest.php @@ -30,158 +30,146 @@ use PHPUnit\Framework\TestCase; /** + * Test for \Magento\Wishlist\Controller\Shared\Cart. + * * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CartTest extends TestCase { - /** @var SharedCart|MockObject */ - protected $model; - - /** @var RequestInterface|MockObject */ - protected $request; - - /** @var ManagerInterface|MockObject */ - protected $messageManager; - - /** @var ActionContext|MockObject */ - protected $context; - - /** @var Cart|MockObject */ - protected $cart; + /** + * @var SharedCart|MockObject + */ + private $model; - /** @var CartHelper|MockObject */ - protected $cartHelper; + /** + * @var RequestInterface|MockObject + */ + private $request; - /** @var Quote|MockObject */ - protected $quote; + /** + * @var ManagerInterface|MockObject + */ + private $messageManager; - /** @var OptionCollection|MockObject */ - protected $optionCollection; + /** + * @var Cart|MockObject + */ + private $cart; - /** @var OptionFactory|MockObject */ - protected $optionFactory; + /** + * @var CartHelper|MockObject + */ + private $cartHelper; - /** @var Option|MockObject */ - protected $option; + /** + * @var Quote|MockObject + */ + private $quote; - /** @var ItemFactory|MockObject */ - protected $itemFactory; + /** + * @var OptionCollection|MockObject + */ + private $optionCollection; - /** @var Item|MockObject */ - protected $item; + /** + * @var Option|MockObject + */ + private $option; - /** @var Escaper|MockObject */ - protected $escaper; + /** + * @var Item|MockObject + */ + private $item; - /** @var RedirectInterface|MockObject */ - protected $redirect; + /** + * @var Escaper|MockObject + */ + private $escaper; - /** @var ResultFactory|MockObject */ - protected $resultFactory; + /** + * @var RedirectInterface|MockObject + */ + private $redirect; - /** @var Redirect|MockObject */ - protected $resultRedirect; + /** + * @var Redirect|MockObject + */ + private $resultRedirect; - /** @var Product|MockObject */ - protected $product; + /** + * @var Product|MockObject + */ + private $product; /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @inheritDoc */ protected function setUp(): void { - $this->request = $this->getMockBuilder(RequestInterface::class) - ->getMockForAbstractClass(); - - $this->redirect = $this->getMockBuilder(RedirectInterface::class) - ->getMockForAbstractClass(); + $this->request = $this->getMockForAbstractClass(RequestInterface::class); + $this->redirect = $this->getMockForAbstractClass(RedirectInterface::class); + $this->messageManager = $this->getMockForAbstractClass(ManagerInterface::class); + $this->resultRedirect = $this->createMock(Redirect::class); - $this->messageManager = $this->getMockBuilder(ManagerInterface::class) - ->getMockForAbstractClass(); - - $this->resultRedirect = $this->getMockBuilder(Redirect::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->resultFactory = $this->getMockBuilder(ResultFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resultFactory->expects($this->once()) + $resultFactory = $this->createMock(ResultFactory::class); + $resultFactory->expects($this->once()) ->method('create') ->with(ResultFactory::TYPE_REDIRECT) ->willReturn($this->resultRedirect); - $this->context = $this->getMockBuilder(ActionContext::class) + /** @var ActionContext|MockObject $context */ + $context = $this->getMockBuilder(ActionContext::class) ->disableOriginalConstructor() ->getMock(); - $this->context->expects($this->any()) + $context->expects($this->any()) ->method('getRequest') ->willReturn($this->request); - $this->context->expects($this->any()) + $context->expects($this->any()) ->method('getRedirect') ->willReturn($this->redirect); - $this->context->expects($this->any()) + $context->expects($this->any()) ->method('getMessageManager') ->willReturn($this->messageManager); - $this->context->expects($this->any()) + $context->expects($this->any()) ->method('getResultFactory') - ->willReturn($this->resultFactory); - - $this->cart = $this->getMockBuilder(Cart::class) - ->disableOriginalConstructor() - ->getMock(); + ->willReturn($resultFactory); - $this->cartHelper = $this->getMockBuilder(CartHelper::class) - ->disableOriginalConstructor() - ->getMock(); + $this->cart = $this->createMock(Cart::class); + $this->cartHelper = $this->createMock(CartHelper::class); $this->quote = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getHasError']) + ->addMethods(['getHasError']) ->getMock(); - $this->optionCollection = $this->getMockBuilder( - OptionCollection::class - )->disableOriginalConstructor()->getMock(); + $this->optionCollection = $this->createMock(OptionCollection::class); $this->option = $this->getMockBuilder(Option::class) ->disableOriginalConstructor() ->getMock(); - $this->optionFactory = $this->getMockBuilder(OptionFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->optionFactory->expects($this->once()) + /** @var OptionFactory|MockObject $optionFactory */ + $optionFactory = $this->createMock(OptionFactory::class); + $optionFactory->expects($this->once()) ->method('create') ->willReturn($this->option); - $this->item = $this->getMockBuilder(Item::class) - ->disableOriginalConstructor() - ->getMock(); + $this->item = $this->createMock(Item::class); - $this->itemFactory = $this->getMockBuilder(ItemFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->itemFactory->expects($this->once()) + $itemFactory = $this->createMock(ItemFactory::class); + $itemFactory->expects($this->once()) ->method('create') ->willReturn($this->item); - $this->escaper = $this->getMockBuilder(Escaper::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->product = $this->getMockBuilder(Product::class) - ->disableOriginalConstructor() - ->getMock(); + $this->escaper = $this->createMock(Escaper::class); + $this->product = $this->createMock(Product::class); $this->model = new SharedCart( - $this->context, + $context, $this->cart, - $this->optionFactory, - $this->itemFactory, + $optionFactory, + $itemFactory, $this->cartHelper, $this->escaper ); From 1b0f8df856aedb16d2afd731638fa9d2677cad45 Mon Sep 17 00:00:00 2001 From: Dmitry Tsymbal Date: Wed, 8 Jul 2020 17:13:05 +0300 Subject: [PATCH 17/66] Enabling Email To Friend Functionality --- ...gateToEmailToFriendSettingsActionGroup.xml | 15 ++++++++ ...ailToFriendOptionsAvailableActionGroup.xml | 18 ++++++++++ .../AdminConfigurationEmailToFriendPage.xml | 14 ++++++++ .../AdminCatalogEmailToFriendSettingsTest.xml | 34 +++++++++++++++++++ .../Section/AdminEmailToFriendSection.xml | 20 +++++++++++ 5 files changed, 101 insertions(+) create mode 100644 app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToEmailToFriendSettingsActionGroup.xml create mode 100644 app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminEmailToFriendOptionsAvailableActionGroup.xml create mode 100644 app/code/Magento/Backend/Test/Mftf/Page/AdminConfigurationEmailToFriendPage.xml create mode 100644 app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml create mode 100644 app/code/Magento/Config/Test/Mftf/Section/AdminEmailToFriendSection.xml diff --git a/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToEmailToFriendSettingsActionGroup.xml b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToEmailToFriendSettingsActionGroup.xml new file mode 100644 index 0000000000000..05903581747d9 --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToEmailToFriendSettingsActionGroup.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminEmailToFriendOptionsAvailableActionGroup.xml b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminEmailToFriendOptionsAvailableActionGroup.xml new file mode 100644 index 0000000000000..88152a2cb4f73 --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminEmailToFriendOptionsAvailableActionGroup.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/app/code/Magento/Backend/Test/Mftf/Page/AdminConfigurationEmailToFriendPage.xml b/app/code/Magento/Backend/Test/Mftf/Page/AdminConfigurationEmailToFriendPage.xml new file mode 100644 index 0000000000000..14bd514f1a16f --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/Page/AdminConfigurationEmailToFriendPage.xml @@ -0,0 +1,14 @@ + + + + + +
+ + diff --git a/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml b/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml new file mode 100644 index 0000000000000..79150854c5939 --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + <description value="Admin should be able to enable Email To A Friend functionality in Magento Admin backend and see additional options"/> + <group value="backend"/> + </annotations> + + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <magentoCLI stepKey="enableSendFriend" command="config:set sendfriend/email/enabled 1"/> + <magentoCLI stepKey="cacheClean" command="cache:clean config"/> + </before> + <after> + <magentoCLI stepKey="disableSendFriend" command="config:set sendfriend/email/enabled 0"/> + <magentoCLI stepKey="cacheClean" command="cache:clean config"/> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + + <actionGroup ref="AdminNavigateToEmailToFriendSettingsActionGroup" stepKey="navigateToSendFriendSettings"/> + <actionGroup ref="AssertAdminEmailToFriendOptionsAvailableActionGroup" stepKey="assertOptions"/> + </test> +</tests> diff --git a/app/code/Magento/Config/Test/Mftf/Section/AdminEmailToFriendSection.xml b/app/code/Magento/Config/Test/Mftf/Section/AdminEmailToFriendSection.xml new file mode 100644 index 0000000000000..956316ed5cb46 --- /dev/null +++ b/app/code/Magento/Config/Test/Mftf/Section/AdminEmailToFriendSection.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> + <section name="AdminEmailToFriendSection"> + <element name="DefaultLayoutsTab" type="button" selector=".entry-edit-head-link"/> + <element name="CheckIfTabExpand" type="button" selector=".entry-edit-head-link:not(.open)"/> + <element name="emailTemplate" type="input" selector="#sendfriend_email_template"/> + <element name="allowForGuests" type="input" selector="#sendfriend_email_allow_guest"/> + <element name="maxRecipients" type="input" selector="#sendfriend_email_max_recipients"/> + <element name="maxPerHour" type="input" selector="#sendfriend_email_max_per_hour"/> + <element name="limitSendingBy" type="input" selector="#sendfriend_email_check_by"/> + </section> +</sections> From 680ca2b76e5f64c1b629052930fe9663ca01e7a1 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk <grp-engcom-vendorworker-Kilo@adobe.com> Date: Wed, 15 Jul 2020 14:41:57 +0300 Subject: [PATCH 18/66] Added testCaseId to MFTF test. --- .../Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml b/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml index 79150854c5939..559c2d13218d1 100644 --- a/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml +++ b/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml @@ -15,6 +15,7 @@ <title value="Admin should be able to manage settings of Email To A Friend Functionality"/> <description value="Admin should be able to enable Email To A Friend functionality in Magento Admin backend and see additional options"/> <group value="backend"/> + <testCaseId value="MC-35895"/> </annotations> <before> From 44a650422ffebb6a33c92988c341e324f2d6f5b3 Mon Sep 17 00:00:00 2001 From: Dmitry Tsymbal <d.tsymbal@atwix.com> Date: Fri, 17 Jul 2020 11:22:52 +0300 Subject: [PATCH 19/66] Severity adding --- .../Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml b/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml index 79150854c5939..6aa5b103b8017 100644 --- a/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml +++ b/app/code/Magento/Backend/Test/Mftf/Test/AdminCatalogEmailToFriendSettingsTest.xml @@ -15,6 +15,7 @@ <title value="Admin should be able to manage settings of Email To A Friend Functionality"/> <description value="Admin should be able to enable Email To A Friend functionality in Magento Admin backend and see additional options"/> <group value="backend"/> + <severity value="MINOR"></severity> </annotations> <before> From e786d514ef72699bdedada6444665d882dd015c3 Mon Sep 17 00:00:00 2001 From: Will Wright <wwrig@guidance.com> Date: Tue, 28 Jul 2020 22:41:30 -0700 Subject: [PATCH 20/66] magento/magento2#29315: \Magento\Config\Model\Config\Source\Email\Template::toOptionArray throws error when setPath() is not called first - Guard against an edge case where toOptionArray is called without having set a path first --- .../Model/Config/Source/Email/Template.php | 10 ++-- .../Config/Source/Email/TemplateTest.php | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Config/Model/Config/Source/Email/Template.php b/app/code/Magento/Config/Model/Config/Source/Email/Template.php index ac168f16ca182..182faa53e5288 100644 --- a/app/code/Magento/Config/Model/Config/Source/Email/Template.php +++ b/app/code/Magento/Config/Model/Config/Source/Email/Template.php @@ -60,10 +60,12 @@ public function toOptionArray() $this->_coreRegistry->register('config_system_email_template', $collection); } $options = $collection->toOptionArray(); - $templateId = str_replace('/', '_', $this->getPath()); - $templateLabel = $this->_emailConfig->getTemplateLabel($templateId); - $templateLabel = __('%1 (Default)', $templateLabel); - array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]); + if (!empty($this->getPath())) { + $templateId = str_replace('/', '_', $this->getPath()); + $templateLabel = $this->_emailConfig->getTemplateLabel($templateId); + $templateLabel = __('%1 (Default)', $templateLabel); + array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]); + } return $options; } } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php index 356d1133aca81..74ab4baa4e990 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php @@ -102,4 +102,48 @@ public function testToOptionArray() $this->_model->setPath('template/new'); $this->assertEquals($expectedResult, $this->_model->toOptionArray()); } -} + + public function testToOptionArrayWithoutPath() + { + $collection = $this->createMock(Collection::class); + $collection->expects( + $this->once() + )->method( + 'toOptionArray' + )->willReturn( + [ + ['value' => 'template_one', 'label' => 'Template One'], + ['value' => 'template_two', 'label' => 'Template Two'], + ] + ); + + $this->_coreRegistry->expects( + $this->once() + )->method( + 'registry' + )->with( + 'config_system_email_template' + )->willReturn( + $collection + ); + + $this->_emailConfig->expects( + $this->never() + )->method( + 'getTemplateLabel' + )->with('') + ->willThrowException(new \UnexpectedValueException("Email template '' is not defined.")); + + $expectedResult = [ + [ + 'value' => 'template_one', + 'label' => 'Template One', + ], + [ + 'value' => 'template_two', + 'label' => 'Template Two', + ], + ]; + + $this->assertEquals($expectedResult, $this->_model->toOptionArray()); + }} From e0972bf2ac019a1b4645f2aaa7ac2e6016859fe5 Mon Sep 17 00:00:00 2001 From: Will Wright <wwrig@guidance.com> Date: Wed, 29 Jul 2020 22:15:00 -0700 Subject: [PATCH 21/66] magento/magento2#29315: \Magento\Config\Model\Config\Source\Email\Template::toOptionArray throws error when setPath() is not called first - Fix formatting for static tests --- .../Unit/Model/Config/Source/Email/TemplateTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php index 74ab4baa4e990..9b531280f66c6 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php @@ -131,8 +131,12 @@ public function testToOptionArrayWithoutPath() $this->never() )->method( 'getTemplateLabel' - )->with('') - ->willThrowException(new \UnexpectedValueException("Email template '' is not defined.")); + )->with( + '' + ) + ->willThrowException( + new \UnexpectedValueException("Email template '' is not defined.") + ); $expectedResult = [ [ @@ -146,4 +150,5 @@ public function testToOptionArrayWithoutPath() ]; $this->assertEquals($expectedResult, $this->_model->toOptionArray()); - }} + } +} From 8f43c639da9fc2f8fbb4394fc38889f718b584b6 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Thu, 30 Jul 2020 23:01:54 +0300 Subject: [PATCH 22/66] community-features#252 Create static test for action controllers. Add Legacy test to check if newly created controllers do not extend AbstractAction. --- .../Magento/App/Action/AbstractActionTest.php | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php new file mode 100644 index 0000000000000..472b557ab389f --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php @@ -0,0 +1,160 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Test\Legacy\App\Action; + +use Exception; +use Magento\Framework\App\Action\AbstractAction; +use Magento\Framework\App\ActionInterface; +use Magento\Framework\App\Utility\Files; +use Magento\Framework\Exception\LocalizedException; +use Magento\TestFramework\Utility\ClassNameExtractor; +use PHPUnit\Framework\TestCase; +use ReflectionClass; + +/** + * Test newly created controllers must do not extend AbstractAction. + */ +class AbstractActionTest extends TestCase +{ + /** + * @var ClassNameExtractor + */ + private $classNameExtractor; + + /** + * @var Files + */ + private $fileUtilities; + + /** + * @throws LocalizedException + */ + protected function setUp(): void + { + $this->classNameExtractor = new ClassNameExtractor(); + $this->fileUtilities = Files::init(); + } + + /** + * Test new + * + */ + public function testNewControllersDoNotExtendAbstractAction(): void + { + $files = $this->getTestFiles(); + $found = []; + + foreach ($files as $file) { + $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($file[0])); + + if ($class) { + try { + $classReflection = new ReflectionClass($class); + if ($classReflection->isSubclassOf(AbstractAction::class)) { + $found[] = $class; + } + } catch (Exception $exception) { + $this->addWarning('Skipped due to exception: ' . $class); + } + } + } + + $this->assertEmpty( + $found, + "The following new controller(s) extend " . AbstractAction::class . "\r\n" + . "All new controller classes must implement " . ActionInterface::class . " instead.\r\n" + . print_r($found, true) + ); + } + + /** + * Provide files for test. + * + * @return array + */ + private function getTestFiles(): array + { + $phpFiles = self::getAddedFilesList(self::getChangedFilesBaseDir()); + + $phpFiles = Files::composeDataSets($phpFiles); + $fileTypes = Files::INCLUDE_APP_CODE | Files::INCLUDE_LIBS | Files::AS_DATA_SET; + return array_intersect_key($phpFiles, $this->fileUtilities->getPhpFiles($fileTypes)); + } + + /** + * Provide list of new files. + * + * @param $changedFilesBaseDir + * + * @return string[] + */ + private static function getAddedFilesList($changedFilesBaseDir) + { + return self::getFilesFromListFile( + $changedFilesBaseDir, + 'changed_files*.added.*', + function () { + // if no list files, probably, this is the dev environment + // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction + @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); + return $addedFiles; + } + ); + } + + /** + * Read files from generated lists. + * + * @param string $listsBaseDir + * @param string $listFilePattern + * @param callable $noListCallback + * @return string[] + */ + private static function getFilesFromListFile( + string $listsBaseDir, + string $listFilePattern, + callable $noListCallback + ): array { + $filesDefinedInList = []; + + $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); + if (!empty($listFiles)) { + foreach ($listFiles as $listFile) { + // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge + $filesDefinedInList = array_merge( + $filesDefinedInList, + file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) + ); + } + } else { + $filesDefinedInList = call_user_func($noListCallback); + } + + array_walk( + $filesDefinedInList, + function (&$file) { + $file = BP . '/' . $file; + } + ); + + $filesDefinedInList = array_values(array_unique($filesDefinedInList)); + + return $filesDefinedInList; + } + + /** + * Returns base directory for generated lists. + * + * @return string + */ + private static function getChangedFilesBaseDir(): string + { + return BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'static' . + DIRECTORY_SEPARATOR . 'testsuite' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR . 'Test'; + } +} From 602dc6894a0ba909d3b631a28155ab58459aa12d Mon Sep 17 00:00:00 2001 From: Oleksandr Kravchuk <swnsma@gmail.com> Date: Fri, 31 Jul 2020 09:26:31 +0300 Subject: [PATCH 23/66] Update dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php Refactoring. Co-authored-by: Ihor Sviziev <ihor-sviziev@users.noreply.github.com> --- .../Test/Legacy/Magento/App/Action/AbstractActionTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php index 472b557ab389f..ced06dcc4ada6 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php @@ -125,12 +125,10 @@ private static function getFilesFromListFile( $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); if (!empty($listFiles)) { foreach ($listFiles as $listFile) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge - $filesDefinedInList = array_merge( - $filesDefinedInList, - file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) - ); + $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } + + $filesDefinedInList = array_merge([], ...$filesDefinedInList); } else { $filesDefinedInList = call_user_func($noListCallback); } From 9342d4c0e01664a8e155160118ab70f49aeb9225 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Fri, 31 Jul 2020 10:03:52 +0200 Subject: [PATCH 24/66] community-features#252 Create static test for action controllers. Fix static tests. --- .../Magento/App/Action/AbstractActionTest.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php index ced06dcc4ada6..d109b263b6b84 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Test\Legacy\App\Action; +namespace Magento\Test\Legacy\Magento\App\Action; use Exception; use Magento\Framework\App\Action\AbstractAction; @@ -41,9 +41,8 @@ protected function setUp(): void } /** - * Test new - * - */ + * Test newly created controllers do not extend deprecated AbstractAction. + */ public function testNewControllersDoNotExtendAbstractAction(): void { $files = $this->getTestFiles(); @@ -121,25 +120,21 @@ private static function getFilesFromListFile( callable $noListCallback ): array { $filesDefinedInList = []; - $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); if (!empty($listFiles)) { foreach ($listFiles as $listFile) { $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } - - $filesDefinedInList = array_merge([], ...$filesDefinedInList); + $filesDefinedInList = array_merge([], ...$filesDefinedInList); } else { $filesDefinedInList = call_user_func($noListCallback); } - array_walk( $filesDefinedInList, function (&$file) { $file = BP . '/' . $file; } ); - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); return $filesDefinedInList; From 8195b0c1ff66189ad50f7b25c5724f2bff36d365 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Fri, 31 Jul 2020 12:04:40 +0200 Subject: [PATCH 25/66] community-features#252 Create static test for action controllers. Fix static tests. --- .../Magento/{ => Framework}/App/Action/AbstractActionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename dev/tests/static/testsuite/Magento/Test/Legacy/Magento/{ => Framework}/App/Action/AbstractActionTest.php (98%) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php similarity index 98% rename from dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php rename to dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php index d109b263b6b84..d5427752004d9 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Test\Legacy\Magento\App\Action; +namespace Magento\Test\Legacy\Magento\Framework\App\Action; use Exception; use Magento\Framework\App\Action\AbstractAction; From 308a5f46cf4378efff331d5ac3035310c009c4fd Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Mon, 3 Aug 2020 21:44:10 +0200 Subject: [PATCH 26/66] community-features#252 Create static test for action controllers. Incapsulate logic in new class. Add test coverage. --- .../integration/etc/config-global.php.dist | 11 ---- .../Utility/ChildrenClassesSearch.php | 53 +++++++++++++++++++ .../Utility/ChildrenClassesSearchTest.php | 39 ++++++++++++++ .../Utility/PartialNamespace/Baz.php | 23 ++++++++ .../Utility/PartialNamespace/Foo.php | 34 ++++++++++++ .../App/Action/AbstractActionTest.php | 28 +++------- 6 files changed, 156 insertions(+), 32 deletions(-) delete mode 100644 dev/tests/integration/etc/config-global.php.dist create mode 100644 dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php diff --git a/dev/tests/integration/etc/config-global.php.dist b/dev/tests/integration/etc/config-global.php.dist deleted file mode 100644 index fbc6714859529..0000000000000 --- a/dev/tests/integration/etc/config-global.php.dist +++ /dev/null @@ -1,11 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -return [ - 'customer/password/limit_password_reset_requests_method' => 0, - 'admin/security/admin_account_sharing' => 1, - 'admin/security/limit_password_reset_requests_method' => 0, -]; diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php new file mode 100644 index 0000000000000..6905e1b4f442c --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +/** + * Search for children classes in list of files. + */ +class ChildrenClassesSearch +{ + /** + * @var ClassNameExtractor + */ + private $classNameExtractor; + + public function __construct() + { + $this->classNameExtractor = new ClassNameExtractor(); + } + + /** + * Get list of classes name which are subclasses of mentioned class. + * + * @param array $fileList + * @param string $parent + * @param bool $asDataSet + * + * @return array + * @throws \ReflectionException + */ + public function getClassesWhichAreChildrenOf(array $fileList, string $parent, bool $asDataSet = true): array + { + $found = []; + + foreach ($fileList as $file) { + $name = $asDataSet ? $file[0] : $file; + $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($name)); + + if ($class) { + $classReflection = new \ReflectionClass($class); + if ($classReflection->isSubclassOf($parent)) { + $found[] = $class; + } + } + } + + return $found; + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php new file mode 100644 index 0000000000000..9947414f7d364 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility; + +use Magento\Framework\App\Action\AbstractAction; + +class ChildrenClassesSearchTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var ChildrenClassesSearch + */ + private $childrenClassesSearch; + + protected function setUp(): void + { + $this->childrenClassesSearch = new ChildrenClassesSearch(); + } + + public function testChildrenSearch(): void + { + $files = [ + __DIR__ . '/PartialNamespace/Foo.php', + __DIR__ . '/PartialNamespace/Bar.php', + __DIR__ . '/PartialNamespace/Baz.php', + ]; + + $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf( + $files, + AbstractAction::class, + false + ); + + $this->assertCount(1, $found); + $this->assertEquals(current($found), \Magento\TestFramework\Utility\PartialNamespace\Foo::class); + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php new file mode 100644 index 0000000000000..1b54259b348ea --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\PartialNamespace; + +use Magento\Framework\App\ActionInterface; +use Magento\Framework\App\ResponseInterface; + +class Baz implements ActionInterface +{ + /** + * Execute action based on request and return result + * + * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface + * @throws \Magento\Framework\Exception\NotFoundException + */ + public function execute() + { + + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php new file mode 100644 index 0000000000000..6d062ff81bcce --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\PartialNamespace; + +use Magento\Framework\App\Action\AbstractAction; +use Magento\Framework\App\RequestInterface; +use Magento\Framework\App\ResponseInterface; + +class Foo extends AbstractAction +{ + /** + * Dispatch request + * + * @param RequestInterface $request + * + * @return ResponseInterface + */ + public function dispatch(RequestInterface $request) + { + } + + /** + * Execute action based on request and return result + * + * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface + * @throws \Magento\Framework\Exception\NotFoundException + */ + public function execute() + { + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php index d5427752004d9..7287adaae7f2f 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php @@ -7,14 +7,12 @@ namespace Magento\Test\Legacy\Magento\Framework\App\Action; -use Exception; use Magento\Framework\App\Action\AbstractAction; use Magento\Framework\App\ActionInterface; use Magento\Framework\App\Utility\Files; use Magento\Framework\Exception\LocalizedException; -use Magento\TestFramework\Utility\ClassNameExtractor; +use Magento\TestFramework\Utility\ChildrenClassesSearch; use PHPUnit\Framework\TestCase; -use ReflectionClass; /** * Test newly created controllers must do not extend AbstractAction. @@ -22,9 +20,9 @@ class AbstractActionTest extends TestCase { /** - * @var ClassNameExtractor + * @var ChildrenClassesSearch */ - private $classNameExtractor; + private $childrenClassesSearch; /** * @var Files @@ -36,32 +34,20 @@ class AbstractActionTest extends TestCase */ protected function setUp(): void { - $this->classNameExtractor = new ClassNameExtractor(); + $this->childrenClassesSearch = new ChildrenClassesSearch(); $this->fileUtilities = Files::init(); } /** * Test newly created controllers do not extend deprecated AbstractAction. + * + * @throws \ReflectionException */ public function testNewControllersDoNotExtendAbstractAction(): void { $files = $this->getTestFiles(); - $found = []; - - foreach ($files as $file) { - $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($file[0])); - if ($class) { - try { - $classReflection = new ReflectionClass($class); - if ($classReflection->isSubclassOf(AbstractAction::class)) { - $found[] = $class; - } - } catch (Exception $exception) { - $this->addWarning('Skipped due to exception: ' . $class); - } - } - } + $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf($files, AbstractAction::class); $this->assertEmpty( $found, From 125a5d4f02ac12e9323e9f9ce0af01b9da21a62c Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Tue, 4 Aug 2020 09:20:39 +0200 Subject: [PATCH 27/66] community-features#252 Create static test for action controllers. Recover accidentally removed file. --- dev/tests/integration/etc/config-global.php.dist | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dev/tests/integration/etc/config-global.php.dist diff --git a/dev/tests/integration/etc/config-global.php.dist b/dev/tests/integration/etc/config-global.php.dist new file mode 100644 index 0000000000000..fbc6714859529 --- /dev/null +++ b/dev/tests/integration/etc/config-global.php.dist @@ -0,0 +1,11 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +return [ + 'customer/password/limit_password_reset_requests_method' => 0, + 'admin/security/admin_account_sharing' => 1, + 'admin/security/limit_password_reset_requests_method' => 0, +]; From 87a70e92e3d60f087bf0fe6dd380f27ef300d351 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Tue, 4 Aug 2020 18:17:04 +0200 Subject: [PATCH 28/66] community-features#252 Create static test for action controllers. Apply code review changes. --- .../TestFramework/Utility/AddedFiles.php | 35 ++++++++++ .../TestFramework/Utility/FilesSearch.php | 48 +++++++++++++ .../Utility/ChildrenClassesSearch/A.php | 10 +++ .../Utility/ChildrenClassesSearch/B.php | 10 +++ .../Utility/ChildrenClassesSearch/C.php | 10 +++ .../Utility/ChildrenClassesSearch/D.php | 10 +++ .../Utility/ChildrenClassesSearch/E.php | 10 +++ .../Utility/ChildrenClassesSearch/F.php | 10 +++ .../Utility/ChildrenClassesSearch/Z.php | 10 +++ .../Utility/ChildrenClassesSearchTest.php | 31 ++++++--- .../TestFramework/Utility/FilesSearchTest.php | 54 +++++++++++++++ .../Utility/PartialNamespace/Baz.php | 23 ------- .../Utility/PartialNamespace/Foo.php | 34 ---------- .../_files/changed_files_some_name_test.txt | 3 + .../App/Action/AbstractActionTest.php | 60 +---------------- .../Magento/Test/Php/LiveCodeTest.php | 67 ++----------------- 16 files changed, 241 insertions(+), 184 deletions(-) create mode 100644 dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php create mode 100644 dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php delete mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php delete mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php new file mode 100644 index 0000000000000..6b1184418e16e --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +/** + * Helper class to add list of added new files. + */ +class AddedFiles +{ + /** + * Provide list of new files. + * + * @param $changedFilesBaseDir + * + * @return string[] + */ + public static function getAddedFilesList(string $changedFilesBaseDir): array + { + return FilesSearch::getFilesFromListFile( + $changedFilesBaseDir, + 'changed_files*.added.*', + function () { + // if no list files, probably, this is the dev environment + // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction + @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); + return $addedFiles; + } + ); + } +} diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php new file mode 100644 index 0000000000000..0ec8124496d1d --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +/** + * Helper class to search files by provided directory and file pattern. + */ +class FilesSearch +{ + /** + * Read files from generated lists. + * + * @param string $listsBaseDir + * @param string $listFilePattern + * @param callable $noListCallback + * @return string[] + */ + public static function getFilesFromListFile( + string $listsBaseDir, + string $listFilePattern, + callable $noListCallback + ): array { + $filesDefinedInList = []; + $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); + if (!empty($listFiles)) { + foreach ($listFiles as $listFile) { + $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + } + $filesDefinedInList = array_merge([], ...$filesDefinedInList); + } else { + $filesDefinedInList = call_user_func($noListCallback); + } + array_walk( + $filesDefinedInList, + function (&$file) { + $file = BP . '/' . $file; + } + ); + $filesDefinedInList = array_values(array_unique($filesDefinedInList)); + + return $filesDefinedInList; + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php new file mode 100644 index 0000000000000..3369df1edd54f --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class A +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php new file mode 100644 index 0000000000000..8873af3e4f9b7 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class B extends A +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php new file mode 100644 index 0000000000000..1fe77df4a7f15 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class C implements Z +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php new file mode 100644 index 0000000000000..8dc2cc0b9269e --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class D +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php new file mode 100644 index 0000000000000..563135ff36d3c --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class E extends B +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php new file mode 100644 index 0000000000000..5c7b8d8fb17af --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class F extends E implements Z +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php new file mode 100644 index 0000000000000..2ac48bda187b6 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +interface Z +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php index 9947414f7d364..efb073d93ed07 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php @@ -3,11 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\TestFramework\Utility; -use Magento\Framework\App\Action\AbstractAction; +use Magento\TestFramework\Utility\ChildrenClassesSearch\A; +use Magento\TestFramework\Utility\ChildrenClassesSearch\B; +use Magento\TestFramework\Utility\ChildrenClassesSearch\E; +use Magento\TestFramework\Utility\ChildrenClassesSearch\F; +use PHPUnit\Framework\TestCase; -class ChildrenClassesSearchTest extends \PHPUnit\Framework\TestCase +class ChildrenClassesSearchTest extends TestCase { /** * @var ChildrenClassesSearch @@ -22,18 +28,27 @@ protected function setUp(): void public function testChildrenSearch(): void { $files = [ - __DIR__ . '/PartialNamespace/Foo.php', - __DIR__ . '/PartialNamespace/Bar.php', - __DIR__ . '/PartialNamespace/Baz.php', + __DIR__ . '/ChildrenClassesSearch/A.php', + __DIR__ . '/ChildrenClassesSearch/B.php', + __DIR__ . '/ChildrenClassesSearch/C.php', + __DIR__ . '/ChildrenClassesSearch/D.php', + __DIR__ . '/ChildrenClassesSearch/E.php', + __DIR__ . '/ChildrenClassesSearch/F.php', + __DIR__ . '/ChildrenClassesSearch/Z.php', ]; $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf( $files, - AbstractAction::class, + A::class, false ); - $this->assertCount(1, $found); - $this->assertEquals(current($found), \Magento\TestFramework\Utility\PartialNamespace\Foo::class); + $expected = [ + B::class, + E::class, + F::class + ]; + + $this->assertSame($expected, $found); } } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php new file mode 100644 index 0000000000000..8c1206c56ce8e --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +use PHPUnit\Framework\TestCase; + +class FilesSearchTest extends TestCase +{ + /** + * Test files list extraction from file. + */ + public function testGetFiles(): void + { + $pattern = 'changed_files*.txt'; + + $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { + return []; + }); + + $expected = [ + BP . '/app/code/Magento/Cms/Block/Block.php', + BP . '/app/code/Magento/Cms/Api/BlockRepositoryInterface.php', + BP . '/app/code/Magento/Cms/Observer/NoCookiesObserver.php' + ]; + + $this->assertSame($files, $expected); + } + + /** + * Test callblack function in case when files with lists did not found. + */ + public function testGetEmptyList(): void + { + $pattern = 'zzz.txt'; + + + $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { + return ['1', '2', '3']; + }); + + $expected = [ + BP . '/1', + BP . '/2', + BP . '/3' + ]; + + $this->assertSame($files, $expected); + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php deleted file mode 100644 index 1b54259b348ea..0000000000000 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\TestFramework\Utility\PartialNamespace; - -use Magento\Framework\App\ActionInterface; -use Magento\Framework\App\ResponseInterface; - -class Baz implements ActionInterface -{ - /** - * Execute action based on request and return result - * - * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface - * @throws \Magento\Framework\Exception\NotFoundException - */ - public function execute() - { - - } -} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php deleted file mode 100644 index 6d062ff81bcce..0000000000000 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\TestFramework\Utility\PartialNamespace; - -use Magento\Framework\App\Action\AbstractAction; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\ResponseInterface; - -class Foo extends AbstractAction -{ - /** - * Dispatch request - * - * @param RequestInterface $request - * - * @return ResponseInterface - */ - public function dispatch(RequestInterface $request) - { - } - - /** - * Execute action based on request and return result - * - * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface - * @throws \Magento\Framework\Exception\NotFoundException - */ - public function execute() - { - } -} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt new file mode 100644 index 0000000000000..816f4b32c9361 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt @@ -0,0 +1,3 @@ +app/code/Magento/Cms/Block/Block.php +app/code/Magento/Cms/Api/BlockRepositoryInterface.php +app/code/Magento/Cms/Observer/NoCookiesObserver.php diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php index 7287adaae7f2f..69050c3c51895 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php @@ -11,6 +11,7 @@ use Magento\Framework\App\ActionInterface; use Magento\Framework\App\Utility\Files; use Magento\Framework\Exception\LocalizedException; +use Magento\TestFramework\Utility\AddedFiles; use Magento\TestFramework\Utility\ChildrenClassesSearch; use PHPUnit\Framework\TestCase; @@ -64,74 +65,19 @@ public function testNewControllersDoNotExtendAbstractAction(): void */ private function getTestFiles(): array { - $phpFiles = self::getAddedFilesList(self::getChangedFilesBaseDir()); + $phpFiles = AddedFiles::getAddedFilesList($this->getChangedFilesBaseDir()); $phpFiles = Files::composeDataSets($phpFiles); $fileTypes = Files::INCLUDE_APP_CODE | Files::INCLUDE_LIBS | Files::AS_DATA_SET; return array_intersect_key($phpFiles, $this->fileUtilities->getPhpFiles($fileTypes)); } - /** - * Provide list of new files. - * - * @param $changedFilesBaseDir - * - * @return string[] - */ - private static function getAddedFilesList($changedFilesBaseDir) - { - return self::getFilesFromListFile( - $changedFilesBaseDir, - 'changed_files*.added.*', - function () { - // if no list files, probably, this is the dev environment - // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction - @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); - return $addedFiles; - } - ); - } - - /** - * Read files from generated lists. - * - * @param string $listsBaseDir - * @param string $listFilePattern - * @param callable $noListCallback - * @return string[] - */ - private static function getFilesFromListFile( - string $listsBaseDir, - string $listFilePattern, - callable $noListCallback - ): array { - $filesDefinedInList = []; - $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); - if (!empty($listFiles)) { - foreach ($listFiles as $listFile) { - $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - } - $filesDefinedInList = array_merge([], ...$filesDefinedInList); - } else { - $filesDefinedInList = call_user_func($noListCallback); - } - array_walk( - $filesDefinedInList, - function (&$file) { - $file = BP . '/' . $file; - } - ); - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); - - return $filesDefinedInList; - } - /** * Returns base directory for generated lists. * * @return string */ - private static function getChangedFilesBaseDir(): string + private function getChangedFilesBaseDir(): string { return BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'testsuite' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR . 'Test'; diff --git a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php index 324753b4bd4ec..ad91025448579 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php @@ -14,6 +14,8 @@ use Magento\TestFramework\CodingStandard\Tool\CopyPasteDetector; use Magento\TestFramework\CodingStandard\Tool\PhpCompatibility; use Magento\TestFramework\CodingStandard\Tool\PhpStan; +use Magento\TestFramework\Utility\AddedFiles; +use Magento\TestFramework\Utility\FilesSearch; use PHPMD\TextUI\Command; /** @@ -113,8 +115,8 @@ public static function getWhitelist( */ private static function getChangedFilesList($changedFilesBaseDir) { - return self::getFilesFromListFile( - $changedFilesBaseDir, + return FilesSearch::getFilesFromListFile( + $changedFilesBaseDir ?: self::getChangedFilesBaseDir(), 'changed_files*', function () { // if no list files, probably, this is the dev environment @@ -128,65 +130,6 @@ function () { ); } - /** - * This method loads list of added files. - * - * @param string $changedFilesBaseDir - * @return string[] - */ - private static function getAddedFilesList($changedFilesBaseDir) - { - return self::getFilesFromListFile( - $changedFilesBaseDir, - 'changed_files*.added.*', - function () { - // if no list files, probably, this is the dev environment - // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction - @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); - return $addedFiles; - } - ); - } - - /** - * Read files from generated lists. - * - * @param string $listsBaseDir - * @param string $listFilePattern - * @param callable $noListCallback - * @return string[] - */ - private static function getFilesFromListFile($listsBaseDir, $listFilePattern, $noListCallback) - { - $filesDefinedInList = []; - - $globFilesListPattern = ($listsBaseDir ?: self::getChangedFilesBaseDir()) - . '/_files/' . $listFilePattern; - $listFiles = glob($globFilesListPattern); - if (!empty($listFiles)) { - foreach ($listFiles as $listFile) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge - $filesDefinedInList = array_merge( - $filesDefinedInList, - file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) - ); - } - } else { - $filesDefinedInList = call_user_func($noListCallback); - } - - array_walk( - $filesDefinedInList, - function (&$file) { - $file = BP . '/' . $file; - } - ); - - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); - - return $filesDefinedInList; - } - /** * Filter list of files. * @@ -427,7 +370,7 @@ public function testCopyPaste() */ public function testStrictTypes() { - $changedFiles = self::getAddedFilesList(''); + $changedFiles = AddedFiles::getAddedFilesList(self::getChangedFilesBaseDir()); try { $blackList = Files::init()->readLists( From 0b92de976b8c57c241672608886f87e681bcd0bd Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Tue, 4 Aug 2020 22:06:46 +0200 Subject: [PATCH 29/66] community-features#252 Create static test for action controllers. Fix static tests. --- .../framework/Magento/TestFramework/Utility/AddedFiles.php | 2 +- .../Magento/TestFramework/Utility/ChildrenClassesSearch.php | 3 +++ .../Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php | 2 ++ .../Magento/TestFramework/Utility/FilesSearchTest.php | 1 - 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php index 6b1184418e16e..4afeda3a035eb 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php @@ -15,7 +15,7 @@ class AddedFiles /** * Provide list of new files. * - * @param $changedFilesBaseDir + * @param string $changedFilesBaseDir * * @return string[] */ diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php index 6905e1b4f442c..53db8ca8d0b08 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php @@ -17,6 +17,9 @@ class ChildrenClassesSearch */ private $classNameExtractor; + /** + * ChildrenClassesSearch constructor. + */ public function __construct() { $this->classNameExtractor = new ClassNameExtractor(); diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php index 2ac48bda187b6..1ec713366dde8 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php @@ -5,6 +5,8 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; +// @codingStandardsIgnoreStar interface Z { } +// @codingStandardsIgnoreEnd diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php index 8c1206c56ce8e..7b27dde3b0bf4 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php @@ -38,7 +38,6 @@ public function testGetEmptyList(): void { $pattern = 'zzz.txt'; - $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { return ['1', '2', '3']; }); From a493bc5769b59b4f2635a09382b379e44dec950a Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk <oleksandr.kravchuk@vaimo.com> Date: Wed, 5 Aug 2020 14:41:32 +0300 Subject: [PATCH 30/66] community-features#252 Create static test for action controllers.. Fix static tests. --- .../Magento/TestFramework/Utility/ChildrenClassesSearch/C.php | 2 +- .../Magento/TestFramework/Utility/ChildrenClassesSearch/F.php | 2 +- .../Utility/ChildrenClassesSearch/{Z.php => ZInterface.php} | 4 +--- .../TestFramework/Utility/ChildrenClassesSearchTest.php | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) rename dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/{Z.php => ZInterface.php} (70%) diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php index 1fe77df4a7f15..e50735fcbb46c 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php @@ -5,6 +5,6 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; -class C implements Z +class C implements ZInterface { } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php index 5c7b8d8fb17af..6976ed26a0d84 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php @@ -5,6 +5,6 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; -class F extends E implements Z +class F extends E implements ZInterface { } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php similarity index 70% rename from dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php rename to dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php index 1ec713366dde8..be1b6d222519c 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php @@ -5,8 +5,6 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; -// @codingStandardsIgnoreStar -interface Z +interface ZInterface { } -// @codingStandardsIgnoreEnd diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php index efb073d93ed07..5b7fd47042347 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php @@ -34,7 +34,7 @@ public function testChildrenSearch(): void __DIR__ . '/ChildrenClassesSearch/D.php', __DIR__ . '/ChildrenClassesSearch/E.php', __DIR__ . '/ChildrenClassesSearch/F.php', - __DIR__ . '/ChildrenClassesSearch/Z.php', + __DIR__ . '/ChildrenClassesSearch/ZInterface.php', ]; $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf( From 8e011b65f9b969a70bb2d75428f81117ebf36247 Mon Sep 17 00:00:00 2001 From: Oleh Usik <o.usik@atwix.com> Date: Mon, 10 Aug 2020 20:16:47 +0300 Subject: [PATCH 31/66] created new action group for click button --- ...stCheckoutUsingFreeShippingAndTaxesTest.xml | 3 +-- .../AdminClickButtonAddTaxRuleActionGroup.xml | 18 ++++++++++++++++++ .../Test/AdminCreateDefaultsTaxRuleTest.xml | 3 +-- .../Test/AdminCreateTaxRateLargeRateTest.xml | 2 +- .../AdminCreateTaxRateSpecificPostcodeTest.xml | 2 +- ...AdminCreateTaxRateWiderZipCodeRangeTest.xml | 2 +- .../AdminCreateTaxRateZipCodeRangeTest.xml | 2 +- ...xRuleWithCustomerAndProductTaxClassTest.xml | 3 +-- ...axRateAndCustomerAndProductTaxClassTest.xml | 3 +-- ...eTaxRuleWithNewTaxClassesAndTaxRateTest.xml | 3 +-- .../AdminCreateTaxRuleWithZipRangeTest.xml | 3 +-- .../Test/Mftf/Test/DeleteTaxRateEntityTest.xml | 3 +-- 12 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml index 1ce48bd8bf408..7ace592b7ae73 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml @@ -120,8 +120,7 @@ <!-- Create a Tax Rule --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with defaults --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml b/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml new file mode 100644 index 0000000000000..313c4c5e84af0 --- /dev/null +++ b/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminClickButtonAddTaxRuleActionGroup"> + <annotations> + <description>Click button for creating new tax rule.</description> + </annotations> + <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> + <waitForPageLoad stepKey="waitForTaxRuleGridLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml index 07968c281c68b..9629740f1cd20 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml @@ -30,8 +30,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with defaults --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> <fillField selector="{{AdminTaxRuleFormSection.taxRateSearch}}" userInput="$$initialTaxRate.code$$" stepKey="fillTaxRateSearch"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml index c8e4defc40c9f..641278d02e726 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml @@ -59,7 +59,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml index c6a5a6c69e788..f454ceced7a3d 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml @@ -58,7 +58,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml index ef9b66041893d..9712a605a5bf4 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml @@ -60,7 +60,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml index 23c4ffd78a88d..2734a57aa312c 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml @@ -62,7 +62,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml index ba0834da7c0e7..c309db52cb194 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml @@ -40,8 +40,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with customer and product class --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml index ae37bc8a8930a..2aaebb0ca5c3e 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml @@ -41,8 +41,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with new and existing tax rate, customer tax class, product tax class --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml index 2a008991c2dc8..d0e9242f3618b 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml @@ -41,8 +41,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with new tax classes and tax rate --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml index de55453fcabc4..0c324f137b84f 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml @@ -41,8 +41,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with new tax classes and tax rate --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml index 881e09e5e35f4..99d9d12d7d182 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml @@ -44,8 +44,7 @@ <!-- Confirm Deleted TaxIdentifier on the tax rule grid page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex3"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex1"/> + <actionGroup ref="AdminClickButtonAddTaxRuleActionGroup" stepKey="clickAddNewTaxRuleButton"/> <fillField selector="{{AdminTaxRuleFormSection.taxRateSearch}}" userInput="$$initialTaxRate.code$$" stepKey="fillTaxRateSearch"/> <wait stepKey="waitForSearch" time="5" /> <dontSee selector="{{AdminTaxRuleFormSection.fieldTaxRate}}" userInput="$$initialTaxRate.code$$" stepKey="dontSeeInTaxRuleForm"/> From 83b40124d87c7904d062577f21566eabdec15f8a Mon Sep 17 00:00:00 2001 From: Oleh Usik <o.usik@atwix.com> Date: Mon, 10 Aug 2020 20:59:46 +0300 Subject: [PATCH 32/66] Add action group for click edit link --- ...stomerClickFirstRowEditLinkActionGroup.xml | 19 +++++++++++++++++++ ...eateCustomerRetailerWithoutAddressTest.xml | 3 +-- ...minCreateCustomerWithCountryPolandTest.xml | 6 ++---- .../AdminCreateCustomerWithCountryUSATest.xml | 6 ++---- ...AdminCreateCustomerWithCustomGroupTest.xml | 3 +-- .../AdminCreateCustomerWithPrefixTest.xml | 3 +-- .../AdminCreateCustomerWithoutAddressTest.xml | 3 +-- ...stomerOnStorefrontSignupNewsletterTest.xml | 3 +-- .../Mftf/Test/AdminCreateNewCustomerTest.xml | 3 +-- ...tomerSubscribeNewsletterPerWebsiteTest.xml | 3 +-- ...ableProductToOrderFromShoppingCartTest.xml | 3 +-- ...mpleProductToOrderFromShoppingCartTest.xml | 3 +-- ...eredConfigurableProductOnOrderPageTest.xml | 3 +-- ...astOrderedSimpleProductOnOrderPageTest.xml | 3 +-- ...iewedBundleFixedProductOnOrderPageTest.xml | 3 +-- ...ewedConfigurableProductOnOrderPageTest.xml | 3 +-- .../AdminSetUpWatermarkForSwatchImageTest.xml | 3 +-- 17 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminCustomerClickFirstRowEditLinkActionGroup.xml diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminCustomerClickFirstRowEditLinkActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminCustomerClickFirstRowEditLinkActionGroup.xml new file mode 100644 index 0000000000000..1c5c29b855bf5 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminCustomerClickFirstRowEditLinkActionGroup.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminCustomerClickFirstRowEditLinkActionGroup"> + <annotations> + <description>Click edit link for first row on the grid.</description> + </annotations> + + <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditLink"/> + <waitForPageLoad stepKey="waitForPageLoading"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerRetailerWithoutAddressTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerRetailerWithoutAddressTest.xml index c8e3bc10cc769..98b488c63a1e0 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerRetailerWithoutAddressTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerRetailerWithoutAddressTest.xml @@ -50,8 +50,7 @@ <see userInput="{{CustomerEntityOne.email}}" selector="{{AdminCustomerGridSection.customerGrid}}" stepKey="assertEmail"/> <!--Assert Customer Form --> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad1"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> <waitForPageLoad stepKey="waitForCustomerInformationPageToLoad"/> <see selector="{{AdminCustomerAccountInformationSection.groupIdValue}}" userInput="Retailer" stepKey="seeCustomerGroup1"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryPolandTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryPolandTest.xml index 5f496e2c5fba3..7d76b79b97279 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryPolandTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryPolandTest.xml @@ -31,8 +31,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterTheCustomerByEmail"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton"/> <!-- Add the Address --> <click selector="{{AdminEditCustomerAddressesSection.addresses}}" stepKey="selectAddress"/> @@ -67,8 +66,7 @@ <see userInput="{{PolandAddress.telephone}}" selector="{{AdminCustomerGridSection.customerGrid}}" stepKey="assertPhoneNumber"/> <!--Assert Customer Form --> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad1"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> <waitForPageLoad stepKey="waitForCustomerInformationPageToLoad"/> <seeInField selector="{{AdminCustomerAccountInformationSection.firstName}}" userInput="$$createCustomer.firstname$$" stepKey="seeCustomerFirstName"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryUSATest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryUSATest.xml index da2eed2006434..7eecdf67d58b1 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryUSATest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCountryUSATest.xml @@ -31,8 +31,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterTheCustomerByEmail"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton"/> <!-- Add the Address --> <click selector="{{AdminEditCustomerAddressesSection.addresses}}" stepKey="selectAddress"/> @@ -67,8 +66,7 @@ <see userInput="{{US_Address_CA.telephone}}" selector="{{AdminCustomerGridSection.customerGrid}}" stepKey="assertPhoneNumber"/> <!--Assert Customer Form --> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad1"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> <waitForPageLoad stepKey="waitForCustomerInformationPageToLoad"/> <seeInField selector="{{AdminCustomerAccountInformationSection.firstName}}" userInput="$$createCustomer.firstname$$" stepKey="seeCustomerFirstName"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCustomGroupTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCustomGroupTest.xml index 8afd1648d26e0..84d6d5df5f8f3 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCustomGroupTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithCustomGroupTest.xml @@ -54,8 +54,7 @@ <see userInput="{{CustomerEntityOne.email}}" selector="{{AdminCustomerGridSection.customerGrid}}" stepKey="assertEmail"/> <!--Assert Customer Form --> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad1"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> <waitForPageLoad stepKey="waitForCustomerInformationPageToLoad"/> <see selector="{{AdminCustomerAccountInformationSection.groupIdValue}}" userInput="$$customerGroup.code$$" stepKey="seeCustomerGroup1"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithPrefixTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithPrefixTest.xml index e9250be637534..a03855b9e90c9 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithPrefixTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithPrefixTest.xml @@ -56,8 +56,7 @@ <see userInput="Male" selector="{{AdminCustomerGridSection.customerGrid}}" stepKey="assertGender"/> <!--Assert Customer Form --> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad1"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> <waitForPageLoad stepKey="waitForCustomerInformationPageToLoad"/> <seeInField selector="{{AdminCustomerAccountInformationSection.namePrefix}}" userInput="{{CustomerEntityOne.prefix}}" stepKey="seeCustomerNamePrefix"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithoutAddressTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithoutAddressTest.xml index 5033f2882af42..c707c322529b9 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithoutAddressTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateCustomerWithoutAddressTest.xml @@ -49,8 +49,7 @@ <see userInput="{{CustomerEntityOne.email}}" selector="{{AdminCustomerGridSection.customerGrid}}" stepKey="assertEmail"/> <!--Assert Customer Form --> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad1"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> <waitForPageLoad stepKey="waitForCustomerInformationPageToLoad"/> <seeInField selector="{{AdminCustomerAccountInformationSection.firstName}}" userInput="{{CustomerEntityOne.firstname}}" stepKey="seeCustomerFirstName"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerOnStorefrontSignupNewsletterTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerOnStorefrontSignupNewsletterTest.xml index 5440339e3a95e..67546a88425b3 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerOnStorefrontSignupNewsletterTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerOnStorefrontSignupNewsletterTest.xml @@ -45,8 +45,7 @@ <see selector="{{AdminCustomerGridSection.customerGrid}}" userInput="{{CustomerEntityOne.email}}" stepKey="seeAssertCustomerEmailInGrid"/> <!--Assert verify created new customer is subscribed to newsletter--> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickFirstRowEditLink"/> - <waitForPageLoad stepKey="waitForEditLinkLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickFirstRowEditLink"/> <click selector="{{AdminEditCustomerInformationSection.newsLetter}}" stepKey="clickNewsLetter"/> <waitForPageLoad stepKey="waitForNewsletterTabToOpen"/> <seeCheckboxIsChecked selector="{{AdminEditCustomerNewsletterSection.subscribedStatus('1')}}" stepKey="seeAssertSubscribedToNewsletterCheckboxIsChecked"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerTest.xml index 6b484e857d276..9583e5d6109c5 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCreateNewCustomerTest.xml @@ -42,8 +42,7 @@ <argument name="email" value="{{CustomerEntityOne.email}}"/> </actionGroup> <waitForPageLoad stepKey="waitForPageToLoad"/> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickOnEditButton1"/> - <waitForPageLoad stepKey="waitForCustomerEditPageToLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickOnEditButton1"/> <!-- Assert Customer Title --> <click selector="{{AdminCustomerAccountInformationSection.accountInformationButton}}" stepKey="clickOnAccountInformation"/> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCustomerSubscribeNewsletterPerWebsiteTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCustomerSubscribeNewsletterPerWebsiteTest.xml index a8391458a1a50..ffcc543609e37 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/AdminCustomerSubscribeNewsletterPerWebsiteTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCustomerSubscribeNewsletterPerWebsiteTest.xml @@ -53,8 +53,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCustomerGrid"> <argument name="email" value="{{CustomerEntityOne.email}}"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickToEditCustomerPage"/> - <waitForPageLoad stepKey="waitForOpenCustomerPage"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickToEditCustomerPage"/> <grabFromCurrentUrl regex="~(\d+)/~" stepKey="grabCustomerId"/> <!-- Assert that created customer is subscribed to newsletter on the new Store View --> <actionGroup ref="AdminAssertCustomerIsSubscribedToNewslettersAndSelectedStoreView" stepKey="assertSubscribedToNewsletter"> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AddConfigurableProductToOrderFromShoppingCartTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AddConfigurableProductToOrderFromShoppingCartTest.xml index 6f4073bf70f46..45bd7ee3e0deb 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AddConfigurableProductToOrderFromShoppingCartTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AddConfigurableProductToOrderFromShoppingCartTest.xml @@ -97,8 +97,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCreatedCustomer"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickEditButton"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickEditButton"/> <!-- Click create order --> <click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickCreateOrder"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AddSimpleProductToOrderFromShoppingCartTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AddSimpleProductToOrderFromShoppingCartTest.xml index d8a9effa56dac..60c33d68354ce 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AddSimpleProductToOrderFromShoppingCartTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AddSimpleProductToOrderFromShoppingCartTest.xml @@ -58,8 +58,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCreatedCustomer"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickEditButton"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickEditButton"/> <!-- Click create order --> <click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickCreateOrder"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedConfigurableProductOnOrderPageTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedConfigurableProductOnOrderPageTest.xml index c635e6b0ad6b2..3d5b54daa7c8f 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedConfigurableProductOnOrderPageTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedConfigurableProductOnOrderPageTest.xml @@ -96,8 +96,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCreatedCustomer"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickEditButton"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickEditButton"/> <!-- Click create order --> <click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickCreateOrder"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedSimpleProductOnOrderPageTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedSimpleProductOnOrderPageTest.xml index eb28ebfd068da..8faedb24e600e 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedSimpleProductOnOrderPageTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/MoveLastOrderedSimpleProductOnOrderPageTest.xml @@ -46,8 +46,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCreatedCustomer"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickEditButton"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickEditButton"/> <!-- Click create order --> <click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickCreateOrder"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedBundleFixedProductOnOrderPageTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedBundleFixedProductOnOrderPageTest.xml index c3fc7a4952143..980bc272c3643 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedBundleFixedProductOnOrderPageTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedBundleFixedProductOnOrderPageTest.xml @@ -96,8 +96,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCreatedCustomer"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickEditButton"/> - <waitForPageLoad stepKey="waitForCustomerPageLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickEditButton"/> <!-- Click create order --> <click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickCreateOrder"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedConfigurableProductOnOrderPageTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedConfigurableProductOnOrderPageTest.xml index 0e021600ab3e3..0bff169c4a68e 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedConfigurableProductOnOrderPageTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/MoveRecentlyViewedConfigurableProductOnOrderPageTest.xml @@ -99,8 +99,7 @@ <actionGroup ref="AdminFilterCustomerByEmail" stepKey="filterCreatedCustomer"> <argument name="email" value="$$createCustomer.email$$"/> </actionGroup> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickEditButton"/> - <waitForPageLoad stepKey="waitForCustomerPageLoad"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickEditButton"/> <!-- Click create order --> <click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickCreateOrder"/> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminSetUpWatermarkForSwatchImageTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminSetUpWatermarkForSwatchImageTest.xml index d56572afd8847..d615c1478d6d7 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/AdminSetUpWatermarkForSwatchImageTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminSetUpWatermarkForSwatchImageTest.xml @@ -38,8 +38,7 @@ </actionGroup> <!-- Select Edit next to the Default Store View --> <comment userInput="Select Edit next to the Default Store View" stepKey="commentEditDefaultView"/> - <click selector="{{AdminCustomerGridSection.firstRowEditLink}}" stepKey="clickToEditDefaultStoreView"/> - <waitForPageLoad stepKey="waitForDefaultStorePage"/> + <actionGroup ref="AdminCustomerClickFirstRowEditLinkActionGroup" stepKey="clickToEditDefaultStoreView"/> <!-- Expand the Product Image Watermarks section--> <comment userInput="Expand the Product Image Watermarks section" stepKey="commentOpenWatermarksSection"/> <click selector="{{AdminDesignConfigSection.watermarkSectionHeader}}" stepKey="clickToProductImageWatermarks"/> From 1b39196a80c9c4a3d229c121b647b82ae242193d Mon Sep 17 00:00:00 2001 From: "vadim.malesh" <engcom-vendorworker-charlie@adobe.com> Date: Tue, 11 Aug 2020 15:53:48 +0300 Subject: [PATCH 33/66] fix store website name rewrites --- .../Listing/Column/Store/Options.php | 33 ++--- .../Listing/Column/Store/OptionsTest.php | 114 ++++++++++++++++++ 2 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php diff --git a/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php b/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php index 907eb74e20fa2..f8aa09cb20a61 100644 --- a/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php +++ b/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php @@ -10,7 +10,7 @@ use Magento\Store\Model\System\Store as SystemStore; /** - * Class Options + * Ui stores options */ class Options implements OptionSourceInterface { @@ -93,37 +93,38 @@ protected function sanitizeName($name) * * @return void */ - protected function generateCurrentOptions() + protected function generateCurrentOptions(): void { $websiteCollection = $this->systemStore->getWebsiteCollection(); $groupCollection = $this->systemStore->getGroupCollection(); $storeCollection = $this->systemStore->getStoreCollection(); - /** @var \Magento\Store\Model\Website $website */ + foreach ($websiteCollection as $website) { $groups = []; - /** @var \Magento\Store\Model\Group $group */ foreach ($groupCollection as $group) { - if ($group->getWebsiteId() == $website->getId()) { + if ($group->getWebsiteId() === $website->getId()) { $stores = []; - /** @var \Magento\Store\Model\Store $store */ foreach ($storeCollection as $store) { - if ($store->getGroupId() == $group->getId()) { - $name = $this->sanitizeName($store->getName()); - $stores[$name]['label'] = str_repeat(' ', 8) . $name; - $stores[$name]['value'] = $store->getId(); + if ($store->getGroupId() === $group->getId()) { + $stores[] = [ + 'label' => str_repeat(' ', 8) . $this->sanitizeName($store->getName()), + 'value' => $store->getId(), + ]; } } if (!empty($stores)) { - $name = $this->sanitizeName($group->getName()); - $groups[$name]['label'] = str_repeat(' ', 4) . $name; - $groups[$name]['value'] = array_values($stores); + $groups[] = [ + 'label' => str_repeat(' ', 4) . $this->sanitizeName($group->getName()), + 'value' => array_values($stores), + ]; } } } if (!empty($groups)) { - $name = $this->sanitizeName($website->getName()); - $this->currentOptions[$name]['label'] = $name; - $this->currentOptions[$name]['value'] = array_values($groups); + $this->currentOptions[] = [ + 'label' => $this->sanitizeName($website->getName()), + 'value' => array_values($groups), + ]; } } } diff --git a/dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php b/dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php new file mode 100644 index 0000000000000..e13c4a427464f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php @@ -0,0 +1,114 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Store\Ui\Component\Listing\Column\Store; + +use Magento\Store\Model\ResourceModel\Group as GroupResource; +use Magento\Store\Model\ResourceModel\Store as StoreResource; +use Magento\Store\Model\ResourceModel\Website as WebsiteResource; +use Magento\Store\Model\StoreManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; + +/** + * Test for \Magento\Store\Ui\Component\Listing\Column\Store\Options. + */ +class OptionsTest extends TestCase +{ + private const DEFAULT_WEBSITE_NAME = 'Main Website'; + private const DEFAULT_STORE_GROUP_NAME = 'Main Website Store'; + private const DEFAULT_STORE_NAME = 'Default Store View'; + + /** + * @var OptionsFactory + */ + private $modelFactory; + + /** + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * @var WebsiteResource + */ + private $websiteResource; + + /** + * @var StoreResource + */ + private $storeResource; + + /** + * @var GroupResource + */ + private $groupResource; + + /** + * @return void + */ + protected function setUp(): void + { + $objectManager = Bootstrap::getObjectManager(); + + $this->modelFactory = $objectManager->get(OptionsFactory::class); + $this->storeManager = $objectManager->get(StoreManagerInterface::class); + + $this->websiteResource = $objectManager->get(WebsiteResource::class); + $this->groupResource = $objectManager->get(GroupResource::class); + $this->storeResource = $objectManager->get(StoreResource::class); + } + + /** + * To option array test with duplicate website, store group, store view names + * + * @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php + * + * @return void + */ + public function testToOptionArray(): void + { + $website = $this->storeManager->getWebsite('test'); + $this->websiteResource->save($website->setName(self::DEFAULT_WEBSITE_NAME)); + + $storeGroup = current($website->getGroups()); + $this->groupResource->save($storeGroup->setName(self::DEFAULT_STORE_GROUP_NAME)); + + $store = current($website->getStores()); + $this->storeResource->save($store->setName(self::DEFAULT_STORE_NAME)); + + $model = $this->modelFactory->create(); + $storeIds = [$this->storeManager->getStore('default')->getId(), $store->getId()]; + + $this->assertEquals($this->getExpectedOptions($storeIds), $model->toOptionArray()); + } + + /** + * Returns expected options + * + * @param array $storeIds + * @return array + */ + private function getExpectedOptions(array $storeIds): array + { + $expectedOptions = []; + foreach ($storeIds as $storeId) { + $expectedOptions[] = [ + 'label' => self::DEFAULT_WEBSITE_NAME, + 'value' => [[ + 'label' => str_repeat(' ', 4) . self::DEFAULT_STORE_GROUP_NAME, + 'value' => [[ + 'label' => str_repeat(' ', 8) . self::DEFAULT_STORE_NAME, + 'value' => $storeId, + ]], + ]], + ]; + } + + return $expectedOptions; + } +} From c5f6a1f4a70e979f2fc31a8c4d714c713bd9e650 Mon Sep 17 00:00:00 2001 From: "vadim.malesh" <engcom-vendorworker-charlie@adobe.com> Date: Wed, 12 Aug 2020 12:41:19 +0300 Subject: [PATCH 34/66] fix http action --- app/code/Magento/Wishlist/Controller/Shared/Allcart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php index c1e908cc0f49e..1c504a7a8a80d 100644 --- a/app/code/Magento/Wishlist/Controller/Shared/Allcart.php +++ b/app/code/Magento/Wishlist/Controller/Shared/Allcart.php @@ -10,7 +10,7 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; -use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\Result\Forward; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; @@ -19,7 +19,7 @@ /** * Wishlist Allcart Controller */ -class Allcart extends Action implements HttpGetActionInterface +class Allcart extends Action implements HttpPostActionInterface { /** * @var WishlistProvider From 4d65656fafe9c132bc8cd441ac2d1f7571b5a0da Mon Sep 17 00:00:00 2001 From: Vasya Tsviklinskyi <tsviklinskyi@gmail.com> Date: Wed, 12 Aug 2020 14:07:58 +0300 Subject: [PATCH 35/66] MC-35699: [Magento Cloud] HTML minification strips triple slashes from html string in phtml --- .../Magento/Framework/View/Template/Html/Minifier.php | 3 ++- .../Framework/View/Test/Unit/Template/Html/MinifierTest.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php index 0a8db80cae349..cdbce9d102a89 100644 --- a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php +++ b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Framework\View\Template\Html; @@ -140,7 +141,7 @@ function ($match) use (&$heredocs) { . '(?:<(?>textarea|pre|script)\b|\z))#', ' ', preg_replace( - '#(?<!:|\\\\|\'|")//(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#', + '#(?<!:|\\\\|\'|"|/)//(?!/)(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#', '', preg_replace( '#(?<!:|\'|")//[^\n\r]*(\?\>)#', diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php index 6aafa5a46cf63..3b13a2f723617 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\View\Test\Unit\Template\Html; use PHPUnit\Framework\TestCase; @@ -139,6 +141,7 @@ public function testMinify() <img src="test.png" alt="some text" /> <?php echo \$block->someMethod(); ?> <div style="width: 800px" class="<?php echo \$block->getClass() ?>" /> + <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-component="main-image"> <script> var i = 1;// comment var j = 1;// <?php echo 'hi' ?> @@ -179,7 +182,7 @@ public function testMinify() TEXT; $expectedContent = <<<TEXT -<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ?> <?php ?> <html><head><title>Test titleText Link some textsomeMethod(); ?>