From 49ff38a9c319c9602781b89345a209f3a86e033c Mon Sep 17 00:00:00 2001 From: Ward Cappelle Date: Sun, 21 Apr 2019 09:45:58 +0200 Subject: [PATCH 01/27] Add support for char element to dto factory To avoid the notice "Types char is not declared" (which breaks setup:upgrade) when using the very type anywhere in the MySQL database, mapping for this specific type is added to the DI as well. --- app/etc/di.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/etc/di.xml b/app/etc/di.xml index 476285878650b..4760550ba10e7 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1435,6 +1435,7 @@ \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\MediumText \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Text \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary + \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Blob \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\MediumBlob From 6950ead57dc9b17f8604401421fbf1339c81592d Mon Sep 17 00:00:00 2001 From: Dmitriy Danichenko Date: Fri, 27 Sep 2019 12:19:07 +0300 Subject: [PATCH 02/27] fix issue 24735 --- .../frontend/web/template/product/image_with_borders.html | 4 ++-- app/design/frontend/Magento/luma/etc/view.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/view/frontend/web/template/product/image_with_borders.html b/app/code/Magento/Catalog/view/frontend/web/template/product/image_with_borders.html index d59237c190f71..48c5feb190990 100644 --- a/app/code/Magento/Catalog/view/frontend/web/template/product/image_with_borders.html +++ b/app/code/Magento/Catalog/view/frontend/web/template/product/image_with_borders.html @@ -4,8 +4,8 @@ * See COPYING.txt for license details. */ --> - + - + diff --git a/app/design/frontend/Magento/luma/etc/view.xml b/app/design/frontend/Magento/luma/etc/view.xml index a2802b7e374f3..e8b8bc66d2e44 100644 --- a/app/design/frontend/Magento/luma/etc/view.xml +++ b/app/design/frontend/Magento/luma/etc/view.xml @@ -53,8 +53,8 @@ 100 - 75 - 75 + 150 + 150 240 From c7deb42a3b9b1875d4afe95ffea3c0f11cd1cb5d Mon Sep 17 00:00:00 2001 From: Dmitriy Danichenko Date: Wed, 2 Oct 2019 09:08:51 +0300 Subject: [PATCH 03/27] fix minicart image for Blank theme --- app/design/frontend/Magento/blank/etc/view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/design/frontend/Magento/blank/etc/view.xml b/app/design/frontend/Magento/blank/etc/view.xml index 5884699af15cd..aebdf8dce4a27 100644 --- a/app/design/frontend/Magento/blank/etc/view.xml +++ b/app/design/frontend/Magento/blank/etc/view.xml @@ -49,8 +49,8 @@ 100 - 78 - 78 + 156 + 156 240 From 3a5cc24f5e1537b4da4abb63ecbdd01c7c29865e Mon Sep 17 00:00:00 2001 From: Tejash Kumbhare Date: Sun, 2 Feb 2020 13:57:51 +0530 Subject: [PATCH 04/27] table bottom color different then thead and tbody border color --- .../Magento/luma/Magento_Customer/web/css/source/_module.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less b/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less index 6354cc35d32ed..34a2dbfeca472 100644 --- a/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less +++ b/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less @@ -8,7 +8,7 @@ // _____________________________________________ @account-title-border-color: @color-gray-middle2; -@account-table-border-bottom-color: @color-gray-middle1; +@account-table-border-bottom-color: @color-gray_light; @account-table-action-delete: @color-red12; @_password-default: @color-gray-light01; From 99a9405b24083c88d00bb35a2be2248d3d1d3f07 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Sun, 6 Oct 2019 11:22:55 +0200 Subject: [PATCH 05/27] Create missing directories in imageuploader tree if they don't already exist. --- .../Magento/Cms/Helper/Wysiwyg/Images.php | 37 ++++++++++++----- .../Test/Unit/Helper/Wysiwyg/ImagesTest.php | 41 ++++++++++++------- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php index cd3473c6bab87..c634910f4468f 100644 --- a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php @@ -224,8 +224,7 @@ public function getImageHtmlDeclaration($filename, $renderAsTag = false) } /** - * Return path of the current selected directory or root directory for startup - * Try to create target directory if it doesn't exist + * Return path of the root directory for startup. Also try to create target directory if it doesn't exist * * @return string * @throws \Magento\Framework\Exception\LocalizedException @@ -241,18 +240,34 @@ public function getCurrentPath() $currentPath = $path; } } + + $currentTreePath = $this->_getRequest()->getParam('current_tree_path'); + if ($currentTreePath) { + $currentTreePath = $this->convertIdToPath($currentTreePath); + $this->createSubDirIfNotExist($currentTreePath); + } + + $this->_currentPath = $currentPath; + } + + return $this->_currentPath; + } + + private function createSubDirIfNotExist(string $absPath) + { + $relPath = $this->_directory->getRelativePath($absPath); + if (!$this->_directory->isExist($relPath)) { try { - $currentDir = $this->_directory->getRelativePath($currentPath); - if (!$this->_directory->isExist($currentDir)) { - $this->_directory->create($currentDir); - } + $this->_directory->create($relPath); } catch (\Magento\Framework\Exception\FileSystemException $e) { - $message = __('The directory %1 is not writable by server.', $currentPath); + $message = __( + 'Can\'t create %1 as subdirectory of %2, you might have some permission issue.', + $relPath, + $this->_directory->getAbsolutePath() + ); throw new \Magento\Framework\Exception\LocalizedException($message); } - $this->_currentPath = $currentPath; } - return $this->_currentPath; } /** @@ -294,6 +309,8 @@ public function idEncode($string) public function idDecode($string) { $string = strtr($string, ':_-', '+/='); + + // phpcs:ignore Magento2.Functions.DiscouragedFunction return base64_decode($string); } @@ -315,7 +332,7 @@ public function getShortFilename($filename, $maxLength = 20) /** * Set user-traversable image directory subpath relative to media directory and relative to nested storage root * - * @var string $subpath + * @param string $subpath * @return void */ public function setImageDirectorySubpath($subpath) diff --git a/app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php b/app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php index d13b4f47a85e7..4acef951d8f4a 100644 --- a/app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php +++ b/app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php @@ -339,13 +339,14 @@ public function providerIsUsingStaticUrlsAllowed() * @param bool $isExist * @dataProvider providerGetCurrentPath */ - public function testGetCurrentPath($pathId, $expectedPath, $isExist) + public function testGetCurrentPath($pathId, $subDir, $expectedPath, $isExist) { $this->requestMock->expects($this->any()) ->method('getParam') ->willReturnMap( [ ['node', null, $pathId], + ['current_tree_path', null, $subDir], ] ); @@ -367,21 +368,33 @@ public function testGetCurrentPath($pathId, $expectedPath, $isExist) ['PATH', '.'], ] ); - $this->directoryWriteMock->expects($this->once()) - ->method('isExist') - ->willReturn($isExist); - $this->directoryWriteMock->expects($this->any()) - ->method('create') - ->with($this->directoryWriteMock->getRelativePath($expectedPath)); + + if ($subDir) { + $this->directoryWriteMock->expects($this->once()) + ->method('isExist') + ->willReturn($isExist); + $this->directoryWriteMock->expects($this->any()) + ->method('create') + ->with($this->directoryWriteMock->getRelativePath($expectedPath)); + } $this->assertEquals($expectedPath, $this->imagesHelper->getCurrentPath()); } public function testGetCurrentPathThrowException() { + $this->requestMock->expects($this->any()) + ->method('getParam') + ->willReturn('PATH'); + $this->expectException(\Magento\Framework\Exception\LocalizedException::class); - $this->expectExceptionMessage('The directory PATH is not writable by server.'); + $this->expectExceptionMessage( + 'Can\'t create SUBDIR as subdirectory of PATH, you might have some permission issue.' + ); + $this->directoryWriteMock->expects($this->any()) + ->method('getRelativePath') + ->willReturn('SUBDIR'); $this->directoryWriteMock->expects($this->once()) ->method('isExist') ->willReturn(false); @@ -402,12 +415,12 @@ public function testGetCurrentPathThrowException() public function providerGetCurrentPath() { return [ - ['L3Rlc3RfcGF0aA--', 'PATH/test_path', true], - ['L215LmpwZw--', 'PATH', true], - [null, 'PATH', true], - ['L3Rlc3RfcGF0aA--', 'PATH/test_path', false], - ['L215LmpwZw--', 'PATH', false], - [null, 'PATH', false], + ['L3Rlc3RfcGF0aA--', 'L3Rlc3RfcGF0aA--', 'PATH/test_path', true], + ['L215LmpwZw--', '', 'PATH', true], + [null, '', 'PATH', true], + ['L3Rlc3RfcGF0aA--', 'L3Rlc3RfcGF0aA--', 'PATH/test_path', false], + ['L215LmpwZw--', '', 'PATH', false], + [null, '', 'PATH', false], ]; } From 58dde946843684dc0eece859f3943b4c897e7ab8 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Tue, 11 Feb 2020 13:46:59 +0200 Subject: [PATCH 06/27] Add support for db_schema.xml char type column --- app/etc/di.xml | 1 + .../Schema/Dto/Columns/StringBinary.php | 7 ++-- .../Setup/Declaration/Schema/etc/schema.xsd | 1 + .../Schema/etc/types/texts/char.xsd | 33 +++++++++++++++++++ .../CharDefinition.php | 29 ++++++++++++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/types/texts/char.xsd create mode 100644 lib/internal/Magento/Framework/Setup/SchemaListenerDefinition/CharDefinition.php diff --git a/app/etc/di.xml b/app/etc/di.xml index dcd6a4253c98a..177c6b67fb50b 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1592,6 +1592,7 @@ Magento\Framework\Setup\SchemaListenerDefinition\TextBlobDefinition Magento\Framework\Setup\SchemaListenerDefinition\TextBlobDefinition Magento\Framework\Setup\SchemaListenerDefinition\TextBlobDefinition + Magento\Framework\Setup\SchemaListenerDefinition\CharDefinition Magento\Framework\Setup\SchemaListenerDefinition\TimestampDefinition Magento\Framework\Setup\SchemaListenerDefinition\TimestampDefinition Magento\Framework\Setup\SchemaListenerDefinition\DateDefinition diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Columns/StringBinary.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Columns/StringBinary.php index 58e6df1146300..4de198ae631f4 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Columns/StringBinary.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Columns/StringBinary.php @@ -11,7 +11,7 @@ /** * String or Binary column. - * Declared in SQL, like VARCHAR(L), BINARY(L) + * Declared in SQL, like CHAR(L), VARCHAR(L), BINARY(L) * where L - length. */ class StringBinary extends Column implements @@ -73,10 +73,9 @@ public function isNullable() } /** - * Return default value. - * Note: default value should be string. + * Return default value, Note: default value should be string. * - * @return string | null + * @return string|null */ public function getDefault() { diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd b/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd index bb9136d8a9ae6..2fbab18161925 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd @@ -20,6 +20,7 @@ + diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/types/texts/char.xsd b/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/types/texts/char.xsd new file mode 100644 index 0000000000000..27ec7852b3b8d --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/types/texts/char.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + Here plain text can be persisted without trailing spaces. Length of this field can't be more than 255 characters + When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled. + + + + + + + + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Setup/SchemaListenerDefinition/CharDefinition.php b/lib/internal/Magento/Framework/Setup/SchemaListenerDefinition/CharDefinition.php new file mode 100644 index 0000000000000..058ca69564871 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/SchemaListenerDefinition/CharDefinition.php @@ -0,0 +1,29 @@ + $definition['type'], + 'name' => $definition['name'], + 'length' => $definition['length'] ?? self::DEFAULT_TEXT_LENGTH, + 'default' => isset($definition['default']) ? (bool) $definition['default'] : null, + 'nullable' => $definition['nullable'] ?? true, + ]; + } +} From 684b951cb29ad0ecb0c6186cbcbcd1fbc25b51b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Mon, 17 Feb 2020 23:20:45 +0100 Subject: [PATCH 07/27] Fix #20309 - URL Rewrites redirect loop --- .../Magento/UrlRewrite/Controller/Router.php | 40 ++- .../UrlRewrite/Model/Storage/DbStorage.php | 13 +- .../Test/Unit/Controller/RouterTest.php | 308 +++++++++++------- .../Test/Unit/Model/Storage/DbStorageTest.php | 303 ++++++++--------- 4 files changed, 360 insertions(+), 304 deletions(-) diff --git a/app/code/Magento/UrlRewrite/Controller/Router.php b/app/code/Magento/UrlRewrite/Controller/Router.php index 0525621b6a20e..edefbb5f4ba3a 100644 --- a/app/code/Magento/UrlRewrite/Controller/Router.php +++ b/app/code/Magento/UrlRewrite/Controller/Router.php @@ -3,15 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\UrlRewrite\Controller; +use Magento\Framework\App\Action\Forward; use Magento\Framework\App\Action\Redirect; +use Magento\Framework\App\ActionFactory; use Magento\Framework\App\ActionInterface; use Magento\Framework\App\Request\Http as HttpRequest; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Response\Http as HttpResponse; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\App\RouterInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\UrlInterface; +use Magento\Store\Model\StoreManagerInterface; use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite; use Magento\UrlRewrite\Model\UrlFinderInterface; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; @@ -21,10 +28,10 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Router implements \Magento\Framework\App\RouterInterface +class Router implements RouterInterface { /** - * @var \Magento\Framework\App\ActionFactory + * @var ActionFactory */ protected $actionFactory; @@ -34,7 +41,7 @@ class Router implements \Magento\Framework\App\RouterInterface protected $url; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $storeManager; @@ -49,17 +56,17 @@ class Router implements \Magento\Framework\App\RouterInterface protected $urlFinder; /** - * @param \Magento\Framework\App\ActionFactory $actionFactory + * @param ActionFactory $actionFactory * @param UrlInterface $url - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\App\ResponseInterface $response + * @param StoreManagerInterface $storeManager + * @param ResponseInterface $response * @param UrlFinderInterface $urlFinder */ public function __construct( - \Magento\Framework\App\ActionFactory $actionFactory, + ActionFactory $actionFactory, UrlInterface $url, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\App\ResponseInterface $response, + StoreManagerInterface $storeManager, + ResponseInterface $response, UrlFinderInterface $urlFinder ) { $this->actionFactory = $actionFactory; @@ -83,24 +90,25 @@ public function match(RequestInterface $request) $this->storeManager->getStore()->getId() ); - if ($rewrite === null) { - //No rewrite rule matching current URl found, continuing with - //processing of this URL. + if ($rewrite === null || $rewrite->getRequestPath() === $rewrite->getTargetPath()) { + // Either no rewrite rule matching current URl found or found one with request path equal to + // target path, continuing with processing of this URL. return null; } + if ($rewrite->getRedirectType()) { - //Rule requires the request to be redirected to another URL - //and cannot be processed further. + // Rule requires the request to be redirected to another URL + // and cannot be processed further. return $this->processRedirect($request, $rewrite); } - //Rule provides actual URL that can be processed by a controller. + // Rule provides actual URL that can be processed by a controller. $request->setAlias( UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $rewrite->getRequestPath() ); $request->setPathInfo('/' . $rewrite->getTargetPath()); return $this->actionFactory->create( - \Magento\Framework\App\Action\Forward::class + Forward::class ); } diff --git a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php index f0e94e8379ad2..f187408d45a9d 100644 --- a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php +++ b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php @@ -138,17 +138,22 @@ private function extractMostRelevantUrlRewrite(string $requestPath, array $urlRe { $prioritizedUrlRewrites = []; foreach ($urlRewrites as $urlRewrite) { + $urlRewriteRequestPath = $urlRewrite[UrlRewrite::REQUEST_PATH]; + $urlRewriteTargetPath = $urlRewrite[UrlRewrite::TARGET_PATH]; switch (true) { - case $urlRewrite[UrlRewrite::REQUEST_PATH] === $requestPath: + case rtrim($urlRewriteRequestPath, '/') === rtrim($urlRewriteTargetPath, '/'): + $priority = 99; + break; + case $urlRewriteRequestPath === $requestPath: $priority = 1; break; - case $urlRewrite[UrlRewrite::REQUEST_PATH] === urldecode($requestPath): + case $urlRewriteRequestPath === urldecode($requestPath): $priority = 2; break; - case rtrim($urlRewrite[UrlRewrite::REQUEST_PATH], '/') === rtrim($requestPath, '/'): + case rtrim($urlRewriteRequestPath, '/') === rtrim($requestPath, '/'): $priority = 3; break; - case rtrim($urlRewrite[UrlRewrite::REQUEST_PATH], '/') === rtrim(urldecode($requestPath), '/'): + case rtrim($urlRewriteRequestPath, '/') === rtrim(urldecode($requestPath), '/'): $priority = 4; break; default: diff --git a/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php b/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php index c67f3f400b007..7038e75f16456 100644 --- a/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php +++ b/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php @@ -6,11 +6,19 @@ namespace Magento\UrlRewrite\Test\Unit\Controller; use Magento\Framework\App\Action\Forward; +use Magento\Framework\App\Action\Redirect; +use Magento\Framework\App\ActionFactory; +use Magento\Framework\App\RequestInterface; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\UrlInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\UrlRewrite\Controller\Router; +use Magento\UrlRewrite\Model\UrlFinderInterface; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; use Magento\Store\Model\Store; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Zend\Stdlib\ParametersInterface; /** @@ -18,15 +26,15 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class RouterTest extends \PHPUnit\Framework\TestCase +class RouterTest extends TestCase { /** - * @var \Magento\UrlRewrite\Controller\Router + * @var Router */ private $router; /** - * @var \Magento\Framework\App\ActionFactory|MockObject + * @var ActionFactory|MockObject */ private $actionFactory; @@ -36,7 +44,7 @@ class RouterTest extends \PHPUnit\Framework\TestCase private $url; /** - * @var \Magento\Store\Model\StoreManagerInterface|MockObject + * @var StoreManagerInterface|MockObject */ private $storeManager; @@ -46,12 +54,12 @@ class RouterTest extends \PHPUnit\Framework\TestCase private $store; /** - * @var \Magento\Framework\App\ResponseInterface|MockObject + * @var ResponseInterface|MockObject */ private $response; /** - * @var \Magento\Framework\App\RequestInterface|MockObject + * @var RequestInterface|MockObject */ private $request; @@ -61,7 +69,7 @@ class RouterTest extends \PHPUnit\Framework\TestCase private $requestQuery; /** - * @var \Magento\UrlRewrite\Model\UrlFinderInterface|MockObject + * @var UrlFinderInterface|MockObject */ private $urlFinder; @@ -71,24 +79,24 @@ class RouterTest extends \PHPUnit\Framework\TestCase protected function setUp() { $objectManager = new ObjectManager($this); - $this->actionFactory = $this->createMock(\Magento\Framework\App\ActionFactory::class); + $this->actionFactory = $this->createMock(ActionFactory::class); $this->url = $this->createMock(UrlInterface::class); - $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->storeManager = $this->createMock(StoreManagerInterface::class); $this->response = $this->createPartialMock( - \Magento\Framework\App\ResponseInterface::class, + ResponseInterface::class, ['setRedirect', 'sendResponse'] ); $this->requestQuery = $this->createMock(ParametersInterface::class); $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) ->disableOriginalConstructor()->getMock(); $this->request->method('getQuery')->willReturn($this->requestQuery); - $this->urlFinder = $this->createMock(\Magento\UrlRewrite\Model\UrlFinderInterface::class); + $this->urlFinder = $this->createMock(UrlFinderInterface::class); $this->store = $this->getMockBuilder( Store::class )->disableOriginalConstructor()->getMock(); $this->router = $objectManager->getObject( - \Magento\UrlRewrite\Controller\Router::class, + Router::class, [ 'actionFactory' => $this->actionFactory, 'url' => $this->url, @@ -104,9 +112,14 @@ protected function setUp() */ public function testNoRewriteExist() { - $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue(null)); - $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); - $this->store->expects($this->any())->method('getId')->will($this->returnValue('current-store-id')); + $this->request->method('getPathInfo') + ->willReturn(''); + $this->urlFinder->method('findOneByData') + ->willReturn(null); + $this->storeManager->method('getStore') + ->willReturn($this->store); + $this->store->method('getId') + ->willReturn(1); $this->assertNull($this->router->match($this->request)); } @@ -118,55 +131,43 @@ public function testRewriteAfterStoreSwitcher() { $initialRequestPath = 'request-path'; $newRequestPath = 'new-request-path'; + $newTargetPath = 'new-target-path'; $oldStoreAlias = 'old-store'; $oldStoreId = 'old-store-id'; $currentStoreId = 'current-store-id'; $rewriteEntityType = 'entity-type'; $rewriteEntityId = 42; - $this->request - ->expects($this->any()) - ->method('getParam') + $this->request->method('getParam') ->with('___from_store') ->willReturn($oldStoreAlias); - $this->request - ->expects($this->any()) - ->method('getPathInfo') + $this->request->method('getPathInfo') ->willReturn($initialRequestPath); $oldStore = $this->getMockBuilder(Store::class) ->disableOriginalConstructor() ->getMock(); - $oldStore->expects($this->any()) - ->method('getId') + $oldStore->method('getId') ->willReturn($oldStoreId); - $this->store - ->expects($this->any()) - ->method('getId') + $this->store->method('getId') ->willReturn($currentStoreId); - $this->storeManager - ->expects($this->any()) - ->method('getStore') + $this->storeManager->method('getStore') ->willReturnMap([[$oldStoreAlias, $oldStore], [null, $this->store]]); $oldUrlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor() ->getMock(); - $oldUrlRewrite->expects($this->any()) - ->method('getEntityType') + $oldUrlRewrite->method('getEntityType') ->willReturn($rewriteEntityType); - $oldUrlRewrite->expects($this->any()) - ->method('getEntityId') + $oldUrlRewrite->method('getEntityId') ->willReturn($rewriteEntityId); - $oldUrlRewrite->expects($this->any()) - ->method('getRedirectType') + $oldUrlRewrite->method('getRedirectType') ->willReturn(0); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor() ->getMock(); - $urlRewrite->expects($this->any()) - ->method('getRequestPath') + $urlRewrite->method('getRequestPath') ->willReturn($newRequestPath); - $this->urlFinder - ->expects($this->any()) - ->method('findOneByData') + $urlRewrite->method('getTargetPath') + ->willReturn($newTargetPath); + $this->urlFinder->method('findOneByData') ->willReturnMap( [ [ @@ -190,22 +191,22 @@ public function testRewriteAfterStoreSwitcher() */ public function testNoRewriteAfterStoreSwitcherWhenNoOldRewrite() { - $this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('request-path')); - $this->request->expects($this->any())->method('getParam')->with('___from_store') - ->will($this->returnValue('old-store')); + $this->request->method('getPathInfo')->willReturn('request-path'); + $this->request->method('getParam')->with('___from_store') + ->willReturn('old-store'); $oldStore = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); - $this->storeManager->expects($this->any())->method('getStore') - ->will($this->returnValueMap([['old-store', $oldStore], [null, $this->store]])); - $oldStore->expects($this->any())->method('getId')->will($this->returnValue('old-store-id')); - $this->store->expects($this->any())->method('getId')->will($this->returnValue('current-store-id')); + $this->storeManager->method('getStore') + ->willReturnMap([['old-store', $oldStore], [null, $this->store]]); + $oldStore->method('getId')->willReturn('old-store-id'); + $this->store->method('getId')->willReturn('current-store-id'); $oldUrlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $oldUrlRewrite->expects($this->any())->method('getEntityType')->will($this->returnValue('entity-type')); - $oldUrlRewrite->expects($this->any())->method('getEntityId')->will($this->returnValue('entity-id')); - $oldUrlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue('request-path')); + $oldUrlRewrite->method('getEntityType')->willReturn('entity-type'); + $oldUrlRewrite->method('getEntityId')->willReturn('entity-id'); + $oldUrlRewrite->method('getRequestPath')->willReturn('request-path'); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $urlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue('request-path')); + $urlRewrite->method('getRequestPath')->willReturn('request-path'); $this->assertNull($this->router->match($this->request)); } @@ -215,41 +216,39 @@ public function testNoRewriteAfterStoreSwitcherWhenNoOldRewrite() */ public function testNoRewriteAfterStoreSwitcherWhenOldRewriteEqualsToNewOne() { - $this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('request-path')); - $this->request->expects($this->any())->method('getParam')->with('___from_store') - ->will($this->returnValue('old-store')); + $this->request->method('getPathInfo')->willReturn('request-path'); + $this->request->method('getParam')->with('___from_store') + ->willReturn('old-store'); $oldStore = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); - $this->storeManager->expects($this->any())->method('getStore') - ->will($this->returnValueMap([['old-store', $oldStore], [null, $this->store]])); - $oldStore->expects($this->any())->method('getId')->will($this->returnValue('old-store-id')); - $this->store->expects($this->any())->method('getId')->will($this->returnValue('current-store-id')); + $this->storeManager->method('getStore') + ->willReturnMap([['old-store', $oldStore], [null, $this->store]]); + $oldStore->method('getId')->willReturn('old-store-id'); + $this->store->method('getId')->willReturn('current-store-id'); $oldUrlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $oldUrlRewrite->expects($this->any())->method('getEntityType')->will($this->returnValue('entity-type')); - $oldUrlRewrite->expects($this->any())->method('getEntityId')->will($this->returnValue('entity-id')); - $oldUrlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue('old-request-path')); + $oldUrlRewrite->method('getEntityType')->willReturn('entity-type'); + $oldUrlRewrite->method('getEntityId')->willReturn('entity-id'); + $oldUrlRewrite->method('getRequestPath')->willReturn('old-request-path'); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $urlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue('old-request-path')); + $urlRewrite->method('getRequestPath')->willReturn('old-request-path'); - $this->urlFinder->expects($this->any())->method('findOneByData')->will( - $this->returnValueMap( + $this->urlFinder->method('findOneByData')->willReturnMap( + [ + [ + [UrlRewrite::REQUEST_PATH => 'request-path', UrlRewrite::STORE_ID => 'old-store-id'], + $oldUrlRewrite, + ], [ [ - [UrlRewrite::REQUEST_PATH => 'request-path', UrlRewrite::STORE_ID => 'old-store-id'], - $oldUrlRewrite, + UrlRewrite::ENTITY_TYPE => 'entity-type', + UrlRewrite::ENTITY_ID => 'entity-id', + UrlRewrite::STORE_ID => 'current-store-id', + UrlRewrite::IS_AUTOGENERATED => 1, ], - [ - [ - UrlRewrite::ENTITY_TYPE => 'entity-type', - UrlRewrite::ENTITY_ID => 'entity-id', - UrlRewrite::STORE_ID => 'current-store-id', - UrlRewrite::IS_AUTOGENERATED => 1, - ], - $urlRewrite - ], - ] - ) + $urlRewrite + ], + ] ); $this->assertNull($this->router->match($this->request)); @@ -261,51 +260,103 @@ public function testNoRewriteAfterStoreSwitcherWhenOldRewriteEqualsToNewOne() public function testMatchWithRedirect() { $queryParams = []; - $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); + $redirectType = 'redirect-code'; + $requestPath = 'request-path'; + $targetPath = 'target-path'; + $newTargetPath = 'new-target-path'; + $this->storeManager->method('getStore') + ->willReturn($this->store); + $this->request->method('getPathInfo') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) - ->disableOriginalConstructor()->getMock(); - $urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue('redirect-code')); - $urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue('target-path')); - $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite)); - $this->response->expects($this->once())->method('setRedirect') - ->with('new-target-path', 'redirect-code'); - $this->request->expects($this->once())->method('getParams')->willReturn($queryParams); - $this->url->expects($this->once())->method('getUrl')->with( - '', - ['_direct' => 'target-path', '_query' => $queryParams] - ) - ->will($this->returnValue('new-target-path')); - $this->request->expects($this->once())->method('setDispatched')->with(true); - $this->actionFactory->expects($this->once())->method('create') - ->with(\Magento\Framework\App\Action\Redirect::class); + ->disableOriginalConstructor() + ->getMock(); + $urlRewrite->method('getRedirectType')->willReturn($redirectType); + $urlRewrite->method('getRequestPath')->willReturn($requestPath); + $urlRewrite->method('getTargetPath')->willReturn($targetPath); + $this->urlFinder->method('findOneByData')->willReturn($urlRewrite); + $this->response->expects($this->once()) + ->method('setRedirect') + ->with($newTargetPath, $redirectType); + $this->request->expects($this->once()) + ->method('getParams') + ->willReturn($queryParams); + $this->url->expects($this->once()) + ->method('getUrl') + ->with( + '', + ['_direct' => $targetPath, '_query' => $queryParams] + ) + ->willReturn($newTargetPath); + $this->request->expects($this->once()) + ->method('setDispatched') + ->with(true); + $this->actionFactory->expects($this->once()) + ->method('create') + ->with(Redirect::class); $this->router->match($this->request); } /** - * @return void + * @param string $requestPath + * @param string $targetPath + * @param bool $shouldRedirect + * @dataProvider customInternalRedirectDataProvider */ - public function testMatchWithCustomInternalRedirect() + public function testMatchWithCustomInternalRedirect($requestPath, $targetPath, $shouldRedirect) { $queryParams = []; - $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); + $redirectType = 'redirect-code'; + $this->storeManager->method('getStore') + ->willReturn($this->store); + $this->request->method('getPathInfo') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) - ->disableOriginalConstructor()->getMock(); - $urlRewrite->expects($this->any())->method('getEntityType')->will($this->returnValue('custom')); - $urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue('redirect-code')); - $urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue('target-path')); - $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite)); - $this->request->expects($this->any())->method('getParams')->willReturn($queryParams); - $this->response->expects($this->once())->method('setRedirect')->with('a', 'redirect-code'); - $this->url->expects($this->once())->method('getUrl')->with( - '', - ['_direct' => 'target-path', '_query' => $queryParams] - )->willReturn('a'); - $this->request->expects($this->once())->method('setDispatched')->with(true); - $this->actionFactory->expects($this->once())->method('create') - ->with(\Magento\Framework\App\Action\Redirect::class); + ->disableOriginalConstructor() + ->getMock(); + $urlRewrite->method('getEntityType')->willReturn('custom'); + $urlRewrite->method('getRedirectType')->willReturn($redirectType); + $urlRewrite->method('getRequestPath')->willReturn($requestPath); + $urlRewrite->method('getTargetPath')->willReturn($targetPath); + $this->urlFinder->method('findOneByData')->willReturn($urlRewrite); - $this->router->match($this->request); + if ($shouldRedirect) { + $this->request->method('getParams')->willReturn($queryParams); + $this->response->expects($this->once()) + ->method('setRedirect') + ->with('a', $redirectType); + $this->url->expects($this->once()) + ->method('getUrl') + ->with( + '', + ['_direct' => $targetPath, '_query' => $queryParams] + ) + ->willReturn('a'); + $this->request->expects($this->once()) + ->method('setDispatched') + ->with(true); + $this->actionFactory->expects($this->once()) + ->method('create') + ->with(Redirect::class); + } + + $routerResult = $this->router->match($this->request); + + if (!$shouldRedirect) { + $this->assertNull($routerResult); + } + } + + /** + * @return array + */ + public function customInternalRedirectDataProvider() + { + return [ + ['request-path', 'target-path', true], + ['/', '/', false], + ]; } /** @@ -314,19 +365,25 @@ public function testMatchWithCustomInternalRedirect() */ public function testMatchWithCustomExternalRedirect($targetPath) { - $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); + $requestPath = 'request-path'; + $this->storeManager->method('getStore')->willReturn($this->store); + $this->request->method('getPathInfo') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $urlRewrite->expects($this->any())->method('getEntityType')->will($this->returnValue('custom')); - $urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue('redirect-code')); - $urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue($targetPath)); - $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite)); - $this->response->expects($this->once())->method('setRedirect')->with($targetPath, 'redirect-code'); + $urlRewrite->method('getEntityType')->willReturn('custom'); + $urlRewrite->method('getRedirectType')->willReturn('redirect-code'); + $urlRewrite->method('getRequestPath')->willReturn($requestPath); + $urlRewrite->method('getTargetPath')->willReturn($targetPath); + $this->urlFinder->method('findOneByData')->willReturn($urlRewrite); + $this->response->expects($this->once()) + ->method('setRedirect') + ->with($targetPath, 'redirect-code'); $this->request->expects($this->never())->method('getParams'); $this->url->expects($this->never())->method('getUrl'); $this->request->expects($this->once())->method('setDispatched')->with(true); $this->actionFactory->expects($this->once())->method('create') - ->with(\Magento\Framework\App\Action\Redirect::class); + ->with(Redirect::class); $this->router->match($this->request); } @@ -347,18 +404,21 @@ public function externalRedirectTargetPathDataProvider() */ public function testMatch() { - $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); + $requestPath = 'request-path'; + $this->storeManager->method('getStore')->willReturn($this->store); + $this->request->method('getPathInfo') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue(0)); - $urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue('target-path')); - $urlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue('request-path')); - $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite)); + $urlRewrite->method('getRedirectType')->willReturn(0); + $urlRewrite->method('getRequestPath')->willReturn($requestPath); + $urlRewrite->method('getTargetPath')->willReturn('target-path'); + $this->urlFinder->method('findOneByData')->willReturn($urlRewrite); $this->request->expects($this->once())->method('setPathInfo')->with('/target-path'); $this->request->expects($this->once())->method('setAlias') ->with(UrlInterface::REWRITE_REQUEST_PATH_ALIAS, 'request-path'); $this->actionFactory->expects($this->once())->method('create') - ->with(\Magento\Framework\App\Action\Forward::class); + ->with(Forward::class); $this->router->match($this->request); } diff --git a/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php b/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php index 697ce33be0fa7..946f30f609290 100644 --- a/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php +++ b/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php @@ -6,64 +6,68 @@ namespace Magento\UrlRewrite\Test\Unit\Model\Storage; +use Magento\Framework\Api\DataObjectHelper; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Select; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\UrlRewrite\Model\Storage\DbStorage; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; +use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; -class DbStorageTest extends \PHPUnit\Framework\TestCase +class DbStorageTest extends TestCase { /** - * @var \Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory|\PHPUnit_Framework_MockObject_MockObject + * @var UrlRewriteFactory|MockObject */ - protected $urlRewriteFactory; + private $urlRewriteFactory; /** - * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject + * @var DataObjectHelper|MockObject */ - protected $dataObjectHelper; + private $dataObjectHelper; /** - * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject + * @var AdapterInterface|MockObject */ - protected $connectionMock; + private $connectionMock; /** - * @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\DB\Select|MockObject */ - protected $select; + private $select; /** - * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject + * @var ResourceConnection|MockObject */ - protected $resource; + private $resource; /** - * @var \Magento\UrlRewrite\Model\Storage\DbStorage + * @var DbStorage */ - protected $storage; + private $storage; protected function setUp() { - $this->urlRewriteFactory = $this->getMockBuilder(\Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory::class) + $this->urlRewriteFactory = $this->getMockBuilder(UrlRewriteFactory::class) ->setMethods(['create']) ->disableOriginalConstructor()->getMock(); - $this->dataObjectHelper = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class); - $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class); + $this->dataObjectHelper = $this->createMock(DataObjectHelper::class); + $this->connectionMock = $this->createMock(AdapterInterface::class); $this->select = $this->getMockBuilder(Select::class) ->disableOriginalConstructor() ->getMock(); - $this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class); + $this->resource = $this->createMock(ResourceConnection::class); - $this->resource->expects($this->any()) - ->method('getConnection') - ->will($this->returnValue($this->connectionMock)); - $this->connectionMock->expects($this->any()) - ->method('select') - ->will($this->returnValue($this->select)); + $this->resource->method('getConnection') + ->willReturn($this->connectionMock); + $this->connectionMock->method('select') + ->willReturn($this->select); $this->storage = (new ObjectManager($this))->getObject( - \Magento\UrlRewrite\Model\Storage\DbStorage::class, + DbStorage::class, [ 'urlRewriteFactory' => $this->urlRewriteFactory, 'dataObjectHelper' => $this->dataObjectHelper, @@ -84,32 +88,32 @@ public function testFindAllByData() ->method('where') ->with('col2 IN (?)', 'val2'); - $this->connectionMock->expects($this->any()) + $this->connectionMock ->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->connectionMock->expects($this->once()) ->method('fetchAll') ->with($this->select) - ->will($this->returnValue([['row1'], ['row2']])); + ->willReturn([['row1'], ['row2']]); $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], ['row1'], \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + ->with(['urlRewrite1'], ['row1'], UrlRewrite::class) ->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->dataObjectHelper->expects($this->at(1)) ->method('populateWithArray') - ->with(['urlRewrite2'], ['row2'], \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + ->with(['urlRewrite2'], ['row2'], UrlRewrite::class) ->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->at(1)) ->method('create') - ->will($this->returnValue(['urlRewrite2'])); + ->willReturn(['urlRewrite2']); $this->assertEquals([['urlRewrite1'], ['urlRewrite2']], $this->storage->findAllByData($data)); } @@ -126,25 +130,24 @@ public function testFindOneByData() ->method('where') ->with('col2 IN (?)', 'val2'); - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') + $this->connectionMock->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->connectionMock->expects($this->once()) ->method('fetchRow') ->with($this->select) - ->will($this->returnValue(['row1'])); + ->willReturn(['row1']); $this->connectionMock->expects($this->never())->method('fetchAll'); $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], ['row1'], \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + ->with(['urlRewrite1'], ['row1'], UrlRewrite::class) ->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); } @@ -153,8 +156,8 @@ public function testFindOneByDataWithRequestPath() { $origRequestPath = 'page-one'; $data = [ - 'col1' => 'val1', - 'col2' => 'val2', + 'col1' => 'val1', + 'col2' => 'val2', UrlRewrite::REQUEST_PATH => $origRequestPath, ]; @@ -170,31 +173,31 @@ public function testFindOneByDataWithRequestPath() ->method('where') ->with('request_path IN (?)', [$origRequestPath, $origRequestPath . '/']); - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') + $this->connectionMock->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->connectionMock->expects($this->never()) ->method('fetchRow'); $urlRewriteRowInDb = [ - UrlRewrite::REQUEST_PATH => $origRequestPath, + UrlRewrite::REQUEST_PATH => $origRequestPath, + UrlRewrite::TARGET_PATH => $origRequestPath, UrlRewrite::REDIRECT_TYPE => 0, ]; $this->connectionMock->expects($this->once()) ->method('fetchAll') ->with($this->select) - ->will($this->returnValue([$urlRewriteRowInDb])); + ->willReturn([$urlRewriteRowInDb]); $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], $urlRewriteRowInDb, \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) - ->will($this->returnSelf()); + ->with(['urlRewrite1'], $urlRewriteRowInDb, UrlRewrite::class) + ->willReturnSelf(); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); } @@ -203,8 +206,8 @@ public function testFindOneByDataWithRequestPathIsDifferent() { $origRequestPath = 'page-one'; $data = [ - 'col1' => 'val1', - 'col2' => 'val2', + 'col1' => 'val1', + 'col2' => 'val2', UrlRewrite::REQUEST_PATH => $origRequestPath, ]; @@ -220,44 +223,44 @@ public function testFindOneByDataWithRequestPathIsDifferent() ->method('where') ->with('request_path IN (?)', [$origRequestPath, $origRequestPath . '/']); - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') + $this->connectionMock->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->connectionMock->expects($this->never()) ->method('fetchRow'); $urlRewriteRowInDb = [ - UrlRewrite::REQUEST_PATH => $origRequestPath . '/', + UrlRewrite::REQUEST_PATH => $origRequestPath . '/', + UrlRewrite::TARGET_PATH => $origRequestPath . '/', UrlRewrite::REDIRECT_TYPE => 0, - UrlRewrite::STORE_ID => 1, + UrlRewrite::STORE_ID => 1, ]; $this->connectionMock->expects($this->once()) ->method('fetchAll') ->with($this->select) - ->will($this->returnValue([$urlRewriteRowInDb])); + ->willReturn([$urlRewriteRowInDb]); $urlRewriteRedirect = [ - 'request_path' => $origRequestPath, - 'redirect_type' => 301, - 'store_id' => 1, - 'entity_type' => 'custom', - 'entity_id' => '0', - 'target_path' => $origRequestPath . '/', - 'description' => null, + 'request_path' => $origRequestPath, + 'redirect_type' => 301, + 'store_id' => 1, + 'entity_type' => 'custom', + 'entity_id' => '0', + 'target_path' => $origRequestPath . '/', + 'description' => null, 'is_autogenerated' => '0', - 'metadata' => null, + 'metadata' => null, ]; $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], $urlRewriteRedirect, \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + ->with(['urlRewrite1'], $urlRewriteRedirect, UrlRewrite::class) ->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); } @@ -266,8 +269,8 @@ public function testFindOneByDataWithRequestPathIsDifferent2() { $origRequestPath = 'page-one/'; $data = [ - 'col1' => 'val1', - 'col2' => 'val2', + 'col1' => 'val1', + 'col2' => 'val2', UrlRewrite::REQUEST_PATH => $origRequestPath, ]; @@ -283,7 +286,7 @@ public function testFindOneByDataWithRequestPathIsDifferent2() ->method('where') ->with('request_path IN (?)', [rtrim($origRequestPath, '/'), rtrim($origRequestPath, '/') . '/']); - $this->connectionMock->expects($this->any()) + $this->connectionMock ->method('quoteIdentifier') ->will($this->returnArgument(0)); @@ -291,36 +294,37 @@ public function testFindOneByDataWithRequestPathIsDifferent2() ->method('fetchRow'); $urlRewriteRowInDb = [ - UrlRewrite::REQUEST_PATH => rtrim($origRequestPath, '/'), + UrlRewrite::REQUEST_PATH => rtrim($origRequestPath, '/'), + UrlRewrite::TARGET_PATH => rtrim($origRequestPath, '/'), UrlRewrite::REDIRECT_TYPE => 0, - UrlRewrite::STORE_ID => 1, + UrlRewrite::STORE_ID => 1, ]; $this->connectionMock->expects($this->once()) ->method('fetchAll') ->with($this->select) - ->will($this->returnValue([$urlRewriteRowInDb])); + ->willReturn([$urlRewriteRowInDb]); $urlRewriteRedirect = [ - 'request_path' => $origRequestPath, - 'redirect_type' => 301, - 'store_id' => 1, - 'entity_type' => 'custom', - 'entity_id' => '0', - 'target_path' => rtrim($origRequestPath, '/'), - 'description' => null, + 'request_path' => $origRequestPath, + 'redirect_type' => 301, + 'store_id' => 1, + 'entity_type' => 'custom', + 'entity_id' => '0', + 'target_path' => rtrim($origRequestPath, '/'), + 'description' => null, 'is_autogenerated' => '0', - 'metadata' => null, + 'metadata' => null, ]; $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], $urlRewriteRedirect, \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + ->with(['urlRewrite1'], $urlRewriteRedirect, UrlRewrite::class) ->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); } @@ -329,8 +333,8 @@ public function testFindOneByDataWithRequestPathIsRedirect() { $origRequestPath = 'page-one'; $data = [ - 'col1' => 'val1', - 'col2' => 'val2', + 'col1' => 'val1', + 'col2' => 'val2', UrlRewrite::REQUEST_PATH => $origRequestPath, ]; @@ -346,33 +350,32 @@ public function testFindOneByDataWithRequestPathIsRedirect() ->method('where') ->with('request_path IN (?)', [$origRequestPath, $origRequestPath . '/']); - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') + $this->connectionMock->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->connectionMock->expects($this->never()) ->method('fetchRow'); $urlRewriteRowInDb = [ - UrlRewrite::REQUEST_PATH => $origRequestPath . '/', - UrlRewrite::TARGET_PATH => 'page-A/', + UrlRewrite::REQUEST_PATH => $origRequestPath . '/', + UrlRewrite::TARGET_PATH => 'page-A/', UrlRewrite::REDIRECT_TYPE => 301, - UrlRewrite::STORE_ID => 1, + UrlRewrite::STORE_ID => 1, ]; $this->connectionMock->expects($this->once()) ->method('fetchAll') ->with($this->select) - ->will($this->returnValue([$urlRewriteRowInDb])); + ->willReturn([$urlRewriteRowInDb]); $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], $urlRewriteRowInDb, \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) - ->will($this->returnSelf()); + ->with(['urlRewrite1'], $urlRewriteRowInDb, UrlRewrite::class) + ->willReturnSelf(); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); } @@ -398,40 +401,39 @@ public function testFindOneByDataWithRequestPathTwoResults() ->method('where') ->with('request_path IN (?)', [$origRequestPath, $origRequestPath . '/']); - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') + $this->connectionMock->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->connectionMock->expects($this->never()) ->method('fetchRow'); $urlRewriteRowInDb = [ - UrlRewrite::REQUEST_PATH => $origRequestPath . '/', - UrlRewrite::TARGET_PATH => 'page-A/', + UrlRewrite::REQUEST_PATH => $origRequestPath . '/', + UrlRewrite::TARGET_PATH => 'page-A/', UrlRewrite::REDIRECT_TYPE => 301, - UrlRewrite::STORE_ID => 1, + UrlRewrite::STORE_ID => 1, ]; $urlRewriteRowInDb2 = [ - UrlRewrite::REQUEST_PATH => $origRequestPath, - UrlRewrite::TARGET_PATH => 'page-B/', + UrlRewrite::REQUEST_PATH => $origRequestPath, + UrlRewrite::TARGET_PATH => 'page-B/', UrlRewrite::REDIRECT_TYPE => 301, - UrlRewrite::STORE_ID => 1, + UrlRewrite::STORE_ID => 1, ]; $this->connectionMock->expects($this->once()) ->method('fetchAll') ->with($this->select) - ->will($this->returnValue([$urlRewriteRowInDb, $urlRewriteRowInDb2])); + ->willReturn([$urlRewriteRowInDb, $urlRewriteRowInDb2]); $this->dataObjectHelper->expects($this->at(0)) ->method('populateWithArray') - ->with(['urlRewrite1'], $urlRewriteRowInDb2, \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) - ->will($this->returnSelf()); + ->with(['urlRewrite1'], $urlRewriteRowInDb2, UrlRewrite::class) + ->willReturnSelf(); $this->urlRewriteFactory->expects($this->at(0)) ->method('create') - ->will($this->returnValue(['urlRewrite1'])); + ->willReturn(['urlRewrite1']); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); } @@ -441,58 +443,48 @@ public function testFindOneByDataWithRequestPathTwoResults() */ public function testReplace() { - $urlFirst = $this->createMock(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class); - $urlSecond = $this->createMock(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class); + $urlFirst = $this->createMock(UrlRewrite::class); + $urlSecond = $this->createMock(UrlRewrite::class); // delete - $urlFirst->expects($this->any()) - ->method('getEntityType') + $urlFirst->method('getEntityType') ->willReturn('product'); - $urlFirst->expects($this->any()) - ->method('getEntityId') + $urlFirst->method('getEntityId') ->willReturn('entity_1'); - $urlFirst->expects($this->any()) - ->method('getStoreId') + $urlFirst->method('getStoreId') ->willReturn('store_id_1'); - $urlSecond->expects($this->any()) - ->method('getEntityType') + $urlSecond->method('getEntityType') ->willReturn('category'); - $urlSecond->expects($this->any()) - ->method('getEntityId') + $urlSecond->method('getEntityId') ->willReturn('entity_2'); - $urlSecond->expects($this->any()) - ->method('getStoreId') + $urlSecond->method('getStoreId') ->willReturn('store_id_2'); - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') - ->will($this->returnArgument(0)); + $this->connectionMock->method('quoteIdentifier') + ->willReturnArgument(0); - $this->select->expects($this->any()) - ->method($this->anything()) + $this->select->method($this->anything()) ->willReturnSelf(); - $this->resource->expects($this->any()) - ->method('getTableName') + $this->resource->method('getTableName') ->with(DbStorage::TABLE_NAME) - ->will($this->returnValue('table_name')); + ->willReturn('table_name'); // insert - $urlFirst->expects($this->any()) - ->method('toArray') - ->will($this->returnValue(['row1'])); - $urlSecond->expects($this->any()) - ->method('toArray') - ->will($this->returnValue(['row2'])); + $urlFirst->method('toArray') + ->willReturn(['row1']); + $urlSecond->method('toArray') + ->willReturn(['row2']); - $this->resource->expects($this->any()) - ->method('getTableName') + $this->resource->method('getTableName') ->with(DbStorage::TABLE_NAME) - ->will($this->returnValue('table_name')); + ->willReturn('table_name'); + + $urls = [$urlFirst, $urlSecond]; - $this->storage->replace([$urlFirst, $urlSecond]); + $this->assertEquals($urls, $this->storage->replace($urls)); } /** @@ -500,23 +492,20 @@ public function testReplace() */ public function testReplaceIfThrewExceptionOnDuplicateUrl() { - $url = $this->createMock(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class); + $url = $this->createMock(UrlRewrite::class); - $url->expects($this->any()) - ->method('toArray') - ->will($this->returnValue(['row1'])); + $url->method('toArray') + ->willReturn(['row1']); $this->connectionMock->expects($this->once()) ->method('insertMultiple') - ->will( - $this->throwException( - new \Exception('SQLSTATE[23000]: test: 1062 test', DbStorage::ERROR_CODE_DUPLICATE_ENTRY) - ) + ->willThrowException( + new \Exception('SQLSTATE[23000]: test: 1062 test', DbStorage::ERROR_CODE_DUPLICATE_ENTRY) ); $conflictingUrl = [ UrlRewrite::URL_REWRITE_ID => 'conflicting-url' ]; - $this->connectionMock->expects($this->any()) + $this->connectionMock ->method('fetchRow') ->willReturn($conflictingUrl); @@ -533,18 +522,15 @@ public function testReplaceIfThrewExceptionOnDuplicateUrl() */ public function testReplaceIfThrewExceptionOnDuplicateEntry() { - $url = $this->createMock(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class); + $url = $this->createMock(UrlRewrite::class); - $url->expects($this->any()) - ->method('toArray') - ->will($this->returnValue(['row1'])); + $url->method('toArray') + ->willReturn(['row1']); $this->connectionMock->expects($this->once()) ->method('insertMultiple') - ->will( - $this->throwException( - new \Exception('SQLSTATE[23000]: test: 1062 test', DbStorage::ERROR_CODE_DUPLICATE_ENTRY) - ) + ->willThrowException( + new \Exception('SQLSTATE[23000]: test: 1062 test', DbStorage::ERROR_CODE_DUPLICATE_ENTRY) ); $this->storage->replace([$url]); @@ -555,15 +541,14 @@ public function testReplaceIfThrewExceptionOnDuplicateEntry() */ public function testReplaceIfThrewCustomException() { - $url = $this->createMock(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class); + $url = $this->createMock(UrlRewrite::class); - $url->expects($this->any()) - ->method('toArray') - ->will($this->returnValue(['row1'])); + $url->method('toArray') + ->willReturn(['row1']); $this->connectionMock->expects($this->once()) ->method('insertMultiple') - ->will($this->throwException(new \RuntimeException())); + ->willThrowException(new \RuntimeException()); $this->storage->replace([$url]); } @@ -572,8 +557,7 @@ public function testDeleteByData() { $data = ['col1' => 'val1', 'col2' => 'val2']; - $this->connectionMock->expects($this->any()) - ->method('quoteIdentifier') + $this->connectionMock->method('quoteIdentifier') ->will($this->returnArgument(0)); $this->select->expects($this->at(1)) @@ -587,12 +571,11 @@ public function testDeleteByData() $this->select->expects($this->at(3)) ->method('deleteFromSelect') ->with('table_name') - ->will($this->returnValue('sql delete query')); + ->willReturn('sql delete query'); - $this->resource->expects($this->any()) - ->method('getTableName') + $this->resource->method('getTableName') ->with(DbStorage::TABLE_NAME) - ->will($this->returnValue('table_name')); + ->willReturn('table_name'); $this->connectionMock->expects($this->once()) ->method('query') From d359cdf8037187c53441965920c555a3bf95985a Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Thu, 20 Feb 2020 10:09:49 +0200 Subject: [PATCH 08/27] ObjectManager cleanup - Remove usage from AdminNotification module --- .../Block/System/Messages.php | 54 +++++++++---------- .../Adminhtml/Notification/AjaxMarkAsRead.php | 18 +++---- .../Adminhtml/Notification/MarkAsRead.php | 23 +++++--- .../Adminhtml/Notification/MassMarkAsRead.php | 20 +++++-- .../Adminhtml/Notification/MassRemove.php | 18 ++++++- .../Adminhtml/Notification/Remove.php | 20 +++++-- 6 files changed, 102 insertions(+), 51 deletions(-) diff --git a/app/code/Magento/AdminNotification/Block/System/Messages.php b/app/code/Magento/AdminNotification/Block/System/Messages.php index b950f5583e599..2fbd918c2d824 100644 --- a/app/code/Magento/AdminNotification/Block/System/Messages.php +++ b/app/code/Magento/AdminNotification/Block/System/Messages.php @@ -5,45 +5,51 @@ */ namespace Magento\AdminNotification\Block\System; -class Messages extends \Magento\Backend\Block\Template +use Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized; +use Magento\Backend\Block\Template; +use Magento\Backend\Block\Template\Context as TemplateContext; +use Magento\Framework\Json\Helper\Data as JsonDataHelper; +use Magento\Framework\Notification\MessageInterface; +use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; + +class Messages extends Template { /** - * Message list + * Synchronized Message collection * - * @var \Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized + * @var Synchronized */ protected $_messages; /** - * @var \Magento\Framework\Json\Helper\Data + * @var JsonDataHelper * @deprecated */ protected $jsonHelper; /** - * @var \Magento\Framework\Serialize\Serializer\Json + * @var JsonSerializer */ private $serializer; /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized $messages - * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * @param TemplateContext $context + * @param Synchronized $messages + * @param JsonDataHelper $jsonHelper + * @param JsonSerializer $serializer * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized $messages, - \Magento\Framework\Json\Helper\Data $jsonHelper, - array $data = [], - \Magento\Framework\Serialize\Serializer\Json $serializer = null + TemplateContext $context, + Synchronized $messages, + JsonDataHelper $jsonHelper, + JsonSerializer $serializer, + array $data = [] ) { $this->jsonHelper = $jsonHelper; parent::__construct($context, $data); $this->_messages = $messages; - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\Serializer\Json::class); + $this->serializer = $serializer; } /** @@ -62,15 +68,13 @@ protected function _toHtml() /** * Retrieve message list * - * @return \Magento\Framework\Notification\MessageInterface[] + * @return MessageInterface[]|null */ public function getLastCritical() { $items = array_values($this->_messages->getItems()); - if (isset( - $items[0] - ) && $items[0]->getSeverity() == \Magento\Framework\Notification\MessageInterface::SEVERITY_CRITICAL - ) { + + if (isset($items[0]) && (int)$items[0]->getSeverity() === MessageInterface::SEVERITY_CRITICAL) { return $items[0]; } return null; @@ -83,9 +87,7 @@ public function getLastCritical() */ public function getCriticalCount() { - return $this->_messages->getCountBySeverity( - \Magento\Framework\Notification\MessageInterface::SEVERITY_CRITICAL - ); + return $this->_messages->getCountBySeverity(MessageInterface::SEVERITY_CRITICAL); } /** @@ -95,9 +97,7 @@ public function getCriticalCount() */ public function getMajorCount() { - return $this->_messages->getCountBySeverity( - \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR - ); + return $this->_messages->getCountBySeverity(MessageInterface::SEVERITY_MAJOR); } /** diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php index da797fe12e75a..e05de78c92356 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php @@ -6,28 +6,26 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\AdminNotification\Model\NotificationService; use Magento\Backend\App\Action; use Magento\Framework\Controller\ResultFactory; -class AjaxMarkAsRead extends \Magento\AdminNotification\Controller\Adminhtml\Notification +class AjaxMarkAsRead extends Notification { /** - * @var \Magento\AdminNotification\Model\NotificationService + * @var NotificationService */ private $notificationService; /** * @param Action\Context $context - * @param \Magento\AdminNotification\Model\NotificationService|null $notificationService - * @throws \RuntimeException + * @param NotificationService $notificationService */ - public function __construct( - Action\Context $context, - \Magento\AdminNotification\Model\NotificationService $notificationService = null - ) { + public function __construct(Action\Context $context, NotificationService $notificationService) + { parent::__construct($context); - $this->notificationService = $notificationService?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\AdminNotification\Model\NotificationService::class); + $this->notificationService = $notificationService; } /** diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php index 6b5e0681139cf..edc6c702abe26 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php @@ -6,7 +6,11 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; -class MarkAsRead extends \Magento\AdminNotification\Controller\Adminhtml\Notification +use Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\AdminNotification\Model\NotificationService; +use Magento\Backend\App\Action; + +class MarkAsRead extends Notification { /** * Authorization level of a basic admin session @@ -15,6 +19,17 @@ class MarkAsRead extends \Magento\AdminNotification\Controller\Adminhtml\Notific */ const ADMIN_RESOURCE = 'Magento_AdminNotification::mark_as_read'; + /** + * @var NotificationService + */ + private $notificationService; + + public function __construct(Action\Context $context, NotificationService $notificationService) + { + parent::__construct($context); + $this->notificationService = $notificationService; + } + /** * @return void */ @@ -23,11 +38,7 @@ public function execute() $notificationId = (int)$this->getRequest()->getParam('id'); if ($notificationId) { try { - $this->_objectManager->create( - \Magento\AdminNotification\Model\NotificationService::class - )->markAsRead( - $notificationId - ); + $this->notificationService->markAsRead($notificationId); $this->messageManager->addSuccessMessage(__('The message has been marked as Read.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php index 9ae4a7cdac0b9..e73f4219b7333 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php @@ -6,9 +6,12 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; -class MassMarkAsRead extends \Magento\AdminNotification\Controller\Adminhtml\Notification -{ +use Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; +use Magento\Backend\App\Action; +class MassMarkAsRead extends Notification +{ /** * Authorization level of a basic admin session * @@ -16,6 +19,17 @@ class MassMarkAsRead extends \Magento\AdminNotification\Controller\Adminhtml\Not */ const ADMIN_RESOURCE = 'Magento_AdminNotification::mark_as_read'; + /** + * @var InboxModelFactory + */ + private $inboxModelFactory; + + public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) + { + parent::__construct($context); + $this->inboxModelFactory = $inboxModelFactory; + } + /** * @return void */ @@ -27,7 +41,7 @@ public function execute() } else { try { foreach ($ids as $id) { - $model = $this->_objectManager->create(\Magento\AdminNotification\Model\Inbox::class)->load($id); + $model = $this->inboxModelFactory->create()->load($id); if ($model->getId()) { $model->setIsRead(1)->save(); } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php index 06659b8452cab..a248430b5660c 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php @@ -6,7 +6,11 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; -class MassRemove extends \Magento\AdminNotification\Controller\Adminhtml\Notification +use Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; +use Magento\Backend\App\Action; + +class MassRemove extends Notification { /** @@ -15,6 +19,16 @@ class MassRemove extends \Magento\AdminNotification\Controller\Adminhtml\Notific * @see _isAllowed() */ const ADMIN_RESOURCE = 'Magento_AdminNotification::adminnotification_remove'; + /** + * @var InboxModelFactory + */ + private $inboxModelFactory; + + public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) + { + parent::__construct($context); + $this->inboxModelFactory = $inboxModelFactory; + } /** * @return void @@ -27,7 +41,7 @@ public function execute() } else { try { foreach ($ids as $id) { - $model = $this->_objectManager->create(\Magento\AdminNotification\Model\Inbox::class)->load($id); + $model = $this->inboxModelFactory->create()->load($id); if ($model->getId()) { $model->setIsRemove(1)->save(); } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php index f0724a9587c50..0d74db43eef2b 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php @@ -6,9 +6,12 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; -class Remove extends \Magento\AdminNotification\Controller\Adminhtml\Notification -{ +use Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; +use Magento\Backend\App\Action; +class Remove extends Notification +{ /** * Authorization level of a basic admin session * @@ -16,13 +19,24 @@ class Remove extends \Magento\AdminNotification\Controller\Adminhtml\Notificatio */ const ADMIN_RESOURCE = 'Magento_AdminNotification::adminnotification_remove'; + /** + * @var InboxModelFactory + */ + private $inboxModelFactory; + + public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) + { + parent::__construct($context); + $this->inboxModelFactory = $inboxModelFactory; + } + /** * @return void */ public function execute() { if ($id = $this->getRequest()->getParam('id')) { - $model = $this->_objectManager->create(\Magento\AdminNotification\Model\Inbox::class)->load($id); + $model = $this->inboxModelFactory->create()->load($id); if (!$model->getId()) { $this->_redirect('adminhtml/*/'); From 26ff555d098c86bf539d1f37f3ffd26a07a6f4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Wed, 15 Jan 2020 12:09:07 +0100 Subject: [PATCH 09/27] Cleanup ObjectManager usage - Magento_Elasticsearch --- .../CategoryFieldsProvider.php | 18 +++--- .../Adapter/DataMapper/ProductDataMapper.php | 27 ++++---- .../FieldMapper/ProductFieldMapper.php | 32 +++++----- .../Elasticsearch5/SearchAdapter/Adapter.php | 39 +++++------ .../SearchAdapter/Query/Builder.php | 20 ++---- .../CategoryFieldsProvider.php | 18 +++--- .../BatchDataMapper/PriceFieldsProvider.php | 22 +++---- .../Model/Adapter/Elasticsearch.php | 61 ++++++++++-------- .../Product/FieldProvider/DynamicField.php | 16 ++--- .../FieldName/Resolver/CategoryName.php | 13 ++-- .../FieldName/Resolver/Position.php | 13 ++-- .../FieldName/Resolver/Price.php | 14 ++-- .../Product/FieldProvider/StaticField.php | 20 +++--- .../Model/DataProvider/Suggestions.php | 24 +++---- .../Elasticsearch/SearchAdapter/Adapter.php | 11 ++-- .../SearchAdapter/Aggregation/Builder.php | 22 ++++--- .../SearchAdapter/Filter/Builder/Term.php | 14 ++-- .../SearchAdapter/Query/Builder.php | 39 ++++++----- .../SearchAdapter/Query/Builder/Match.php | 34 +++++----- .../Query/Preprocessor/Stopwords.php | 64 +++++++++---------- 20 files changed, 247 insertions(+), 274 deletions(-) diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php index eb7874a936140..dd9a9d904ddfe 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php @@ -3,14 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\BatchDataMapper; -use Magento\Elasticsearch\Model\ResourceModel\Index; use Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Framework\App\ObjectManager; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; +use Magento\Elasticsearch\Model\ResourceModel\Index; /** * Provide data mapping for categories fields @@ -34,19 +34,17 @@ class CategoryFieldsProvider implements AdditionalFieldsProviderInterface /** * @param Index $resourceIndex - * @param AttributeProvider|null $attributeAdapterProvider - * @param ResolverInterface|null $fieldNameResolver + * @param AttributeProvider $attributeAdapterProvider + * @param ResolverInterface $fieldNameResolver */ public function __construct( Index $resourceIndex, - AttributeProvider $attributeAdapterProvider = null, - ResolverInterface $fieldNameResolver = null + AttributeProvider $attributeAdapterProvider, + ResolverInterface $fieldNameResolver ) { $this->resourceIndex = $resourceIndex; - $this->attributeAdapterProvider = $attributeAdapterProvider ?: ObjectManager::getInstance() - ->get(AttributeProvider::class); - $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() - ->get(ResolverInterface::class); + $this->attributeAdapterProvider = $attributeAdapterProvider; + $this->fieldNameResolver = $fieldNameResolver; } /** diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/DataMapper/ProductDataMapper.php b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/DataMapper/ProductDataMapper.php index f0b7380397235..7007a8a6a8533 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/DataMapper/ProductDataMapper.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/DataMapper/ProductDataMapper.php @@ -7,17 +7,16 @@ namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\DataMapper; use Magento\Catalog\Model\ResourceModel\Eav\Attribute; -use Magento\Elasticsearch\Model\Adapter\Container\Attribute as AttributeContainer; -use Magento\Elasticsearch\Model\Adapter\Document\Builder; -use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\Data\GroupInterface; -use Magento\Elasticsearch\Model\ResourceModel\Index; -use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; +use Magento\Elasticsearch\Model\Adapter\Container\Attribute as AttributeContainer; use Magento\Elasticsearch\Model\Adapter\DataMapperInterface; -use Magento\Elasticsearch\Model\Adapter\FieldType\Date as DateFieldType; +use Magento\Elasticsearch\Model\Adapter\Document\Builder; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Framework\App\ObjectManager; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; +use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; +use Magento\Elasticsearch\Model\Adapter\FieldType\Date as DateFieldType; +use Magento\Elasticsearch\Model\ResourceModel\Index; +use Magento\Store\Model\StoreManagerInterface; /** * Don't use this product data mapper class. @@ -103,8 +102,8 @@ class ProductDataMapper implements DataMapperInterface * @param FieldMapperInterface $fieldMapper * @param StoreManagerInterface $storeManager * @param DateFieldType $dateFieldType - * @param AttributeProvider|null $attributeAdapterProvider - * @param ResolverInterface|null $fieldNameResolver + * @param AttributeProvider $attributeAdapterProvider + * @param ResolverInterface $fieldNameResolver */ public function __construct( Builder $builder, @@ -113,8 +112,8 @@ public function __construct( FieldMapperInterface $fieldMapper, StoreManagerInterface $storeManager, DateFieldType $dateFieldType, - AttributeProvider $attributeAdapterProvider = null, - ResolverInterface $fieldNameResolver = null + AttributeProvider $attributeAdapterProvider, + ResolverInterface $fieldNameResolver ) { $this->builder = $builder; $this->attributeContainer = $attributeContainer; @@ -122,10 +121,8 @@ public function __construct( $this->fieldMapper = $fieldMapper; $this->storeManager = $storeManager; $this->dateFieldType = $dateFieldType; - $this->attributeAdapterProvider = $attributeAdapterProvider ?: ObjectManager::getInstance() - ->get(AttributeProvider::class); - $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() - ->get(ResolverInterface::class); + $this->attributeAdapterProvider = $attributeAdapterProvider; + $this->fieldNameResolver = $fieldNameResolver; $this->mediaGalleryRoles = [ self::MEDIA_ROLE_IMAGE, diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/ProductFieldMapper.php b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/ProductFieldMapper.php index 5aea87e5e6ae1..86bfc8ea35b2b 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/ProductFieldMapper.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/ProductFieldMapper.php @@ -3,22 +3,23 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper; +use Magento\Customer\Model\Session as CustomerSession; use Magento\Eav\Model\Config; +use Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldType; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; -use Magento\Framework\App\ObjectManager; -use Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldType; use Magento\Framework\Registry; use Magento\Store\Model\StoreManagerInterface as StoreManager; -use \Magento\Customer\Model\Session as CustomerSession; /** - * Class ProductFieldMapper + * Elasticsearch5 Product Field Mapper Adapter + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) */ class ProductFieldMapper implements FieldMapperInterface { @@ -73,9 +74,9 @@ class ProductFieldMapper implements FieldMapperInterface * @param CustomerSession $customerSession * @param StoreManager $storeManager * @param Registry $coreRegistry - * @param ResolverInterface|null $fieldNameResolver - * @param AttributeProvider|null $attributeAdapterProvider - * @param FieldProviderInterface|null $fieldProvider + * @param ResolverInterface $fieldNameResolver + * @param AttributeProvider $attributeAdapterProvider + * @param FieldProviderInterface $fieldProvider */ public function __construct( Config $eavConfig, @@ -83,21 +84,18 @@ public function __construct( CustomerSession $customerSession, StoreManager $storeManager, Registry $coreRegistry, - ResolverInterface $fieldNameResolver = null, - AttributeProvider $attributeAdapterProvider = null, - FieldProviderInterface $fieldProvider = null + ResolverInterface $fieldNameResolver, + AttributeProvider $attributeAdapterProvider, + FieldProviderInterface $fieldProvider ) { $this->eavConfig = $eavConfig; $this->fieldType = $fieldType; $this->customerSession = $customerSession; $this->storeManager = $storeManager; $this->coreRegistry = $coreRegistry; - $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() - ->get(ResolverInterface::class); - $this->attributeAdapterProvider = $attributeAdapterProvider ?: ObjectManager::getInstance() - ->get(AttributeProvider::class); - $this->fieldProvider = $fieldProvider ?: ObjectManager::getInstance() - ->get(FieldProviderInterface::class); + $this->fieldNameResolver = $fieldNameResolver; + $this->attributeAdapterProvider = $attributeAdapterProvider; + $this->fieldProvider = $fieldProvider; } /** diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Adapter.php b/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Adapter.php index 0ae347d5791ad..3b40db4787767 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Adapter.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Adapter.php @@ -5,13 +5,13 @@ */ namespace Magento\Elasticsearch\Elasticsearch5\SearchAdapter; -use Magento\Framework\App\ObjectManager; +use Magento\Elasticsearch\SearchAdapter\Aggregation\Builder as AggregationBuilder; +use Magento\Elasticsearch\SearchAdapter\ConnectionManager; +use Magento\Elasticsearch\SearchAdapter\QueryContainerFactory; +use Magento\Elasticsearch\SearchAdapter\ResponseFactory; use Magento\Framework\Search\AdapterInterface; use Magento\Framework\Search\RequestInterface; use Magento\Framework\Search\Response\QueryResponse; -use Magento\Elasticsearch\SearchAdapter\Aggregation\Builder as AggregationBuilder; -use Magento\Elasticsearch\SearchAdapter\ConnectionManager; -use \Magento\Elasticsearch\SearchAdapter\ResponseFactory; use Psr\Log\LoggerInterface; /** @@ -44,7 +44,7 @@ class Adapter implements AdapterInterface protected $aggregationBuilder; /** - * @var \Magento\Elasticsearch\SearchAdapter\QueryContainerFactory + * @var QueryContainerFactory */ private $queryContainerFactory; @@ -54,19 +54,15 @@ class Adapter implements AdapterInterface * @var array */ private static $emptyRawResponse = [ - "hits" => - [ - "hits" => [] - ], - "aggregations" => - [ - "price_bucket" => [], - "category_bucket" => - [ - "buckets" => [] - - ] + 'hits' => [ + 'hits' => [] + ], + 'aggregations' => [ + 'price_bucket' => [], + 'category_bucket' => [ + 'buckets' => [] ] + ] ]; /** @@ -79,7 +75,7 @@ class Adapter implements AdapterInterface * @param Mapper $mapper * @param ResponseFactory $responseFactory * @param AggregationBuilder $aggregationBuilder - * @param \Magento\Elasticsearch\SearchAdapter\QueryContainerFactory $queryContainerFactory + * @param QueryContainerFactory $queryContainerFactory * @param LoggerInterface $logger */ public function __construct( @@ -87,16 +83,15 @@ public function __construct( Mapper $mapper, ResponseFactory $responseFactory, AggregationBuilder $aggregationBuilder, - \Magento\Elasticsearch\SearchAdapter\QueryContainerFactory $queryContainerFactory, - LoggerInterface $logger = null + QueryContainerFactory $queryContainerFactory, + LoggerInterface $logger ) { $this->connectionManager = $connectionManager; $this->mapper = $mapper; $this->responseFactory = $responseFactory; $this->aggregationBuilder = $aggregationBuilder; $this->queryContainerFactory = $queryContainerFactory; - $this->logger = $logger ?: ObjectManager::getInstance() - ->get(LoggerInterface::class); + $this->logger = $logger; } /** diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Query/Builder.php b/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Query/Builder.php index 75c675663f03f..b75621191dae7 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Query/Builder.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Query/Builder.php @@ -56,17 +56,20 @@ class Builder * @param SearchIndexNameResolver $searchIndexNameResolver * @param AggregationBuilder $aggregationBuilder * @param ScopeResolverInterface $scopeResolver + * @param Sort|null $sortBuilder */ public function __construct( Config $clientConfig, SearchIndexNameResolver $searchIndexNameResolver, AggregationBuilder $aggregationBuilder, - ScopeResolverInterface $scopeResolver + ScopeResolverInterface $scopeResolver, + ?Sort $sortBuilder = null ) { $this->clientConfig = $clientConfig; $this->searchIndexNameResolver = $searchIndexNameResolver; $this->aggregationBuilder = $aggregationBuilder; $this->scopeResolver = $scopeResolver; + $this->sortBuilder = $sortBuilder ?: ObjectManager::getInstance()->get(Sort::class); } /** @@ -88,7 +91,7 @@ public function initQuery(RequestInterface $request) 'from' => $request->getFrom(), 'size' => $request->getSize(), 'stored_fields' => ['_id', '_score'], - 'sort' => $this->getSortBuilder()->getSort($request), + 'sort' => $this->sortBuilder->getSort($request), 'query' => [], ], ]; @@ -109,17 +112,4 @@ public function initAggregations( ) { return $this->aggregationBuilder->build($request, $searchQuery); } - - /** - * Get sort builder instance. - * - * @return Sort - */ - private function getSortBuilder() - { - if (null === $this->sortBuilder) { - $this->sortBuilder = ObjectManager::getInstance()->get(Sort::class); - } - return $this->sortBuilder; - } } diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php index 0e130c24e79d3..8e9de47aa7951 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php @@ -3,14 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\Model\Adapter\BatchDataMapper; -use Magento\Elasticsearch\Model\ResourceModel\Index; use Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Framework\App\ObjectManager; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; +use Magento\Elasticsearch\Model\ResourceModel\Index; /** * Provide data mapping for categories fields @@ -34,19 +34,17 @@ class CategoryFieldsProvider implements AdditionalFieldsProviderInterface /** * @param Index $resourceIndex - * @param AttributeProvider|null $attributeAdapterProvider - * @param ResolverInterface|null $fieldNameResolver + * @param AttributeProvider $attributeAdapterProvider + * @param ResolverInterface $fieldNameResolver */ public function __construct( Index $resourceIndex, - AttributeProvider $attributeAdapterProvider = null, - ResolverInterface $fieldNameResolver = null + AttributeProvider $attributeAdapterProvider, + ResolverInterface $fieldNameResolver ) { $this->resourceIndex = $resourceIndex; - $this->attributeAdapterProvider = $attributeAdapterProvider ?: ObjectManager::getInstance() - ->get(AttributeProvider::class); - $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() - ->get(ResolverInterface::class); + $this->attributeAdapterProvider = $attributeAdapterProvider; + $this->fieldNameResolver = $fieldNameResolver; } /** diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php index 56c84593256be..33e0993daba8d 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php @@ -3,16 +3,16 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\Model\Adapter\BatchDataMapper; -use Magento\Elasticsearch\Model\ResourceModel\Index; -use Magento\Store\Model\StoreManagerInterface; use Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface; use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\DataProvider; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Framework\App\ObjectManager; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; +use Magento\Elasticsearch\Model\ResourceModel\Index; +use Magento\Store\Model\StoreManagerInterface; /** * Provide data mapping for price fields @@ -48,23 +48,21 @@ class PriceFieldsProvider implements AdditionalFieldsProviderInterface * @param Index $resourceIndex * @param DataProvider $dataProvider * @param StoreManagerInterface $storeManager - * @param AttributeProvider|null $attributeAdapterProvider - * @param ResolverInterface|null $fieldNameResolver + * @param AttributeProvider $attributeAdapterProvider + * @param ResolverInterface $fieldNameResolver */ public function __construct( Index $resourceIndex, DataProvider $dataProvider, StoreManagerInterface $storeManager, - AttributeProvider $attributeAdapterProvider = null, - ResolverInterface $fieldNameResolver = null + AttributeProvider $attributeAdapterProvider, + ResolverInterface $fieldNameResolver ) { $this->resourceIndex = $resourceIndex; $this->dataProvider = $dataProvider; $this->storeManager = $storeManager; - $this->attributeAdapterProvider = $attributeAdapterProvider ?: ObjectManager::getInstance() - ->get(AttributeProvider::class); - $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() - ->get(ResolverInterface::class); + $this->attributeAdapterProvider = $attributeAdapterProvider; + $this->fieldNameResolver = $fieldNameResolver; } /** @@ -73,7 +71,7 @@ public function __construct( public function getFields(array $productIds, $storeId) { $websiteId = $this->storeManager->getStore($storeId)->getWebsiteId(); - + $priceData = $this->dataProvider->getSearchableAttribute('price') ? $this->resourceIndex->getPriceIndexData($productIds, $storeId) : []; diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php b/app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php index fa193d86c03c7..d2ffbfdc34756 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php @@ -3,10 +3,16 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\Model\Adapter; -use Magento\Framework\App\ObjectManager; +use Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface; +use Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver; +use Magento\Elasticsearch\Model\Config; +use Magento\Elasticsearch\SearchAdapter\ConnectionManager; +use Magento\Framework\Exception\LocalizedException; +use Psr\Log\LoggerInterface; /** * Elasticsearch adapter @@ -37,18 +43,13 @@ class Elasticsearch */ protected $documentDataMapper; - /** - * @var \Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver - */ - protected $indexNameResolver; - /** * @var FieldMapperInterface */ protected $fieldMapper; /** - * @var \Magento\Elasticsearch\Model\Config + * @var Config */ protected $clientConfig; @@ -58,15 +59,20 @@ class Elasticsearch protected $client; /** - * @var \Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface + * @var BuilderInterface */ protected $indexBuilder; /** - * @var \Psr\Log\LoggerInterface + * @var LoggerInterface */ protected $logger; + /** + * @var IndexNameResolver + */ + protected $indexNameResolver; + /** * @var array */ @@ -80,27 +86,27 @@ class Elasticsearch /** * Constructor for Elasticsearch adapter. * - * @param \Magento\Elasticsearch\SearchAdapter\ConnectionManager $connectionManager + * @param ConnectionManager $connectionManager * @param DataMapperInterface $documentDataMapper * @param FieldMapperInterface $fieldMapper - * @param \Magento\Elasticsearch\Model\Config $clientConfig - * @param \Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface $indexBuilder - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver $indexNameResolver - * @param array $options + * @param Config $clientConfig + * @param BuilderInterface $indexBuilder + * @param LoggerInterface $logger + * @param IndexNameResolver $indexNameResolver * @param BatchDataMapperInterface $batchDocumentDataMapper - * @throws \Magento\Framework\Exception\LocalizedException + * @param array $options + * @throws LocalizedException */ public function __construct( - \Magento\Elasticsearch\SearchAdapter\ConnectionManager $connectionManager, + ConnectionManager $connectionManager, DataMapperInterface $documentDataMapper, FieldMapperInterface $fieldMapper, - \Magento\Elasticsearch\Model\Config $clientConfig, - \Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface $indexBuilder, - \Psr\Log\LoggerInterface $logger, - \Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver $indexNameResolver, - $options = [], - BatchDataMapperInterface $batchDocumentDataMapper = null + Config $clientConfig, + BuilderInterface $indexBuilder, + LoggerInterface $logger, + IndexNameResolver $indexNameResolver, + BatchDataMapperInterface $batchDocumentDataMapper, + $options = [] ) { $this->connectionManager = $connectionManager; $this->documentDataMapper = $documentDataMapper; @@ -109,14 +115,13 @@ public function __construct( $this->indexBuilder = $indexBuilder; $this->logger = $logger; $this->indexNameResolver = $indexNameResolver; - $this->batchDocumentDataMapper = $batchDocumentDataMapper ?: - ObjectManager::getInstance()->get(BatchDataMapperInterface::class); + $this->batchDocumentDataMapper = $batchDocumentDataMapper; try { $this->client = $this->connectionManager->getConnection($options); } catch (\Exception $e) { $this->logger->critical($e); - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('The search failed because of a search engine misconfiguration.') ); } @@ -126,14 +131,14 @@ public function __construct( * Retrieve Elasticsearch server status * * @return bool - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function ping() { try { $response = $this->client->ping(); } catch (\Exception $e) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('Could not ping search engine: %1', $e->getMessage()) ); } diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php index 76bc7a15e47a7..16131a281c231 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php @@ -8,18 +8,17 @@ namespace Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider; use Magento\Catalog\Api\CategoryListInterface; +use Magento\Catalog\Model\ResourceModel\Category\Collection; use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface - as FieldTypeConverterInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface as IndexTypeConverterInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface as FieldNameResolver; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface + as FieldTypeConverterInterface; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface; use Magento\Framework\Api\SearchCriteriaBuilder; -use Magento\Catalog\Model\ResourceModel\Category\Collection; -use Magento\Framework\App\ObjectManager; /** * Provide dynamic fields for product. @@ -83,7 +82,7 @@ class DynamicField implements FieldProviderInterface * @param CategoryListInterface $categoryList * @param FieldNameResolver $fieldNameResolver * @param AttributeProvider $attributeAdapterProvider - * @param Collection|null $categoryCollection + * @param Collection $categoryCollection */ public function __construct( FieldTypeConverterInterface $fieldTypeConverter, @@ -93,7 +92,7 @@ public function __construct( CategoryListInterface $categoryList, FieldNameResolver $fieldNameResolver, AttributeProvider $attributeAdapterProvider, - Collection $categoryCollection = null + Collection $categoryCollection ) { $this->groupRepository = $groupRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; @@ -102,8 +101,7 @@ public function __construct( $this->categoryList = $categoryList; $this->fieldNameResolver = $fieldNameResolver; $this->attributeAdapterProvider = $attributeAdapterProvider; - $this->categoryCollection = $categoryCollection ?: - ObjectManager::getInstance()->get(Collection::class); + $this->categoryCollection = $categoryCollection; } /** diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/CategoryName.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/CategoryName.php index 5824aca6cdd54..03240034b959d 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/CategoryName.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/CategoryName.php @@ -8,10 +8,9 @@ namespace Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\Resolver; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; use Magento\Framework\Registry; use Magento\Store\Model\StoreManagerInterface as StoreManager; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; -use Magento\Framework\App\ObjectManager; /** * Resolver field name for Category name attribute. @@ -33,13 +32,11 @@ class CategoryName implements ResolverInterface * @param Registry $coreRegistry */ public function __construct( - StoreManager $storeManager = null, - Registry $coreRegistry = null + StoreManager $storeManager, + Registry $coreRegistry ) { - $this->storeManager = $storeManager ?: ObjectManager::getInstance() - ->get(StoreManager::class); - $this->coreRegistry = $coreRegistry ?: ObjectManager::getInstance() - ->get(Registry::class); + $this->storeManager = $storeManager; + $this->coreRegistry = $coreRegistry; } /** diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Position.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Position.php index 044d5d8da9a6c..9f91e82275434 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Position.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Position.php @@ -8,10 +8,9 @@ namespace Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\Resolver; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; use Magento\Framework\Registry; use Magento\Store\Model\StoreManagerInterface as StoreManager; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; -use Magento\Framework\App\ObjectManager; /** * Resolver field name for position attribute. @@ -33,13 +32,11 @@ class Position implements ResolverInterface * @param Registry $coreRegistry */ public function __construct( - StoreManager $storeManager = null, - Registry $coreRegistry = null + StoreManager $storeManager, + Registry $coreRegistry ) { - $this->storeManager = $storeManager ?: ObjectManager::getInstance() - ->get(StoreManager::class); - $this->coreRegistry = $coreRegistry ?: ObjectManager::getInstance() - ->get(Registry::class); + $this->storeManager = $storeManager; + $this->coreRegistry = $coreRegistry; } /** diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Price.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Price.php index 12e53ca2bd714..b55707ea7009f 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Price.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldName/Resolver/Price.php @@ -7,14 +7,14 @@ namespace Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\Resolver; -use Magento\Framework\App\ObjectManager; use Magento\Customer\Model\Session as CustomerSession; -use Magento\Store\Model\StoreManagerInterface as StoreManager; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface; +use Magento\Store\Model\StoreManagerInterface as StoreManager; /** * Resolver field name for price attribute. + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) */ class Price implements ResolverInterface { @@ -33,13 +33,11 @@ class Price implements ResolverInterface * @param StoreManager $storeManager */ public function __construct( - CustomerSession $customerSession = null, - StoreManager $storeManager = null + CustomerSession $customerSession, + StoreManager $storeManager ) { - $this->storeManager = $storeManager ?: ObjectManager::getInstance() - ->get(StoreManager::class); - $this->customerSession = $customerSession ?: ObjectManager::getInstance() - ->get(CustomerSession::class); + $this->storeManager = $storeManager; + $this->customerSession = $customerSession; } /** diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/StaticField.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/StaticField.php index 7a5d6fcdcc1b1..d20c898c6c0e2 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/StaticField.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/StaticField.php @@ -7,19 +7,18 @@ namespace Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider; -use Magento\Framework\App\ObjectManager; -use Magento\Eav\Model\Config; use Magento\Catalog\Api\Data\ProductAttributeInterface; +use Magento\Eav\Model\Config; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface - as FieldTypeConverterInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface as IndexTypeConverterInterface; -use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface - as FieldTypeResolver; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ResolverInterface as FieldIndexResolver; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface + as FieldTypeConverterInterface; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface + as FieldTypeResolver; +use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; /** @@ -74,7 +73,7 @@ class StaticField implements FieldProviderInterface * @param FieldTypeResolver $fieldTypeResolver * @param FieldIndexResolver $fieldIndexResolver * @param AttributeProvider $attributeAdapterProvider - * @param FieldName\ResolverInterface|null $fieldNameResolver + * @param FieldName\ResolverInterface $fieldNameResolver * @param array $excludedAttributes */ public function __construct( @@ -84,7 +83,7 @@ public function __construct( FieldTypeResolver $fieldTypeResolver, FieldIndexResolver $fieldIndexResolver, AttributeProvider $attributeAdapterProvider, - FieldName\ResolverInterface $fieldNameResolver = null, + FieldName\ResolverInterface $fieldNameResolver, array $excludedAttributes = [] ) { $this->eavConfig = $eavConfig; @@ -93,8 +92,7 @@ public function __construct( $this->fieldTypeResolver = $fieldTypeResolver; $this->fieldIndexResolver = $fieldIndexResolver; $this->attributeAdapterProvider = $attributeAdapterProvider; - $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() - ->get(FieldName\ResolverInterface::class); + $this->fieldNameResolver = $fieldNameResolver; $this->excludedAttributes = $excludedAttributes; } diff --git a/app/code/Magento/Elasticsearch/Model/DataProvider/Suggestions.php b/app/code/Magento/Elasticsearch/Model/DataProvider/Suggestions.php index c4fab39dfde61..45669ba345183 100644 --- a/app/code/Magento/Elasticsearch/Model/DataProvider/Suggestions.php +++ b/app/code/Magento/Elasticsearch/Model/DataProvider/Suggestions.php @@ -3,37 +3,39 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Elasticsearch\Model\DataProvider; -use Magento\Store\Model\ScopeInterface; -use Magento\Search\Model\QueryInterface; use Magento\AdvancedSearch\Model\SuggestedQueriesInterface; use Magento\Elasticsearch\Model\Config; use Magento\Elasticsearch\SearchAdapter\ConnectionManager; -use Magento\Search\Model\QueryResultFactory; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Search\Model\QueryInterface; +use Magento\Search\Model\QueryResultFactory; +use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface as StoreManager; /** - * Class Suggestions + * Elasticsearch Suggestions Data Provider */ class Suggestions implements SuggestedQueriesInterface { /** - * @deprecated + * @deprecated this constant is no longer used * @see SuggestedQueriesInterface::SEARCH_SUGGESTION_COUNT */ const CONFIG_SUGGESTION_COUNT = 'catalog/search/search_suggestion_count'; /** - * @deprecated + * @deprecated this constant is no longer used * @see SuggestedQueriesInterface::SEARCH_SUGGESTION_COUNT_RESULTS_ENABLED */ const CONFIG_SUGGESTION_COUNT_RESULTS_ENABLED = 'catalog/search/search_suggestion_count_results_enabled'; /** - * @deprecated + * @deprecated this constant is no longer used * @see SuggestedQueriesInterface::SEARCH_SUGGESTION_ENABLED */ const CONFIG_SUGGESTION_ENABLED = 'catalog/search/search_suggestion_enabled'; @@ -126,7 +128,7 @@ public function getItems(QueryInterface $query) public function isResultsCountEnabled() { return $this->scopeConfig->isSetFlag( - self::CONFIG_SUGGESTION_COUNT_RESULTS_ENABLED, + self::SEARCH_SUGGESTION_COUNT_RESULTS_ENABLED, ScopeInterface::SCOPE_STORE ); } @@ -203,7 +205,7 @@ private function fetchQuery(array $query) private function getSearchSuggestionsCount() { return (int)$this->scopeConfig->getValue( - self::CONFIG_SUGGESTION_COUNT, + self::SEARCH_SUGGESTION_COUNT, ScopeInterface::SCOPE_STORE ); } @@ -216,7 +218,7 @@ private function getSearchSuggestionsCount() private function isSuggestionsAllowed() { $isSuggestionsEnabled = $this->scopeConfig->isSetFlag( - self::CONFIG_SUGGESTION_ENABLED, + self::SEARCH_SUGGESTION_ENABLED, ScopeInterface::SCOPE_STORE ); $isEnabled = $this->config->isElasticsearchEnabled(); diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Adapter.php b/app/code/Magento/Elasticsearch/SearchAdapter/Adapter.php index 6f9ef552351fd..08f57a3c60ac0 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Adapter.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Adapter.php @@ -3,13 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Elasticsearch\SearchAdapter; -use Magento\Framework\App\ObjectManager; +use Magento\Elasticsearch\SearchAdapter\Aggregation\Builder as AggregationBuilder; use Magento\Framework\Search\AdapterInterface; use Magento\Framework\Search\RequestInterface; -use Magento\Framework\Search\Response\QueryResponse; -use Magento\Elasticsearch\SearchAdapter\Aggregation\Builder as AggregationBuilder; /** * Elasticsearch Search Adapter @@ -57,14 +57,13 @@ public function __construct( Mapper $mapper, ResponseFactory $responseFactory, AggregationBuilder $aggregationBuilder, - QueryContainerFactory $queryContainerFactory = null + QueryContainerFactory $queryContainerFactory ) { $this->connectionManager = $connectionManager; $this->mapper = $mapper; $this->responseFactory = $responseFactory; $this->aggregationBuilder = $aggregationBuilder; - $this->queryContainerFactory = $queryContainerFactory - ?: ObjectManager::getInstance()->get(QueryContainerFactory::class); + $this->queryContainerFactory = $queryContainerFactory; } /** diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder.php b/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder.php index 1e9b60da74a5b..3a9e3ca036597 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder.php @@ -3,15 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\SearchAdapter\Aggregation; +use Magento\Elasticsearch\SearchAdapter\Aggregation\Builder\BucketBuilderInterface; use Magento\Elasticsearch\SearchAdapter\QueryContainer; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Search\RequestInterface; use Magento\Framework\Search\Dynamic\DataProviderInterface; -use Magento\Elasticsearch\SearchAdapter\Aggregation\Builder\BucketBuilderInterface; +use Magento\Framework\Search\RequestInterface; +/** + * Elasticsearch aggregation builder + */ class Builder { /** @@ -32,32 +35,31 @@ class Builder /** * @var QueryContainer */ - private $query = null; + private $query; /** * @param DataProviderInterface[] $dataProviderContainer * @param BucketBuilderInterface[] $aggregationContainer - * @param DataProviderFactory|null $dataProviderFactory + * @param DataProviderFactory $dataProviderFactory */ public function __construct( array $dataProviderContainer, array $aggregationContainer, - DataProviderFactory $dataProviderFactory = null + DataProviderFactory $dataProviderFactory ) { $this->dataProviderContainer = array_map( - function (DataProviderInterface $dataProvider) { + static function (DataProviderInterface $dataProvider) { return $dataProvider; }, $dataProviderContainer ); $this->aggregationContainer = array_map( - function (BucketBuilderInterface $bucketBuilder) { + static function (BucketBuilderInterface $bucketBuilder) { return $bucketBuilder; }, $aggregationContainer ); - $this->dataProviderFactory = $dataProviderFactory - ?: ObjectManager::getInstance()->get(DataProviderFactory::class); + $this->dataProviderFactory = $dataProviderFactory; } /** diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder/Term.php b/app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder/Term.php index d88c7e53d813a..a4f9e7bcea71d 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder/Term.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder/Term.php @@ -3,15 +3,16 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Elasticsearch\SearchAdapter\Filter\Builder; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Search\Request\Filter\Term as TermFilterRequest; -use Magento\Framework\Search\Request\FilterInterface as RequestFilterInterface; -use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface as FieldTypeConverterInterface; +use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; +use Magento\Framework\Search\Request\Filter\Term as TermFilterRequest; +use Magento\Framework\Search\Request\FilterInterface as RequestFilterInterface; /** * Term filter builder @@ -41,12 +42,11 @@ class Term implements FilterInterface */ public function __construct( FieldMapperInterface $fieldMapper, - AttributeProvider $attributeAdapterProvider = null, + AttributeProvider $attributeAdapterProvider, array $integerTypeAttributes = [] ) { $this->fieldMapper = $fieldMapper; - $this->attributeAdapterProvider = $attributeAdapterProvider - ?? ObjectManager::getInstance()->get(AttributeProvider::class); + $this->attributeAdapterProvider = $attributeAdapterProvider; $this->integerTypeAttributes = array_merge($this->integerTypeAttributes, $integerTypeAttributes); } diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder.php index 0bea8683692f2..778e73e6518e8 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder.php @@ -3,11 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Elasticsearch\SearchAdapter\Query; +use Magento\Elasticsearch\Model\Config; +use Magento\Elasticsearch\SearchAdapter\Query\Builder\Aggregation as AggregationBuilder; use Magento\Elasticsearch\SearchAdapter\Query\Builder\Sort; -use Magento\Framework\App\ObjectManager; +use Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver; +use Magento\Framework\App\ScopeResolverInterface; use Magento\Framework\Search\RequestInterface; use Magento\Elasticsearch\Elasticsearch5\SearchAdapter\Query\Builder as Elasticsearch5Builder; @@ -24,6 +28,24 @@ class Builder extends Elasticsearch5Builder */ private $sortBuilder; + /** + * @param Config $clientConfig + * @param SearchIndexNameResolver $searchIndexNameResolver + * @param AggregationBuilder $aggregationBuilder + * @param ScopeResolverInterface $scopeResolver + * @param Sort $sortBuilder + */ + public function __construct( + Config $clientConfig, + SearchIndexNameResolver $searchIndexNameResolver, + AggregationBuilder $aggregationBuilder, + ScopeResolverInterface $scopeResolver, + Sort $sortBuilder + ) { + parent::__construct($clientConfig, $searchIndexNameResolver, $aggregationBuilder, $scopeResolver); + $this->sortBuilder = $sortBuilder; + } + /** * Set initial settings for query. * @@ -42,23 +64,10 @@ public function initQuery(RequestInterface $request) 'from' => $request->getFrom(), 'size' => $request->getSize(), 'fields' => ['_id', '_score'], - 'sort' => $this->getSortBuilder()->getSort($request), + 'sort' => $this->sortBuilder->getSort($request), 'query' => [], ], ]; return $searchQuery; } - - /** - * Get sort builder instance. - * - * @return Sort - */ - private function getSortBuilder() - { - if (null === $this->sortBuilder) { - $this->sortBuilder = ObjectManager::getInstance()->get(Sort::class); - } - return $this->sortBuilder; - } } diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php index 8a44b58d35fb8..0afbbfd849e16 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php @@ -3,17 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Elasticsearch\SearchAdapter\Query\Builder; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface as TypeResolver; +use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; use Magento\Elasticsearch\Model\Config; use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface; use Magento\Framework\Search\Request\Query\BoolExpression; use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface; -use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; -use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface; /** * Builder for match query. @@ -59,28 +60,25 @@ class Match implements QueryInterface /** * @param FieldMapperInterface $fieldMapper * @param PreprocessorInterface[] $preprocessorContainer - * @param AttributeProvider|null $attributeProvider - * @param TypeResolver|null $fieldTypeResolver - * @param ValueTransformerPool|null $valueTransformerPool - * @param Config|null $config + * @param AttributeProvider $attributeProvider + * @param TypeResolver $fieldTypeResolver + * @param ValueTransformerPool $valueTransformerPool + * @param Config $config */ public function __construct( FieldMapperInterface $fieldMapper, array $preprocessorContainer, - AttributeProvider $attributeProvider = null, - TypeResolver $fieldTypeResolver = null, - ValueTransformerPool $valueTransformerPool = null, - Config $config = null + AttributeProvider $attributeProvider, + TypeResolver $fieldTypeResolver, + ValueTransformerPool $valueTransformerPool, + Config $config ) { $this->fieldMapper = $fieldMapper; $this->preprocessorContainer = $preprocessorContainer; - $this->attributeProvider = $attributeProvider ?? ObjectManager::getInstance() - ->get(AttributeProvider::class); - $this->fieldTypeResolver = $fieldTypeResolver ?? ObjectManager::getInstance() - ->get(TypeResolver::class); - $this->valueTransformerPool = $valueTransformerPool ?? ObjectManager::getInstance() - ->get(ValueTransformerPool::class); - $this->config = $config ?? ObjectManager::getInstance()->get(Config::class); + $this->attributeProvider = $attributeProvider; + $this->fieldTypeResolver = $fieldTypeResolver; + $this->valueTransformerPool = $valueTransformerPool; + $this->config = $config; } /** diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Preprocessor/Stopwords.php b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Preprocessor/Stopwords.php index d8d1a071611c1..e21baa231b14b 100644 --- a/app/code/Magento/Elasticsearch/SearchAdapter/Query/Preprocessor/Stopwords.php +++ b/app/code/Magento/Elasticsearch/SearchAdapter/Query/Preprocessor/Stopwords.php @@ -5,12 +5,20 @@ */ namespace Magento\Elasticsearch\SearchAdapter\Query\Preprocessor; -use Magento\Framework\Filesystem\Directory\ReadFactory; use Magento\Elasticsearch\Model\Adapter\Index\Config\EsConfigInterface; -use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface; +use Magento\Framework\App\Cache\Type\Config; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Filesystem\Directory\ReadFactory; +use Magento\Framework\Locale\Resolver; use Magento\Framework\Module\Dir; +use Magento\Framework\Module\Dir\Reader; +use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Store\Model\StoreManagerInterface; /** + * Elasticsearch stopwords preprocessor + * * @api * @since 100.1.0 */ @@ -27,13 +35,13 @@ class Stopwords implements PreprocessorInterface const STOPWORDS_FILE_MODIFICATION_TIME_GAP = 900; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface * @since 100.1.0 */ protected $storeManager; /** - * @var \Magento\Framework\Locale\Resolver + * @var Resolver * @since 100.1.0 */ protected $localeResolver; @@ -45,7 +53,7 @@ class Stopwords implements PreprocessorInterface protected $readFactory; /** - * @var \Magento\Framework\App\Cache\Type\Config + * @var Config * @since 100.1.0 */ protected $configCache; @@ -57,7 +65,7 @@ class Stopwords implements PreprocessorInterface protected $esConfig; /** - * @var \Magento\Framework\Module\Dir\Reader + * @var Reader * @since 100.1.0 */ protected $moduleDirReader; @@ -73,31 +81,33 @@ class Stopwords implements PreprocessorInterface private $stopwordsDirectory; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var SerializerInterface */ private $serializer; /** * Initialize dependencies. * - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\Locale\Resolver $localeResolver + * @param StoreManagerInterface $storeManager + * @param Resolver $localeResolver * @param ReadFactory $readFactory - * @param \Magento\Framework\App\Cache\Type\Config $configCache + * @param Config $configCache * @param EsConfigInterface $esConfig - * @param \Magento\Framework\Module\Dir\Reader $moduleDirReader + * @param Reader $moduleDirReader * @param string $stopwordsModule * @param string $stopwordsDirectory + * @param SerializerInterface|null $serializer */ public function __construct( - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Locale\Resolver $localeResolver, + StoreManagerInterface $storeManager, + Resolver $localeResolver, ReadFactory $readFactory, - \Magento\Framework\App\Cache\Type\Config $configCache, + Config $configCache, EsConfigInterface $esConfig, - \Magento\Framework\Module\Dir\Reader $moduleDirReader, + Reader $moduleDirReader, $stopwordsModule = '', - $stopwordsDirectory = '' + $stopwordsDirectory = '', + ?SerializerInterface $serializer = null ) { $this->storeManager = $storeManager; $this->localeResolver = $localeResolver; @@ -107,10 +117,11 @@ public function __construct( $this->moduleDirReader = $moduleDirReader; $this->stopwordsModule = $stopwordsModule; $this->stopwordsDirectory = $stopwordsDirectory; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** - * {@inheritdoc} + * @inheritDoc * @since 100.1.0 */ public function process($query) @@ -136,11 +147,11 @@ protected function getStopwordsList() $fileStats = $source->stat($filename); if (((time() - $fileStats['mtime']) > self::STOPWORDS_FILE_MODIFICATION_TIME_GAP) && ($cachedValue = $this->configCache->load(self::CACHE_ID))) { - $stopwords = $this->getSerializer()->unserialize($cachedValue); + $stopwords = $this->serializer->unserialize($cachedValue); } else { $fileContent = $source->readFile($filename); $stopwords = explode("\n", $fileContent); - $this->configCache->save($this->getSerializer()->serialize($stopwords), self::CACHE_ID); + $this->configCache->save($this->serializer->serialize($stopwords), self::CACHE_ID); } return $stopwords; } @@ -160,19 +171,4 @@ protected function getStopwordsFile() $stopwordsFile = isset($stopwordsInfo[$locale]) ? $stopwordsInfo[$locale] : $stopwordsInfo['default']; return $stopwordsFile; } - - /** - * Get serializer - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated 100.2.0 - */ - private function getSerializer() - { - if (null === $this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - return $this->serializer; - } } From 08319582702be82b594225db5b66b873a87d18e7 Mon Sep 17 00:00:00 2001 From: Sathish Date: Tue, 25 Feb 2020 23:59:26 +0530 Subject: [PATCH 10/27] Fix #26992 Add new rating is active checkbox alignment issue --- .../backend/Magento_Review/web/css/source/_module.less | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less index 08606402f7a0e..9eae708819a0b 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less @@ -77,3 +77,11 @@ } } } + +.review-rating-edit { + .admin__field-control.control { + input[type='checkbox'] { + margin: 8px 0 0 0; + } + } +} From 744b0f72ffcd5048c241381861cf5500e82f259a Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 26 Feb 2020 14:09:17 +0200 Subject: [PATCH 11/27] ObjectManager cleanup - Remove usage from AdminNotification module Fix small issues after code review --- app/code/Magento/AdminNotification/Block/System/Messages.php | 4 ++-- .../Controller/Adminhtml/Notification/MarkAsRead.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/AdminNotification/Block/System/Messages.php b/app/code/Magento/AdminNotification/Block/System/Messages.php index 2fbd918c2d824..318b8f8384e2e 100644 --- a/app/code/Magento/AdminNotification/Block/System/Messages.php +++ b/app/code/Magento/AdminNotification/Block/System/Messages.php @@ -74,8 +74,8 @@ public function getLastCritical() { $items = array_values($this->_messages->getItems()); - if (isset($items[0]) && (int)$items[0]->getSeverity() === MessageInterface::SEVERITY_CRITICAL) { - return $items[0]; + if (!empty($items) && current($items)->getSeverity() === MessageInterface::SEVERITY_CRITICAL) { + return current($items); } return null; } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php index edc6c702abe26..6dd40b56e0a24 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php @@ -9,6 +9,7 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\NotificationService; use Magento\Backend\App\Action; +use Magento\Framework\Exception\LocalizedException; class MarkAsRead extends Notification { @@ -40,7 +41,7 @@ public function execute() try { $this->notificationService->markAsRead($notificationId); $this->messageManager->addSuccessMessage(__('The message has been marked as Read.')); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addExceptionMessage( From 0fd6fd364a3816fbcd9c642bc3368017694e2883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Wed, 26 Feb 2020 23:10:51 +0100 Subject: [PATCH 12/27] Fix #20309 - fix url rewrite check with query params, add integration test cases --- .../Magento/UrlRewrite/Controller/Router.php | 27 +++++++++++++++---- .../Test/Unit/Controller/RouterTest.php | 14 ++++++++++ .../UrlRewrite/Controller/UrlRewriteTest.php | 15 +++++++++++ .../Magento/UrlRewrite/_files/url_rewrite.php | 18 +++++++++++++ .../_files/url_rewrite_rollback.php | 4 ++- 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/UrlRewrite/Controller/Router.php b/app/code/Magento/UrlRewrite/Controller/Router.php index edefbb5f4ba3a..040aa6fc85702 100644 --- a/app/code/Magento/UrlRewrite/Controller/Router.php +++ b/app/code/Magento/UrlRewrite/Controller/Router.php @@ -90,9 +90,26 @@ public function match(RequestInterface $request) $this->storeManager->getStore()->getId() ); - if ($rewrite === null || $rewrite->getRequestPath() === $rewrite->getTargetPath()) { - // Either no rewrite rule matching current URl found or found one with request path equal to - // target path, continuing with processing of this URL. + if ($rewrite === null) { + // No rewrite rule matching current URl found, continuing with + // processing of this URL. + return null; + } + + $requestStringTrimmed = ltrim($request->getRequestString(), '/'); + $rewriteRequestPath = $rewrite->getRequestPath(); + $rewriteTargetPath = $rewrite->getTargetPath(); + $rewriteTargetPathTrimmed = ltrim($rewriteTargetPath, '/'); + + if (preg_replace('/\?.*/', '', $rewriteRequestPath) === preg_replace('/\?.*/', '', $rewriteTargetPath) && + ( + !$requestStringTrimmed || + !$rewriteTargetPathTrimmed || + strpos($requestStringTrimmed, $rewriteTargetPathTrimmed) === 0 + ) + ) { + // Request and target paths of rewrite found without query params are equal and current request string + // starts with request target path, continuing with processing of this URL. return null; } @@ -104,9 +121,9 @@ public function match(RequestInterface $request) // Rule provides actual URL that can be processed by a controller. $request->setAlias( UrlInterface::REWRITE_REQUEST_PATH_ALIAS, - $rewrite->getRequestPath() + $rewriteRequestPath ); - $request->setPathInfo('/' . $rewrite->getTargetPath()); + $request->setPathInfo('/' . $rewriteTargetPath); return $this->actionFactory->create( Forward::class ); diff --git a/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php b/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php index 7038e75f16456..7a3a6d346a792 100644 --- a/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php +++ b/app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php @@ -114,6 +114,8 @@ public function testNoRewriteExist() { $this->request->method('getPathInfo') ->willReturn(''); + $this->request->method('getRequestString') + ->willReturn(''); $this->urlFinder->method('findOneByData') ->willReturn(null); $this->storeManager->method('getStore') @@ -142,6 +144,8 @@ public function testRewriteAfterStoreSwitcher() ->willReturn($oldStoreAlias); $this->request->method('getPathInfo') ->willReturn($initialRequestPath); + $this->request->method('getRequestString') + ->willReturn($initialRequestPath); $oldStore = $this->getMockBuilder(Store::class) ->disableOriginalConstructor() ->getMock(); @@ -192,6 +196,7 @@ public function testRewriteAfterStoreSwitcher() public function testNoRewriteAfterStoreSwitcherWhenNoOldRewrite() { $this->request->method('getPathInfo')->willReturn('request-path'); + $this->request->method('getRequestString')->willReturn('request-path'); $this->request->method('getParam')->with('___from_store') ->willReturn('old-store'); $oldStore = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); @@ -217,6 +222,7 @@ public function testNoRewriteAfterStoreSwitcherWhenNoOldRewrite() public function testNoRewriteAfterStoreSwitcherWhenOldRewriteEqualsToNewOne() { $this->request->method('getPathInfo')->willReturn('request-path'); + $this->request->method('getRequestString')->willReturn('request-path'); $this->request->method('getParam')->with('___from_store') ->willReturn('old-store'); $oldStore = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); @@ -268,6 +274,8 @@ public function testMatchWithRedirect() ->willReturn($this->store); $this->request->method('getPathInfo') ->willReturn($requestPath); + $this->request->method('getRequestString') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor() ->getMock(); @@ -312,6 +320,8 @@ public function testMatchWithCustomInternalRedirect($requestPath, $targetPath, $ ->willReturn($this->store); $this->request->method('getPathInfo') ->willReturn($requestPath); + $this->request->method('getRequestString') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor() ->getMock(); @@ -369,6 +379,8 @@ public function testMatchWithCustomExternalRedirect($targetPath) $this->storeManager->method('getStore')->willReturn($this->store); $this->request->method('getPathInfo') ->willReturn($requestPath); + $this->request->method('getRequestString') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); $urlRewrite->method('getEntityType')->willReturn('custom'); @@ -408,6 +420,8 @@ public function testMatch() $this->storeManager->method('getStore')->willReturn($this->store); $this->request->method('getPathInfo') ->willReturn($requestPath); + $this->request->method('getRequestString') + ->willReturn($requestPath); $urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); $urlRewrite->method('getRedirectType')->willReturn(0); diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/UrlRewriteTest.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/UrlRewriteTest.php index cea44226f6192..867fcd4c2f338 100644 --- a/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/UrlRewriteTest.php +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/UrlRewriteTest.php @@ -133,6 +133,21 @@ public function requestDataProvider(): array 'request' => '/page-external4?param1=custom1¶m2=custom2', 'redirect' => 'https://example.com/external2/?param2=value2', ], + 'Use Case #17: Rewrite: / --(301)--> /; No redirect' => [ + 'request' => '/', + 'redirect' => '/', + 'expectedCode' => HttpResponse::STATUS_CODE_200, + ], + 'Use Case #18: Rewrite: contact/ --(301)--> contact?param1=1; ' + . 'Request: contact/ --(301)--> contact?param1=1' => [ + 'request' => 'contact/', + 'redirect' => 'contact?param1=1', + ], + 'Use Case #19: Rewrite: contact/?param2=2 --(301)--> contact?param1=1¶m2=2; ' + . 'Request: contact/?¶m2=2 --(301)--> contact?param1=1¶m2=2' => [ + 'request' => 'contact/?¶m2=2', + 'redirect' => 'contact?param1=1¶m2=2', + ], ]; } } diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite.php index 68d1212539c6d..62aa27562537a 100644 --- a/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite.php +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite.php @@ -156,6 +156,24 @@ ->setDescription('From page-similar-query-param with trailing slash to page-e with query param'); $rewriteResource->save($rewrite); +$rewrite = $objectManager->create(UrlRewrite::class); +$rewrite->setEntityType('custom') + ->setRequestPath('/') + ->setTargetPath('/') + ->setRedirectType(OptionProvider::PERMANENT) + ->setStoreId($storeID) + ->setDescription('From / to /'); +$rewriteResource->save($rewrite); + +$rewrite = $objectManager->create(UrlRewrite::class); +$rewrite->setEntityType('custom') + ->setRequestPath('contact/') + ->setTargetPath('contact?param1=1') + ->setRedirectType(OptionProvider::PERMANENT) + ->setStoreId($storeID) + ->setDescription('From contact with trailing slash to contact with query param'); +$rewriteResource->save($rewrite); + $rewrite = $objectManager->create(UrlRewrite::class); $rewrite->setEntityType('custom') ->setRequestPath('page-external1') diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite_rollback.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite_rollback.php index a5c21f7a00e48..4d2c148141943 100644 --- a/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite_rollback.php +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/_files/url_rewrite_rollback.php @@ -43,7 +43,9 @@ 'http://example.com/external', 'https://example.com/external2/', 'http://example.com/external?param1=value1', - 'https://example.com/external2/?param2=value2' + 'https://example.com/external2/?param2=value2', + '/', + 'contact?param1=1' ] ) ->load() From b1d4c72e09d5d5e024d2a29efbceb51f6219eda8 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Thu, 27 Feb 2020 13:50:02 +0200 Subject: [PATCH 13/27] cover changes with setup-integration test --- .../Magento/TestSetupDeclarationModule1/etc/db_schema.xml | 1 + .../fixture/valid_xml_revision_1.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/etc/db_schema.xml b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/etc/db_schema.xml index ae6c98e4627d2..9de94cf0549be 100644 --- a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/etc/db_schema.xml +++ b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/etc/db_schema.xml @@ -48,6 +48,7 @@ + diff --git a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php index a064d096f6d38..0109b644e546f 100644 --- a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php +++ b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php @@ -199,6 +199,12 @@ 'type' => 'mediumtext', 'name' => 'mediumtext', ], + 'char' => [ + 'type' => 'char', + 'name' => 'char', + 'length' => '255', + 'nullable' => 'true', + ], 'varchar' => [ 'type' => 'varchar', 'name' => 'varchar', From 6070770d1fc2d22f275147c2b6972b9e15a248ba Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Thu, 27 Feb 2020 15:28:46 +0200 Subject: [PATCH 14/27] add cgar column to fixtures --- .../fixture/declarative_installer/column_modification.php | 1 + .../Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php | 1 + 2 files changed, 2 insertions(+) diff --git a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php index a69e456ec4a8b..f2a34c338edc2 100644 --- a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php +++ b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php @@ -36,6 +36,7 @@ `longtext` longtext, `mediumtext` mediumtext, `varchar` varchar(100) DEFAULT NULL, + `char` char(255) DEFAULT NULL, `mediumblob` mediumblob, `blob` blob, `boolean` tinyint(1) DEFAULT \'1\', diff --git a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php index e642e57701149..7735bd433d9d2 100644 --- a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php +++ b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php @@ -38,6 +38,7 @@ `longtext` longtext NULL , `mediumtext` mediumtext NULL , `varchar` varchar(254) NULL , +`char` char(255) NULL , `mediumblob` mediumblob NULL , `blob` blob NULL , `boolean` BOOLEAN NULL , From 92ec5943ef3186f72a31214011abc5271db646a9 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Thu, 27 Feb 2020 20:04:25 +0200 Subject: [PATCH 15/27] added assertion --- .../fixture/declarative_installer/constraint_modification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php index 01e007edb7684..0b1ec6245478b 100644 --- a/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php +++ b/dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php @@ -38,6 +38,7 @@ `longtext` longtext, `mediumtext` mediumtext, `varchar` varchar(254) DEFAULT NULL, + `char` char(255) DEFAULT NULL, `mediumblob` mediumblob, `blob` blob, `boolean` tinyint(1) DEFAULT NULL, From 97642b5f28da27bec827c906dc2a096aa95fb502 Mon Sep 17 00:00:00 2001 From: Sathish Date: Sat, 29 Feb 2020 00:46:37 +0530 Subject: [PATCH 16/27] Fixed alignment of other checkboxes --- .../Magento_Catalog/web/css/source/_module.less | 13 ++++++++++++- .../Magento_Customer/web/css/source/_module.less | 6 ------ .../Magento_Review/web/css/source/_module.less | 8 -------- .../backend/Magento_Tax/web/css/source/_module.less | 6 ------ .../backend/web/css/source/forms/_fields.less | 2 +- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less index ffbbaeb084162..f494bb0ad0088 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less @@ -20,7 +20,7 @@ .admin__grid-control-value { display: none; } - } + } } .product-composite-configure-inner { @@ -102,3 +102,14 @@ } } } + +// +// Catalog Product Edit Action Attribute +// --------------------------------------------- +.admin__field-control { + .attribute-change-checkbox { + input[type='checkbox'].checkbox { + margin-top: 0; + } + } +} diff --git a/app/design/adminhtml/Magento/backend/Magento_Customer/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Customer/web/css/source/_module.less index 0c7dd7e7cb94c..e526ae4857469 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Customer/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Customer/web/css/source/_module.less @@ -101,10 +101,4 @@ } } } - - > .admin__field > .admin__field-control { - input[type='checkbox'] { - margin: 8px 0 0 0; - } - } } diff --git a/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less index 9eae708819a0b..08606402f7a0e 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Review/web/css/source/_module.less @@ -77,11 +77,3 @@ } } } - -.review-rating-edit { - .admin__field-control.control { - input[type='checkbox'] { - margin: 8px 0 0 0; - } - } -} diff --git a/app/design/adminhtml/Magento/backend/Magento_Tax/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Tax/web/css/source/_module.less index 2377f7c9a9c11..49459bc11cfb2 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Tax/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Tax/web/css/source/_module.less @@ -25,9 +25,3 @@ font-size: 1.3rem; } } - -.admin__fieldset > .admin__field > .admin__field-control { - input.zip-is-range-checkbox { - margin: 8px 0 0 0; - } -} diff --git a/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less b/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less index bfb515c700b33..256ac453578df 100644 --- a/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less +++ b/app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less @@ -122,7 +122,7 @@ > .admin__field-control { #mix-grid .column(@field-control-grid__column, @field-grid__columns); input[type="checkbox"] { - margin-top: 0; + margin-top: @indent__s; } } From bcadcfb6cd7f6957618d77f50cf199aae85d3c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Sat, 29 Feb 2020 00:46:26 +0100 Subject: [PATCH 17/27] Cleanup ObjectManager usage - Magento_Analytics --- .../System/Config/CollectionTimeLabel.php | 31 +++++++----- .../System/Config/CollectionTimeLabelTest.php | 50 ++++++++++++------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php index 34f2b7d53d9be..62ef86c7dafb5 100644 --- a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php +++ b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php @@ -3,42 +3,47 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Analytics\Block\Adminhtml\System\Config; -use Magento\Framework\App\ObjectManager; +use Magento\Backend\Block\Template\Context; +use Magento\Config\Block\System\Config\Form\Field; +use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\Locale\ResolverInterface; /** * Provides label with default Time Zone */ -class CollectionTimeLabel extends \Magento\Config\Block\System\Config\Form\Field +class CollectionTimeLabel extends Field { /** - * @var \Magento\Framework\Locale\ResolverInterface + * @var ResolverInterface */ private $localeResolver; /** - * @param \Magento\Backend\Block\Template\Context $context + * @param Context $context + * @param ResolverInterface $localeResolver * @param array $data - * @param \Magento\Framework\Locale\ResolverInterface|null $localeResolver */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - array $data = [], - \Magento\Framework\Locale\ResolverInterface $localeResolver = null + Context $context, + ResolverInterface $localeResolver, + array $data = [] ) { - $this->localeResolver = $localeResolver ?: - ObjectManager::getInstance()->get(\Magento\Framework\Locale\ResolverInterface::class); parent::__construct($context, $data); + $this->localeResolver = $localeResolver; } /** * Add current time zone to comment, properly translated according to locale * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element + * * @return string */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + public function render(AbstractElement $element) { $timeZoneCode = $this->_localeDate->getConfigTimezone(); $locale = $this->localeResolver->getLocale(); @@ -46,7 +51,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele ->getDisplayName(false, \IntlTimeZone::DISPLAY_LONG, $locale); $element->setData( 'comment', - sprintf("%s (%s)", $getLongTimeZoneName, $timeZoneCode) + sprintf('%s (%s)', $getLongTimeZoneName, $timeZoneCode) ); return parent::render($element); } diff --git a/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php index 08ee3c356937a..3a98fd6acbf4d 100644 --- a/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php +++ b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php @@ -3,17 +3,25 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Analytics\Test\Unit\Block\Adminhtml\System\Config; use Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel; use Magento\Backend\Block\Template\Context; use Magento\Framework\Data\Form; use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\Escaper; use Magento\Framework\Locale\ResolverInterface; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; -class CollectionTimeLabelTest extends \PHPUnit\Framework\TestCase +/** + * Test class for \Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel + */ +class CollectionTimeLabelTest extends TestCase { /** * @var CollectionTimeLabel @@ -21,25 +29,33 @@ class CollectionTimeLabelTest extends \PHPUnit\Framework\TestCase private $collectionTimeLabel; /** - * @var Context|\PHPUnit_Framework_MockObject_MockObject + * @var Context|MockObject */ private $contextMock; /** - * @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ResolverInterface|MockObject + */ + private $localeResolverMock; + + /** + * @var Form|MockObject + */ + private $formMock; + + /** + * @var TimezoneInterface|MockObject */ private $timeZoneMock; /** - * @var AbstractElement|\PHPUnit_Framework_MockObject_MockObject + * @var AbstractElement|MockObject */ private $abstractElementMock; /** - * @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject + * @inheritDoc */ - private $localeResolver; - protected function setUp() { $this->abstractElementMock = $this->getMockBuilder(AbstractElement::class) @@ -48,7 +64,7 @@ protected function setUp() ->getMock(); $objectManager = new ObjectManager($this); - $escaper = $objectManager->getObject(\Magento\Framework\Escaper::class); + $escaper = $objectManager->getObject(Escaper::class); $reflection = new \ReflectionClass($this->abstractElementMock); $reflection_property = $reflection->getProperty('_escaper'); $reflection_property->setAccessible(true); @@ -64,35 +80,35 @@ protected function setUp() $this->timeZoneMock = $this->getMockBuilder(TimezoneInterface::class) ->disableOriginalConstructor() ->getMock(); - $this->contextMock->expects($this->any()) - ->method('getLocaleDate') + $this->contextMock->method('getLocaleDate') ->willReturn($this->timeZoneMock); - $this->localeResolver = $this->getMockBuilder(ResolverInterface::class) + $this->localeResolverMock = $this->getMockBuilder(ResolverInterface::class) ->disableOriginalConstructor() ->setMethods(['getLocale']) ->getMockForAbstractClass(); - $objectManager = new ObjectManager($this); $this->collectionTimeLabel = $objectManager->getObject( CollectionTimeLabel::class, [ 'context' => $this->contextMock, - 'localeResolver' => $this->localeResolver + 'localeResolver' => $this->localeResolverMock ] ); } + /** + * Test for \Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel::render() + */ public function testRender() { - $timeZone = "America/New_York"; + $timeZone = 'America/New_York'; $this->abstractElementMock->setForm($this->formMock); $this->timeZoneMock->expects($this->once()) ->method('getConfigTimezone') ->willReturn($timeZone); - $this->abstractElementMock->expects($this->any()) - ->method('getComment') + $this->abstractElementMock->method('getComment') ->willReturn('Eastern Standard Time (America/New_York)'); - $this->localeResolver->expects($this->once()) + $this->localeResolverMock->expects($this->once()) ->method('getLocale') ->willReturn('en_US'); $this->assertRegExp( From 807f055d704f5c8b8172dacaaad608826db22df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Fri, 21 Feb 2020 22:53:00 +0100 Subject: [PATCH 18/27] Cleanup ObjectManager usage - Magento_EncryptionKey --- .../Controller/Adminhtml/Crypt/Key/Index.php | 38 ++++++++--- .../Setup/Patch/Data/SodiumChachaPatch.php | 64 +++++++++++-------- app/code/Magento/EncryptionKey/etc/di.xml | 14 ++++ 3 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 app/code/Magento/EncryptionKey/etc/di.xml diff --git a/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php b/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php index 86fc0082f7a5a..9b841fc32c383 100644 --- a/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php +++ b/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php @@ -1,18 +1,40 @@ writer = $writer; + } + /** * Render main page with form * @@ -20,10 +42,8 @@ class Index extends \Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key implem */ public function execute() { - /** @var \Magento\Framework\App\DeploymentConfig\Writer $writer */ - $writer = $this->_objectManager->get(\Magento\Framework\App\DeploymentConfig\Writer::class); - if (!$writer->checkIfWritable()) { - $this->messageManager->addError(__('Deployment configuration file is not writable.')); + if (!$this->writer->checkIfWritable()) { + $this->messageManager->addErrorMessage(__('Deployment configuration file is not writable.')); } $this->_view->loadLayout(); @@ -31,8 +51,8 @@ public function execute() $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Encryption Key')); if (($formBlock = $this->_view->getLayout()->getBlock('crypt.key.form')) && - ($data = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getFormData(true))) { - /* @var \Magento\EncryptionKey\Block\Adminhtml\Crypt\Key\Form $formBlock */ + ($data = $this->_session->getFormData(true))) { + /* @var Form $formBlock */ $formBlock->setFormData($data); } diff --git a/app/code/Magento/EncryptionKey/Setup/Patch/Data/SodiumChachaPatch.php b/app/code/Magento/EncryptionKey/Setup/Patch/Data/SodiumChachaPatch.php index 9331b68675b67..e04fabeb0db34 100644 --- a/app/code/Magento/EncryptionKey/Setup/Patch/Data/SodiumChachaPatch.php +++ b/app/code/Magento/EncryptionKey/Setup/Patch/Data/SodiumChachaPatch.php @@ -7,8 +7,14 @@ namespace Magento\EncryptionKey\Setup\Patch\Data; +use Magento\Config\Model\Config\Backend\Encrypted; +use Magento\Config\Model\Config\Structure; +use Magento\Framework\App\Area; +use Magento\Framework\App\State; +use Magento\Framework\Config\ScopeInterface; +use Magento\Framework\Encryption\EncryptorInterface; +use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; -use Magento\Framework\App\ObjectManager; /** * Migrate encrypted configuration values to the latest cipher @@ -16,50 +22,50 @@ class SodiumChachaPatch implements DataPatchInterface { /** - * @var \Magento\Framework\Config\ScopeInterface - */ - private $scope; - - /** - * @var \Magento\Framework\Setup\ModuleDataSetupInterface + * @var ModuleDataSetupInterface */ private $moduleDataSetup; /** - * @var \Magento\Config\Model\Config\Structure + * @var Structure */ private $structure; /** - * @var \Magento\Framework\Encryption\EncryptorInterface + * @var EncryptorInterface */ private $encryptor; /** - * @var \Magento\Framework\App\State + * @var State */ private $state; + /** + * @var ScopeInterface + */ + private $scope; + /** * SodiumChachaPatch constructor. - * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup - * @param \Magento\Config\Model\Config\Structure\Proxy $structure - * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor - * @param \Magento\Framework\App\State $state - * @param \Magento\Framework\Config\ScopeInterface|null $scope + * @param ModuleDataSetupInterface $moduleDataSetup + * @param Structure $structure + * @param EncryptorInterface $encryptor + * @param State $state + * @param ScopeInterface $scope */ public function __construct( - \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, - \Magento\Config\Model\Config\Structure\Proxy $structure, - \Magento\Framework\Encryption\EncryptorInterface $encryptor, - \Magento\Framework\App\State $state, - \Magento\Framework\Config\ScopeInterface $scope = null + ModuleDataSetupInterface $moduleDataSetup, + Structure $structure, + EncryptorInterface $encryptor, + State $state, + ScopeInterface $scope ) { $this->moduleDataSetup = $moduleDataSetup; $this->structure = $structure; $this->encryptor = $encryptor; $this->state = $state; - $this->scope = $scope ?? ObjectManager::getInstance()->get(\Magento\Framework\Config\ScopeInterface::class); + $this->scope = $scope; } /** @@ -72,6 +78,8 @@ public function apply() $this->reEncryptSystemConfigurationValues(); $this->moduleDataSetup->endSetup(); + + return $this; } /** @@ -106,19 +114,25 @@ private function reEncryptSystemConfigurationValues() $currentScope = $this->scope->getCurrentScope(); $structure = $this->structure; $paths = $this->state->emulateAreaCode( - \Magento\Framework\App\Area::AREA_ADMINHTML, + Area::AREA_ADMINHTML, function () use ($structure) { - $this->scope->setCurrentScope(\Magento\Framework\App\Area::AREA_ADMINHTML); + $this->scope->setCurrentScope(Area::AREA_ADMINHTML); /** Returns list of structure paths to be re encrypted */ $paths = $structure->getFieldPathsByAttribute( 'backend_model', - \Magento\Config\Model\Config\Backend\Encrypted::class + Encrypted::class ); /** Returns list of mapping between configPath => [structurePaths] */ $mappedPaths = $structure->getFieldPaths(); foreach ($mappedPaths as $mappedPath => $data) { foreach ($data as $structurePath) { - if ($structurePath !== $mappedPath && $key = array_search($structurePath, $paths)) { + if ($structurePath === $mappedPath) { + continue; + } + + $key = array_search($structurePath, $paths); + + if ($key) { $paths[$key] = $mappedPath; } } diff --git a/app/code/Magento/EncryptionKey/etc/di.xml b/app/code/Magento/EncryptionKey/etc/di.xml new file mode 100644 index 0000000000000..b4e471f4e40ef --- /dev/null +++ b/app/code/Magento/EncryptionKey/etc/di.xml @@ -0,0 +1,14 @@ + + + + + + Magento\Config\Model\Config\Structure\Proxy + + + From dee769295d724a6867c6f6d0390acbc84f0f50d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Sat, 29 Feb 2020 01:09:34 +0100 Subject: [PATCH 19/27] Cleanup ObjectManager usage - Magento_CacheInvalidate --- .../Observer/InvalidateVarnishObserver.php | 60 ++++++------ .../InvalidateVarnishObserverTest.php | 98 ++++++++++++------- 2 files changed, 94 insertions(+), 64 deletions(-) diff --git a/app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php b/app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php index 3527d4f6cdf4e..a3062ea9d6a76 100644 --- a/app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php +++ b/app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php @@ -3,61 +3,76 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\CacheInvalidate\Observer; +use Magento\CacheInvalidate\Model\PurgeCache; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\App\Cache\Tag\Resolver; +use Magento\PageCache\Model\Config; +/** + * Observer used to invalidate varnish cache once Magento cache was cleaned + */ class InvalidateVarnishObserver implements ObserverInterface { /** * Application config object * - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ - protected $config; + private $config; /** - * @var \Magento\CacheInvalidate\Model\PurgeCache + * @var PurgeCache */ - protected $purgeCache; + private $purgeCache; /** * Invalidation tags resolver * - * @var \Magento\Framework\App\Cache\Tag\Resolver + * @var Resolver */ private $tagResolver; /** - * @param \Magento\PageCache\Model\Config $config - * @param \Magento\CacheInvalidate\Model\PurgeCache $purgeCache + * @param Config $config + * @param PurgeCache $purgeCache + * @param Resolver $tagResolver */ public function __construct( - \Magento\PageCache\Model\Config $config, - \Magento\CacheInvalidate\Model\PurgeCache $purgeCache + Config $config, + PurgeCache $purgeCache, + Resolver $tagResolver ) { $this->config = $config; $this->purgeCache = $purgeCache; + $this->tagResolver = $tagResolver; } /** - * If Varnish caching is enabled it collects array of tags - * of incoming object and asks to clean cache. + * If Varnish caching is enabled it collects array of tags of incoming object and asks to clean cache. + * + * @param Observer $observer * - * @param \Magento\Framework\Event\Observer $observer * @return void */ - public function execute(\Magento\Framework\Event\Observer $observer) + public function execute(Observer $observer) { $object = $observer->getEvent()->getObject(); + if (!is_object($object)) { return; } - if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) { - $bareTags = $this->getTagResolver()->getTags($object); + + if ((int)$this->config->getType() === Config::VARNISH && $this->config->isEnabled()) { + $bareTags = $this->tagResolver->getTags($object); $tags = []; - $pattern = "((^|,)%s(,|$))"; + $pattern = '((^|,)%s(,|$))'; foreach ($bareTags as $tag) { $tags[] = sprintf($pattern, $tag); } @@ -66,17 +81,4 @@ public function execute(\Magento\Framework\Event\Observer $observer) } } } - - /** - * @deprecated 100.1.2 - * @return \Magento\Framework\App\Cache\Tag\Resolver - */ - private function getTagResolver() - { - if ($this->tagResolver === null) { - $this->tagResolver = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\App\Cache\Tag\Resolver::class); - } - return $this->tagResolver; - } } diff --git a/app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php b/app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php index b333fcaaa678a..56684ed564dde 100644 --- a/app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php +++ b/app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php @@ -3,49 +3,77 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\CacheInvalidate\Test\Unit\Observer; +use Magento\CacheInvalidate\Model\PurgeCache; +use Magento\CacheInvalidate\Observer\InvalidateVarnishObserver; +use Magento\Framework\App\Cache\Tag\Resolver; +use Magento\Framework\Event; +use Magento\Framework\Event\Observer; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\PageCache\Model\Config; +use Magento\Store\Model\Store; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; -class InvalidateVarnishObserverTest extends \PHPUnit\Framework\TestCase +/** + * Test class for \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver + */ +class InvalidateVarnishObserverTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver */ - protected $model; + /** + * @var InvalidateVarnishObserver + */ + private $model; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\Observer */ - protected $observerMock; + /** + * @var Config|MockObject + */ + private $configMock; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Model\Config */ - protected $configMock; + /** + * @var PurgeCache|MockObject + */ + private $purgeCacheMock; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Model\PurgeCache */ - protected $purgeCache; + /** + * @var Resolver|MockObject + */ + private $tagResolverMock; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\DataObject\ */ - protected $observerObject; + /** + * @var Observer|MockObject + */ + private $observerMock; - /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Tag\Resolver */ - private $tagResolver; + /** + * @var Store|MockObject + */ + private $observerObject; /** - * Set up all mocks and data for test + * @inheritDoc */ protected function setUp() { - $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - - $this->configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']); - $this->purgeCache = $this->createMock(\Magento\CacheInvalidate\Model\PurgeCache::class); - $this->model = new \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver( - $this->configMock, - $this->purgeCache - ); + $this->configMock = $this->createPartialMock(Config::class, ['getType', 'isEnabled']); + $this->purgeCacheMock = $this->createMock(PurgeCache::class); + $this->tagResolverMock = $this->createMock(Resolver::class); - $this->tagResolver = $this->createMock(\Magento\Framework\App\Cache\Tag\Resolver::class); - $helper->setBackwardCompatibleProperty($this->model, 'tagResolver', $this->tagResolver); + $this->observerMock = $this->createPartialMock(Observer::class, ['getEvent']); + $this->observerObject = $this->createMock(Store::class); - $this->observerMock = $this->createPartialMock(\Magento\Framework\Event\Observer::class, ['getEvent']); - $this->observerObject = $this->createMock(\Magento\Store\Model\Store::class); + $objectManager = new ObjectManager($this); + $this->model = $objectManager->getObject( + InvalidateVarnishObserver::class, + [ + 'config' => $this->configMock, + 'purgeCache' => $this->purgeCacheMock, + 'tagResolver' => $this->tagResolverMock + ] + ); } /** @@ -56,21 +84,21 @@ public function testInvalidateVarnish() $tags = ['cache_1', 'cache_group']; $pattern = '((^|,)cache_1(,|$))|((^|,)cache_group(,|$))'; - $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); + $this->configMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->configMock->expects( $this->once() )->method( 'getType' - )->will( - $this->returnValue(\Magento\PageCache\Model\Config::VARNISH) + )->willReturn( + Config::VARNISH ); - $eventMock = $this->createPartialMock(\Magento\Framework\Event::class, ['getObject']); - $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->observerObject)); - $this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); - $this->tagResolver->expects($this->once())->method('getTags')->with($this->observerObject) - ->will($this->returnValue($tags)); - $this->purgeCache->expects($this->once())->method('sendPurgeRequest')->with($pattern); + $eventMock = $this->createPartialMock(Event::class, ['getObject']); + $eventMock->expects($this->once())->method('getObject')->willReturn($this->observerObject); + $this->observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock); + $this->tagResolverMock->expects($this->once())->method('getTags')->with($this->observerObject) + ->willReturn($tags); + $this->purgeCacheMock->expects($this->once())->method('sendPurgeRequest')->with($pattern); $this->model->execute($this->observerMock); } From ee00b989feee1ecf0412abe9d860cb0320fb5f26 Mon Sep 17 00:00:00 2001 From: Eduard Chitoraga Date: Sun, 1 Mar 2020 08:02:06 +0200 Subject: [PATCH 20/27] Small adjustment --- .../Magento/backend/Magento_Catalog/web/css/source/_module.less | 1 + 1 file changed, 1 insertion(+) diff --git a/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less index f494bb0ad0088..650fe6177d04b 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less @@ -106,6 +106,7 @@ // // Catalog Product Edit Action Attribute // --------------------------------------------- + .admin__field-control { .attribute-change-checkbox { input[type='checkbox'].checkbox { From 21afe21644fe586b83654344d56b6651a3279873 Mon Sep 17 00:00:00 2001 From: Vaha Date: Wed, 26 Feb 2020 14:53:21 +0200 Subject: [PATCH 21/27] improved event handlers for prompt widget --- ...nsertEditImageTinyMCEButtonActionGroup.xml | 19 +++++++ ...CreateImageFolderByEnterKeyActionGroup.xml | 18 +++++++ .../ActionGroup/DeleteFolderActionGroup.xml | 28 ++++++++++ .../PressEscImageFolderActionGroup.xml | 27 ++++++++++ .../Cms/Test/Mftf/Section/TinyMCESection.xml | 1 + ...capeAndEnterHandlesForWYSIWYGBlockTest.xml | 53 +++++++++++++++++++ .../Ui/view/base/web/js/modal/prompt.js | 38 +++++++++++++ 7 files changed, 184 insertions(+) create mode 100644 app/code/Magento/Cms/Test/Mftf/ActionGroup/ClickInsertEditImageTinyMCEButtonActionGroup.xml create mode 100644 app/code/Magento/Cms/Test/Mftf/ActionGroup/CreateImageFolderByEnterKeyActionGroup.xml create mode 100644 app/code/Magento/Cms/Test/Mftf/ActionGroup/DeleteFolderActionGroup.xml create mode 100644 app/code/Magento/Cms/Test/Mftf/ActionGroup/PressEscImageFolderActionGroup.xml create mode 100644 app/code/Magento/Cms/Test/Mftf/Test/AdminCheckCreateFolderEscapeAndEnterHandlesForWYSIWYGBlockTest.xml diff --git a/app/code/Magento/Cms/Test/Mftf/ActionGroup/ClickInsertEditImageTinyMCEButtonActionGroup.xml b/app/code/Magento/Cms/Test/Mftf/ActionGroup/ClickInsertEditImageTinyMCEButtonActionGroup.xml new file mode 100644 index 0000000000000..1685898743596 --- /dev/null +++ b/app/code/Magento/Cms/Test/Mftf/ActionGroup/ClickInsertEditImageTinyMCEButtonActionGroup.xml @@ -0,0 +1,19 @@ + + + + + + + Clicks on the 'Insert/edit image' TinyMCE button. + + + + + + diff --git a/app/code/Magento/Cms/Test/Mftf/ActionGroup/CreateImageFolderByEnterKeyActionGroup.xml b/app/code/Magento/Cms/Test/Mftf/ActionGroup/CreateImageFolderByEnterKeyActionGroup.xml new file mode 100644 index 0000000000000..5d8138b9c9cc7 --- /dev/null +++ b/app/code/Magento/Cms/Test/Mftf/ActionGroup/CreateImageFolderByEnterKeyActionGroup.xml @@ -0,0 +1,18 @@ + + + + + + + Creates a folder (by enter key) in the Media Gallery based on the provided Folder. + + + + + diff --git a/app/code/Magento/Cms/Test/Mftf/ActionGroup/DeleteFolderActionGroup.xml b/app/code/Magento/Cms/Test/Mftf/ActionGroup/DeleteFolderActionGroup.xml new file mode 100644 index 0000000000000..4c33b3d8ce35d --- /dev/null +++ b/app/code/Magento/Cms/Test/Mftf/ActionGroup/DeleteFolderActionGroup.xml @@ -0,0 +1,28 @@ + + + + + + + Deletes the provided folder by name from the Media Gallery. + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Cms/Test/Mftf/ActionGroup/PressEscImageFolderActionGroup.xml b/app/code/Magento/Cms/Test/Mftf/ActionGroup/PressEscImageFolderActionGroup.xml new file mode 100644 index 0000000000000..85f83193e64e3 --- /dev/null +++ b/app/code/Magento/Cms/Test/Mftf/ActionGroup/PressEscImageFolderActionGroup.xml @@ -0,0 +1,27 @@ + + + + + + + Opens the 'create folder' modal, fills 'folder name' input with provided folder name, + presses escape key to cancel folder creation (close modal). + + + + + + + + + + + + + diff --git a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection.xml b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection.xml index b85c7554b58ae..aebed8c9efec0 100644 --- a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection.xml +++ b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection.xml @@ -51,6 +51,7 @@ + diff --git a/app/code/Magento/Cms/Test/Mftf/Test/AdminCheckCreateFolderEscapeAndEnterHandlesForWYSIWYGBlockTest.xml b/app/code/Magento/Cms/Test/Mftf/Test/AdminCheckCreateFolderEscapeAndEnterHandlesForWYSIWYGBlockTest.xml new file mode 100644 index 0000000000000..8114310e46f73 --- /dev/null +++ b/app/code/Magento/Cms/Test/Mftf/Test/AdminCheckCreateFolderEscapeAndEnterHandlesForWYSIWYGBlockTest.xml @@ -0,0 +1,53 @@ + + + + + + + + + + <description value="Admin should be able to cancel and close 'create folder' modal window using ESC key and + to add image to new folder (using enter key) for WYSIWYG content of Block"/> + </annotations> + + <before> + <createData entity="_defaultBlock" stepKey="createPreReqBlock" /> + <actionGroup ref="LoginActionGroup" stepKey="login"/> + <actionGroup ref="EnabledWYSIWYGActionGroup" stepKey="enableWYSIWYG"/> + <actionGroup ref="SwitchToVersion4ActionGroup" stepKey="switchToTinyMCE4" /> + </before> + + <after> + <deleteData createDataKey="createPreReqBlock" stepKey="deletePreReqBlock" /> + <actionGroup ref="DisabledWYSIWYGActionGroup" stepKey="disableWYSIWYG"/> + <actionGroup ref="logout" stepKey="logout"/> + </after> + + <actionGroup ref="NavigateToCreatedCMSBlockPageActionGroup" stepKey="navigateToCreatedCMSBlockPage"> + <argument name="CMSBlockPage" value="$$createPreReqBlock$$"/> + </actionGroup> + <actionGroup ref="ClickInsertEditImageTinyMCEButtonActionGroup" stepKey="clickInsertImageIcon"/> + <actionGroup ref="ClickBrowseBtnOnUploadPopupActionGroup" stepKey="clickBrowserBtn"/> + <actionGroup ref="VerifyMediaGalleryStorageActionsActionGroup" stepKey="VerifyMediaGalleryStorageBtn"/> + + <actionGroup ref="CreateImageFolderByEnterKeyActionGroup" stepKey="CreateImageFolderByEnterKeyPress"> + <argument name="ImageFolder" value="ImageFolder"/> + </actionGroup> + + <actionGroup ref="DeleteFolderActionGroup" stepKey="DeleteCreatedFolder"> + <argument name="ImageFolder" value="ImageFolder"/> + </actionGroup> + + <actionGroup ref="PressEscImageFolderActionGroup" stepKey="CancelImageFolderCreation"> + <argument name="ImageFolder" value="ImageFolder"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 13b4d55ea2787..443d35f1b0ded 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -27,6 +27,44 @@ define([ value: '', validation: false, validationRules: [], + keyEventHandlers: { + + /** + * Enter key press handler, + * submit result and close modal window + * @param {Object} event - event + */ + enterKey: function (event) { + if (this.options.isOpen && this.modal.find(document.activeElement).length || + this.options.isOpen && this.modal[0] === document.activeElement) { + this.closeModal(true); + event.preventDefault(); + } + }, + + /** + * Tab key press handler, + * set focus to elements + */ + tabKey: function () { + if (document.activeElement === this.modal[0]) { + this._setFocus('start'); + } + }, + + /** + * Escape key press handler, + * cancel and close modal window + * @param {Object} event - event + */ + escapeKey: function (event) { + if (this.options.isOpen && this.modal.find(document.activeElement).length || + this.options.isOpen && this.modal[0] === document.activeElement) { + this.closeModal(); + event.preventDefault(); + } + } + }, actions: { /** From 945c427b17f9a7199982b10efe73c5f53f1d18cd Mon Sep 17 00:00:00 2001 From: Adarsh Manickam <amanickam@ztech.io> Date: Tue, 3 Mar 2020 16:34:23 +0530 Subject: [PATCH 22/27] Removed unnecessary tabindex property --- app/code/Magento/Ui/view/base/web/templates/grid/masonry.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/templates/grid/masonry.html b/app/code/Magento/Ui/view/base/web/templates/grid/masonry.html index 788cb0c2b5e56..089ee21bec15c 100644 --- a/app/code/Magento/Ui/view/base/web/templates/grid/masonry.html +++ b/app/code/Magento/Ui/view/base/web/templates/grid/masonry.html @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ --> -<div data-role="grid-wrapper" class="masonry-image-grid" attr="'data-id': containerId" tabindex="0"> +<div data-role="grid-wrapper" class="masonry-image-grid" attr="'data-id': containerId"> <div class="masonry-image-column" repeat="foreach: rows, item: '$row'"> <div outerfasteach="data: getVisible(), as: '$col'" template="getBody()"/> </div> From 4b069f6772badc952dc990c98df607184aa003ce Mon Sep 17 00:00:00 2001 From: Vadim Malesh <51680850+engcom-Charlie@users.noreply.github.com> Date: Tue, 3 Mar 2020 13:56:06 +0200 Subject: [PATCH 23/27] Update app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php --- .../Block/Adminhtml/System/Config/CollectionTimeLabel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php index 62ef86c7dafb5..664278debd655 100644 --- a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php +++ b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php @@ -43,7 +43,7 @@ public function __construct( * * @return string */ - public function render(AbstractElement $element) + public function render(AbstractElement $element): string { $timeZoneCode = $this->_localeDate->getConfigTimezone(); $locale = $this->localeResolver->getLocale(); From 25989946b2a32204516a43ad491c69252e441ef2 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk <grp-engcom-vendorworker-Kilo@adobe.com> Date: Thu, 27 Feb 2020 15:55:55 +0200 Subject: [PATCH 24/27] magento2/pull/26939: Fixed static test. --- .../Block/System/Messages.php | 3 +++ .../Adminhtml/Notification/AjaxMarkAsRead.php | 7 ++++-- .../Adminhtml/Notification/MarkAsRead.php | 20 +++++++++++----- .../Adminhtml/Notification/MassMarkAsRead.php | 17 ++++++++++---- .../Adminhtml/Notification/MassRemove.php | 17 ++++++++++---- .../Adminhtml/Notification/Remove.php | 23 ++++++++++++------- .../Notification/MassMarkAsReadTest.php | 3 +++ .../Adminhtml/Notification/MassRemoveTest.php | 3 +++ 8 files changed, 69 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/AdminNotification/Block/System/Messages.php b/app/code/Magento/AdminNotification/Block/System/Messages.php index 318b8f8384e2e..c9b3a0b8844cc 100644 --- a/app/code/Magento/AdminNotification/Block/System/Messages.php +++ b/app/code/Magento/AdminNotification/Block/System/Messages.php @@ -12,6 +12,9 @@ use Magento\Framework\Notification\MessageInterface; use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; +/** + * AdminNotification Messages class + */ class Messages extends Template { /** diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php index e05de78c92356..be128435b62a1 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,9 +8,13 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\NotificationService; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; -class AjaxMarkAsRead extends Notification +/** + * AdminNotification AjaxMarkAsRead controller + */ +class AjaxMarkAsRead extends Notification implements HttpPostActionInterface { /** * @var NotificationService diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php index 6dd40b56e0a24..b1bfddc2ea67f 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,9 +8,13 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\NotificationService; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\Exception\LocalizedException; -class MarkAsRead extends Notification +/** + * AdminNotification MarkAsRead controller + */ +class MarkAsRead extends Notification implements HttpGetActionInterface { /** * Authorization level of a basic admin session @@ -25,6 +28,10 @@ class MarkAsRead extends Notification */ private $notificationService; + /** + * @param Action\Context $context + * @param NotificationService $notificationService + */ public function __construct(Action\Context $context, NotificationService $notificationService) { parent::__construct($context); @@ -32,7 +39,9 @@ public function __construct(Action\Context $context, NotificationService $notifi } /** - * @return void + * @inheritdoc + * + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -50,9 +59,8 @@ public function execute() ); } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); - return; + return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php index e73f4219b7333..9d052e8474dd9 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,8 +8,12 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; -class MassMarkAsRead extends Notification +/** + * AdminNotification MassMarkAsRead controller + */ +class MassMarkAsRead extends Notification implements HttpPostActionInterface { /** * Authorization level of a basic admin session @@ -24,6 +27,10 @@ class MassMarkAsRead extends Notification */ private $inboxModelFactory; + /** + * @param Action\Context $context + * @param InboxModelFactory $inboxModelFactory + */ public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) { parent::__construct($context); @@ -31,7 +38,9 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod } /** - * @return void + * @inheritdoc + * + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -58,6 +67,6 @@ public function execute() ); } } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php index a248430b5660c..3f6575cdd4c67 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,8 +8,12 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; -class MassRemove extends Notification +/** + * AdminNotification MassRemove controller + */ +class MassRemove extends Notification implements HttpPostActionInterface { /** @@ -24,6 +27,10 @@ class MassRemove extends Notification */ private $inboxModelFactory; + /** + * @param Action\Context $context + * @param InboxModelFactory $inboxModelFactory + */ public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) { parent::__construct($context); @@ -31,7 +38,9 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod } /** - * @return void + * @inheritdoc + * + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -56,6 +65,6 @@ public function execute() ); } } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php index 0d74db43eef2b..39c563e8c1b29 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,8 +8,12 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; -class Remove extends Notification +/** + * AdminNotification Remove controller + */ +class Remove extends Notification implements HttpGetActionInterface { /** * Authorization level of a basic admin session @@ -24,6 +27,10 @@ class Remove extends Notification */ private $inboxModelFactory; + /** + * @param Action\Context $context + * @param InboxModelFactory $inboxModelFactory + */ public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) { parent::__construct($context); @@ -31,7 +38,9 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod } /** - * @return void + * @inheritdoc + * + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -39,8 +48,7 @@ public function execute() $model = $this->inboxModelFactory->create()->load($id); if (!$model->getId()) { - $this->_redirect('adminhtml/*/'); - return; + return $this->_redirect('adminhtml/*/'); } try { @@ -55,9 +63,8 @@ public function execute() ); } - $this->_redirect('adminhtml/*/'); - return; + return $this->_redirect('adminhtml/*/'); } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php index c611d6fd7289f..04a69fe200dd1 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php +++ b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php @@ -5,12 +5,15 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\Framework\App\Request\Http as HttpRequest; + class MassMarkAsReadTest extends \Magento\TestFramework\TestCase\AbstractBackendController { public function setUp() { $this->resource = 'Magento_AdminNotification::mark_as_read'; $this->uri = 'backend/admin/notification/massmarkasread'; + $this->httpMethod = HttpRequest::METHOD_POST; parent::setUp(); } } diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php index f05985015833a..55ee6a58063a4 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php +++ b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php @@ -5,12 +5,15 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\Framework\App\Request\Http as HttpRequest; + class MassRemoveTest extends \Magento\TestFramework\TestCase\AbstractBackendController { public function setUp() { $this->resource = 'Magento_AdminNotification::adminnotification_remove'; $this->uri = 'backend/admin/notification/massremove'; + $this->httpMethod = HttpRequest::METHOD_POST; parent::setUp(); } } From 57af3d7395f1b2dbea7aa33758040f9cf25566ce Mon Sep 17 00:00:00 2001 From: Alexander Steshuk <grp-engcom-vendorworker-Kilo@adobe.com> Date: Thu, 27 Feb 2020 15:55:55 +0200 Subject: [PATCH 25/27] magento2/pull/26939: Fixed static test. --- .../Block/System/Messages.php | 3 +++ .../Adminhtml/Notification/AjaxMarkAsRead.php | 7 +++++-- .../Adminhtml/Notification/MarkAsRead.php | 18 ++++++++++------ .../Adminhtml/Notification/MassMarkAsRead.php | 15 +++++++++---- .../Adminhtml/Notification/MassRemove.php | 15 +++++++++---- .../Adminhtml/Notification/Remove.php | 21 ++++++++++++------- .../Notification/MassMarkAsReadTest.php | 3 +++ .../Adminhtml/Notification/MassRemoveTest.php | 3 +++ 8 files changed, 61 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/AdminNotification/Block/System/Messages.php b/app/code/Magento/AdminNotification/Block/System/Messages.php index 318b8f8384e2e..c9b3a0b8844cc 100644 --- a/app/code/Magento/AdminNotification/Block/System/Messages.php +++ b/app/code/Magento/AdminNotification/Block/System/Messages.php @@ -12,6 +12,9 @@ use Magento\Framework\Notification\MessageInterface; use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; +/** + * AdminNotification Messages class + */ class Messages extends Template { /** diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php index e05de78c92356..be128435b62a1 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,9 +8,13 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\NotificationService; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; -class AjaxMarkAsRead extends Notification +/** + * AdminNotification AjaxMarkAsRead controller + */ +class AjaxMarkAsRead extends Notification implements HttpPostActionInterface { /** * @var NotificationService diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php index 6dd40b56e0a24..7b3f99ae8e2c1 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,9 +8,13 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\NotificationService; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\Exception\LocalizedException; -class MarkAsRead extends Notification +/** + * AdminNotification MarkAsRead controller + */ +class MarkAsRead extends Notification implements HttpGetActionInterface { /** * Authorization level of a basic admin session @@ -25,6 +28,10 @@ class MarkAsRead extends Notification */ private $notificationService; + /** + * @param Action\Context $context + * @param NotificationService $notificationService + */ public function __construct(Action\Context $context, NotificationService $notificationService) { parent::__construct($context); @@ -32,7 +39,7 @@ public function __construct(Action\Context $context, NotificationService $notifi } /** - * @return void + * @inheritdoc */ public function execute() { @@ -50,9 +57,8 @@ public function execute() ); } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); - return; + return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php index e73f4219b7333..12198d05f6ae7 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,8 +8,12 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; -class MassMarkAsRead extends Notification +/** + * AdminNotification MassMarkAsRead controller + */ +class MassMarkAsRead extends Notification implements HttpPostActionInterface { /** * Authorization level of a basic admin session @@ -24,6 +27,10 @@ class MassMarkAsRead extends Notification */ private $inboxModelFactory; + /** + * @param Action\Context $context + * @param InboxModelFactory $inboxModelFactory + */ public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) { parent::__construct($context); @@ -31,7 +38,7 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod } /** - * @return void + * @inheritdoc */ public function execute() { @@ -58,6 +65,6 @@ public function execute() ); } } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php index a248430b5660c..0ca114ac4021c 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,8 +8,12 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; -class MassRemove extends Notification +/** + * AdminNotification MassRemove controller + */ +class MassRemove extends Notification implements HttpPostActionInterface { /** @@ -24,6 +27,10 @@ class MassRemove extends Notification */ private $inboxModelFactory; + /** + * @param Action\Context $context + * @param InboxModelFactory $inboxModelFactory + */ public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) { parent::__construct($context); @@ -31,7 +38,7 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod } /** - * @return void + * @inheritdoc */ public function execute() { @@ -56,6 +63,6 @@ public function execute() ); } } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php index 0d74db43eef2b..fe699cd692160 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -9,8 +8,12 @@ use Magento\AdminNotification\Controller\Adminhtml\Notification; use Magento\AdminNotification\Model\InboxFactory as InboxModelFactory; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; -class Remove extends Notification +/** + * AdminNotification Remove controller + */ +class Remove extends Notification implements HttpGetActionInterface { /** * Authorization level of a basic admin session @@ -24,6 +27,10 @@ class Remove extends Notification */ private $inboxModelFactory; + /** + * @param Action\Context $context + * @param InboxModelFactory $inboxModelFactory + */ public function __construct(Action\Context $context, InboxModelFactory $inboxModelFactory) { parent::__construct($context); @@ -31,7 +38,7 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod } /** - * @return void + * @inheritdoc */ public function execute() { @@ -39,8 +46,7 @@ public function execute() $model = $this->inboxModelFactory->create()->load($id); if (!$model->getId()) { - $this->_redirect('adminhtml/*/'); - return; + return $this->_redirect('adminhtml/*/'); } try { @@ -55,9 +61,8 @@ public function execute() ); } - $this->_redirect('adminhtml/*/'); - return; + return $this->_redirect('adminhtml/*/'); } - $this->_redirect('adminhtml/*/'); + return $this->_redirect('adminhtml/*/'); } } diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php index c611d6fd7289f..04a69fe200dd1 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php +++ b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php @@ -5,12 +5,15 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\Framework\App\Request\Http as HttpRequest; + class MassMarkAsReadTest extends \Magento\TestFramework\TestCase\AbstractBackendController { public function setUp() { $this->resource = 'Magento_AdminNotification::mark_as_read'; $this->uri = 'backend/admin/notification/massmarkasread'; + $this->httpMethod = HttpRequest::METHOD_POST; parent::setUp(); } } diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php index f05985015833a..55ee6a58063a4 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php +++ b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php @@ -5,12 +5,15 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; +use Magento\Framework\App\Request\Http as HttpRequest; + class MassRemoveTest extends \Magento\TestFramework\TestCase\AbstractBackendController { public function setUp() { $this->resource = 'Magento_AdminNotification::adminnotification_remove'; $this->uri = 'backend/admin/notification/massremove'; + $this->httpMethod = HttpRequest::METHOD_POST; parent::setUp(); } } From b7c1d0467cee29fa80b81d6cd20307a3dc8eed78 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk <grp-engcom-vendorworker-Kilo@adobe.com> Date: Tue, 3 Mar 2020 16:42:06 +0200 Subject: [PATCH 26/27] magento2/pull/26939: Fixed static test. --- .../Controller/Adminhtml/Notification/MarkAsRead.php | 2 -- .../Controller/Adminhtml/Notification/MassMarkAsRead.php | 2 -- .../Controller/Adminhtml/Notification/MassRemove.php | 2 -- .../Controller/Adminhtml/Notification/Remove.php | 2 -- 4 files changed, 8 deletions(-) diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php index b1bfddc2ea67f..7b3f99ae8e2c1 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsRead.php @@ -40,8 +40,6 @@ public function __construct(Action\Context $context, NotificationService $notifi /** * @inheritdoc - * - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php index 9d052e8474dd9..12198d05f6ae7 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsRead.php @@ -39,8 +39,6 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod /** * @inheritdoc - * - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php index 3f6575cdd4c67..0ca114ac4021c 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php @@ -39,8 +39,6 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod /** * @inheritdoc - * - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php index 39c563e8c1b29..fe699cd692160 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Remove.php @@ -39,8 +39,6 @@ public function __construct(Action\Context $context, InboxModelFactory $inboxMod /** * @inheritdoc - * - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface */ public function execute() { From bbee9822e5810faf730c5fd0572db7ed36a39b32 Mon Sep 17 00:00:00 2001 From: Slava Mankivski <mankivsk@adobe.com> Date: Mon, 9 Mar 2020 11:18:46 -0500 Subject: [PATCH 27/27] Fixed docblock --- app/code/Magento/Cms/Helper/Wysiwyg/Images.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php index c634910f4468f..e42bb0143f6bf 100644 --- a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php @@ -253,6 +253,12 @@ public function getCurrentPath() return $this->_currentPath; } + /** + * Create subdirectory if doesn't exist + * + * @param string $absPath Path of subdirectory to create + * @throws \Magento\Framework\Exception\LocalizedException + */ private function createSubDirIfNotExist(string $absPath) { $relPath = $this->_directory->getRelativePath($absPath);