From 42d2163e2d0afa261411ae174b6fca23fe189045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tylek?= Date: Tue, 29 Oct 2019 15:52:51 +0100 Subject: [PATCH 01/19] M2C-2205 Move LESS styling files --- .../Magento/backend/Magento_Contact}/web/css/source/_module.less | 0 .../Magento/blank/Magento_Contact}/web/css/source/_module.less | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename app/{code/Magento/Cms/view/adminhtml => design/adminhtml/Magento/backend/Magento_Contact}/web/css/source/_module.less (100%) rename app/{code/Magento/Contact/view/frontend => design/frontend/Magento/blank/Magento_Contact}/web/css/source/_module.less (100%) diff --git a/app/code/Magento/Cms/view/adminhtml/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Contact/web/css/source/_module.less similarity index 100% rename from app/code/Magento/Cms/view/adminhtml/web/css/source/_module.less rename to app/design/adminhtml/Magento/backend/Magento_Contact/web/css/source/_module.less diff --git a/app/code/Magento/Contact/view/frontend/web/css/source/_module.less b/app/design/frontend/Magento/blank/Magento_Contact/web/css/source/_module.less similarity index 100% rename from app/code/Magento/Contact/view/frontend/web/css/source/_module.less rename to app/design/frontend/Magento/blank/Magento_Contact/web/css/source/_module.less From 2c6ad75fc12645c8d6a13ebd3c66bb4fbae18da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tylek?= Date: Wed, 30 Oct 2019 10:30:03 +0100 Subject: [PATCH 02/19] M2C-2205 Move Magento_Cms to its proper directory --- .../{Magento_Contact => Magento_Cms}/web/css/source/_module.less | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/design/adminhtml/Magento/backend/{Magento_Contact => Magento_Cms}/web/css/source/_module.less (100%) diff --git a/app/design/adminhtml/Magento/backend/Magento_Contact/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Cms/web/css/source/_module.less similarity index 100% rename from app/design/adminhtml/Magento/backend/Magento_Contact/web/css/source/_module.less rename to app/design/adminhtml/Magento/backend/Magento_Cms/web/css/source/_module.less From e6e6769531c7ff689f56376697fa7e7af5117c4e Mon Sep 17 00:00:00 2001 From: Evgenii Kalashnikov Date: Sun, 10 Nov 2019 12:42:03 +0300 Subject: [PATCH 03/19] upload media files fix --- .../CatalogImportExport/Model/Import/Product.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 9ff2edaf2708f..0b13b93ee79f8 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -1198,7 +1198,7 @@ protected function _initTypeModels() // phpcs:disable Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge $this->_fieldsMap = array_merge($this->_fieldsMap, $model->getCustomFieldsMapping()); $this->_specialAttributes = array_merge($this->_specialAttributes, $model->getParticularAttributes()); - // phpcs:enable + // phpcs:enable } $this->_initErrorTemplates(); // remove doubles @@ -2035,9 +2035,9 @@ protected function _saveProductTierPrices(array $tierPriceData) protected function _getUploader() { if ($this->_fileUploader === null) { - $this->_fileUploader = $this->_uploaderFactory->create(); + $fileUploader = $this->_uploaderFactory->create(); - $this->_fileUploader->init(); + $fileUploader->init(); $dirConfig = DirectoryList::getDefaultConfig(); $dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH]; @@ -2048,7 +2048,7 @@ protected function _getUploader() $tmpPath = $dirAddon . '/' . $this->_mediaDirectory->getRelativePath('import'); } - if (!$this->_fileUploader->setTmpDir($tmpPath)) { + if (!$fileUploader->setTmpDir($tmpPath)) { throw new LocalizedException( __('File directory \'%1\' is not readable.', $tmpPath) ); @@ -2057,11 +2057,13 @@ protected function _getUploader() $destinationPath = $dirAddon . '/' . $this->_mediaDirectory->getRelativePath($destinationDir); $this->_mediaDirectory->create($destinationPath); - if (!$this->_fileUploader->setDestDir($destinationPath)) { + if (!$fileUploader->setDestDir($destinationPath)) { throw new LocalizedException( __('File directory \'%1\' is not writable.', $destinationPath) ); } + + $this->_fileUploader = $fileUploader; } return $this->_fileUploader; } From 5c3424f781c7767cc1d6c581e847a008a59fa3cf Mon Sep 17 00:00:00 2001 From: Alexander Shkurko Date: Sun, 10 Nov 2019 12:19:54 +0200 Subject: [PATCH 04/19] 585: cover with unit test the GetById media asset command --- .../Model/Asset/Command/GetById.php | 5 +- .../Unit/Model/Asset/Command/GetByIdTest.php | 119 ++++++++++++++++++ 2 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index 4519e0f926981..0ffeb206beb54 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -66,9 +66,10 @@ public function __construct( public function execute(int $mediaAssetId): AssetInterface { try { + $mediaAssetTable = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); $connection = $this->resourceConnection->getConnection(); $select = $connection->select() - ->from(['amg' => $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET)]) + ->from(['amg' => $mediaAssetTable]) ->where('amg.id = ?', $mediaAssetId); $data = $connection->query($select)->fetch(); @@ -80,7 +81,7 @@ public function execute(int $mediaAssetId): AssetInterface return $this->assetFactory->create(['data' => $data]); } catch (\Exception $exception) { $message = __( - 'En error occurred during get media asset with id %id by id: %error', + 'En error occurred during get media asset with id %id: %error', ['id' => $mediaAssetId, 'error' => $exception->getMessage()] ); $this->logger->critical($message); diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php new file mode 100644 index 0000000000000..2e25dc7c4df09 --- /dev/null +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php @@ -0,0 +1,119 @@ + 1]; + + /** + * @var GetById|MockObject + */ + private $getMediaAssetById; + + /** + * @var AssetInterfaceFactory|MockObject + */ + private $assetFactory; + + /** + * @var AdapterInterface|MockObject + */ + private $adapter; + + /** + * @var Select|MockObject + */ + private $selectStub; + + /** + * @var Statement|MockObject + */ + private $statementMock; + + /** + * @var LoggerInterface|MockObject + */ + private $logger; + + /** + * Initialize basic test class mocks + */ + protected function setUp(): void + { + $resourceConnection = $this->createMock(ResourceConnection::class); + $this->assetFactory = $this->createMock(AssetInterfaceFactory::class); + $this->logger = $this->createMock(LoggerInterface::class); + + $this->getMediaAssetById = (new ObjectManager($this))->getObject( + GetById::class, + [ + 'resourceConnection' => $resourceConnection, + 'assetFactory' => $this->assetFactory, + 'logger' => $this->logger, + ] + ); + $this->adapter = $this->createMock(AdapterInterface::class); + $resourceConnection->method('getConnection')->willReturn($this->adapter); + + $this->selectStub = $this->createMock(Select::class); + $this->selectStub->method('from')->willReturnSelf(); + $this->selectStub->method('where')->willReturnSelf(); + $this->adapter->method('select')->willReturn($this->selectStub); + + $this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock(); + } + + /** + * Test successful get media asset by id command execution. + */ + public function testSuccessfulGetByIdExecution(): void + { + $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); + $this->adapter->method('query')->willReturn($this->statementMock); + + $mediaAssetStub = $this->getMockBuilder(AssetInterface::class)->getMock(); + $this->assetFactory->expects($this->once())->method('create')->willReturn($mediaAssetStub); + + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); + } + + /** + * Test case when there is no found media asset by id. + */ + public function testNotFoundMediaAssetException(): void + { + $this->statementMock->method('fetch')->willReturn([]); + $this->adapter->method('query')->willReturn($this->statementMock); + + $this->expectException(IntegrationException::class); + $this->logger->expects($this->once()) + ->method('critical') + ->willReturnSelf(); + + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); + } +} From d08eb4494b8bd9539d4f48cf171865dc924a2030 Mon Sep 17 00:00:00 2001 From: Alexander Shkurko Date: Sun, 10 Nov 2019 20:16:47 +0200 Subject: [PATCH 05/19] Change the GetById command execution logic and cover with tests --- .../Model/Asset/Command/GetById.php | 31 ++++++++++------ .../Unit/Model/Asset/Command/GetByIdTest.php | 35 ++++++++++++++++++- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index 0ffeb206beb54..cdb0f8587f8bc 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -7,12 +7,12 @@ namespace Magento\MediaGallery\Model\Asset\Command; -use Magento\MediaGalleryApi\Api\Data\AssetInterface; -use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; -use Magento\MediaGalleryApi\Model\Asset\Command\GetByIdInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\IntegrationException; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\MediaGalleryApi\Api\Data\AssetInterface; +use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; +use Magento\MediaGalleryApi\Model\Asset\Command\GetByIdInterface; use Psr\Log\LoggerInterface; /** @@ -71,20 +71,29 @@ public function execute(int $mediaAssetId): AssetInterface $select = $connection->select() ->from(['amg' => $mediaAssetTable]) ->where('amg.id = ?', $mediaAssetId); - $data = $connection->query($select)->fetch(); + $mediaAssetData = $connection->query($select)->fetch(); + } catch (\Exception $exception) { + $message = __( + 'En error occurred during get media asset data by id %id: %error', + ['id' => $mediaAssetId, 'error' => $exception->getMessage()] + ); + $this->logger->critical($message); + throw new IntegrationException($message, $exception); + } - if (empty($data)) { - $message = __('There is no such media asset with id "%1"', $mediaAssetId); - throw new NoSuchEntityException($message); - } + if (empty($mediaAssetData)) { + $message = __('There is no such media asset with id "%1"', $mediaAssetId); + throw new NoSuchEntityException($message); + } - return $this->assetFactory->create(['data' => $data]); + try { + return $this->assetFactory->create(['data' => $mediaAssetData]); } catch (\Exception $exception) { + $this->logger->critical($exception->getMessage()); $message = __( - 'En error occurred during get media asset with id %id: %error', + 'En error occurred during initialize media asset with id %id: %error', ['id' => $mediaAssetId, 'error' => $exception->getMessage()] ); - $this->logger->critical($message); throw new IntegrationException($message, $exception); } } diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php index 2e25dc7c4df09..eb9d3c80039e9 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php @@ -11,6 +11,7 @@ use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Select; use Magento\Framework\Exception\IntegrationException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\MediaGallery\Model\Asset\Command\GetById; use Magento\MediaGalleryApi\Api\Data\AssetInterface; @@ -22,6 +23,7 @@ /** * Test the GetById command model + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class GetByIdTest extends TestCase { @@ -98,6 +100,22 @@ public function testSuccessfulGetByIdExecution(): void $mediaAssetStub = $this->getMockBuilder(AssetInterface::class)->getMock(); $this->assetFactory->expects($this->once())->method('create')->willReturn($mediaAssetStub); + $this->assertEquals( + $mediaAssetStub, + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID) + ); + } + + /** + * Test an exception during the get asset data query. + */ + public function testExceptionDuringGetMediaAssetData(): void + { + $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); + $this->adapter->method('query')->willThrowException(new \Exception()); + + $this->expectException(IntegrationException::class); + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); } @@ -109,8 +127,23 @@ public function testNotFoundMediaAssetException(): void $this->statementMock->method('fetch')->willReturn([]); $this->adapter->method('query')->willReturn($this->statementMock); + $this->expectException(NoSuchEntityException::class); + + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); + } + + /** + * Test case when a problem occurred during asset initialization from received data. + */ + public function testErrorDuringMediaAssetInitializationException(): void + { + $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); + $this->adapter->method('query')->willReturn($this->statementMock); + + $this->assetFactory->expects($this->once())->method('create')->willThrowException(new \Exception()); + $this->expectException(IntegrationException::class); - $this->logger->expects($this->once()) + $this->logger->expects($this->any()) ->method('critical') ->willReturnSelf(); From b0fb36394eaca8f656c61d3c2e24f27ac5c35e33 Mon Sep 17 00:00:00 2001 From: Alexander Shkurko Date: Tue, 12 Nov 2019 15:51:48 +0200 Subject: [PATCH 06/19] Change the way the GetById command is tested --- ...ionDuringMediaAssetInitializationTest.php} | 51 +-------- .../GetByIdExceptionNoSuchEntityTest.php | 100 ++++++++++++++++++ .../Command/GetByIdExceptionOnGetDataTest.php | 89 ++++++++++++++++ .../Asset/Command/GetByIdSuccessfulTest.php | 99 +++++++++++++++++ 4 files changed, 290 insertions(+), 49 deletions(-) rename app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/{GetByIdTest.php => GetByIdExceptionDuringMediaAssetInitializationTest.php} (63%) create mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php create mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php create mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php similarity index 63% rename from app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php rename to app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php index eb9d3c80039e9..bb586db60dad8 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php @@ -11,21 +11,17 @@ use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Select; use Magento\Framework\Exception\IntegrationException; -use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\MediaGallery\Model\Asset\Command\GetById; -use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Zend\Db\Adapter\Driver\Pdo\Statement; /** - * Test the GetById command model - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * Test the GetById command model with exception during media asset initialization */ -class GetByIdTest extends TestCase +class GetByIdExceptionDuringMediaAssetInitializationTest extends \PHPUnit\Framework\TestCase { private const MEDIA_ASSET_STUB_ID = 1; @@ -89,49 +85,6 @@ protected function setUp(): void $this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock(); } - /** - * Test successful get media asset by id command execution. - */ - public function testSuccessfulGetByIdExecution(): void - { - $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); - $this->adapter->method('query')->willReturn($this->statementMock); - - $mediaAssetStub = $this->getMockBuilder(AssetInterface::class)->getMock(); - $this->assetFactory->expects($this->once())->method('create')->willReturn($mediaAssetStub); - - $this->assertEquals( - $mediaAssetStub, - $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID) - ); - } - - /** - * Test an exception during the get asset data query. - */ - public function testExceptionDuringGetMediaAssetData(): void - { - $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); - $this->adapter->method('query')->willThrowException(new \Exception()); - - $this->expectException(IntegrationException::class); - - $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); - } - - /** - * Test case when there is no found media asset by id. - */ - public function testNotFoundMediaAssetException(): void - { - $this->statementMock->method('fetch')->willReturn([]); - $this->adapter->method('query')->willReturn($this->statementMock); - - $this->expectException(NoSuchEntityException::class); - - $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); - } - /** * Test case when a problem occurred during asset initialization from received data. */ diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php new file mode 100644 index 0000000000000..d6df9ca422e06 --- /dev/null +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php @@ -0,0 +1,100 @@ + 1]; + + /** + * @var GetById|MockObject + */ + private $getMediaAssetById; + + /** + * @var AssetInterfaceFactory|MockObject + */ + private $assetFactory; + + /** + * @var AdapterInterface|MockObject + */ + private $adapter; + + /** + * @var Select|MockObject + */ + private $selectStub; + + /** + * @var Statement|MockObject + */ + private $statementMock; + + /** + * @var LoggerInterface|MockObject + */ + private $logger; + + /** + * Initialize basic test class mocks + */ + protected function setUp(): void + { + $resourceConnection = $this->createMock(ResourceConnection::class); + $this->assetFactory = $this->createMock(AssetInterfaceFactory::class); + $this->logger = $this->createMock(LoggerInterface::class); + + $this->getMediaAssetById = (new ObjectManager($this))->getObject( + GetById::class, + [ + 'resourceConnection' => $resourceConnection, + 'assetFactory' => $this->assetFactory, + 'logger' => $this->logger, + ] + ); + $this->adapter = $this->createMock(AdapterInterface::class); + $resourceConnection->method('getConnection')->willReturn($this->adapter); + + $this->selectStub = $this->createMock(Select::class); + $this->selectStub->method('from')->willReturnSelf(); + $this->selectStub->method('where')->willReturnSelf(); + $this->adapter->method('select')->willReturn($this->selectStub); + + $this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock(); + } + + /** + * Test case when there is no found media asset by id. + */ + public function testNotFoundMediaAssetException(): void + { + $this->statementMock->method('fetch')->willReturn([]); + $this->adapter->method('query')->willReturn($this->statementMock); + + $this->expectException(NoSuchEntityException::class); + + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); + } +} diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php new file mode 100644 index 0000000000000..958a5f3ccb609 --- /dev/null +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php @@ -0,0 +1,89 @@ + 1]; + + /** + * @var GetById|MockObject + */ + private $getMediaAssetById; + /** + * @var AdapterInterface|MockObject + */ + private $adapter; + + /** + * @var Select|MockObject + */ + private $selectStub; + + /** + * @var Statement|MockObject + */ + private $statementMock; + + /** + * Initialize basic test class mocks + */ + protected function setUp(): void + { + $resourceConnection = $this->createMock(ResourceConnection::class); + $assetFactory = $this->createMock(AssetInterfaceFactory::class); + $logger = $this->createMock(LoggerInterface::class); + + $this->getMediaAssetById = (new ObjectManager($this))->getObject( + GetById::class, + [ + 'resourceConnection' => $resourceConnection, + 'assetFactory' => $assetFactory, + 'logger' => $logger, + ] + ); + $this->adapter = $this->createMock(AdapterInterface::class); + $resourceConnection->method('getConnection')->willReturn($this->adapter); + + $this->selectStub = $this->createMock(Select::class); + $this->selectStub->method('from')->willReturnSelf(); + $this->selectStub->method('where')->willReturnSelf(); + $this->adapter->method('select')->willReturn($this->selectStub); + + $this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock(); + } + + /** + * Test an exception during the get asset data query. + */ + public function testExceptionDuringGetMediaAssetData(): void + { + $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); + $this->adapter->method('query')->willThrowException(new \Exception()); + + $this->expectException(IntegrationException::class); + + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); + } +} diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php new file mode 100644 index 0000000000000..72e44027469cd --- /dev/null +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php @@ -0,0 +1,99 @@ + 1]; + + /** + * @var GetById|MockObject + */ + private $getMediaAssetById; + + /** + * @var AssetInterfaceFactory|MockObject + */ + private $assetFactory; + + /** + * @var AdapterInterface|MockObject + */ + private $adapter; + + /** + * @var Select|MockObject + */ + private $selectStub; + + /** + * @var Statement|MockObject + */ + private $statementMock; + + /** + * Initialize basic test class mocks + */ + protected function setUp(): void + { + $resourceConnection = $this->createMock(ResourceConnection::class); + $this->assetFactory = $this->createMock(AssetInterfaceFactory::class); + $logger = $this->createMock(LoggerInterface::class); + + $this->getMediaAssetById = (new ObjectManager($this))->getObject( + GetById::class, + [ + 'resourceConnection' => $resourceConnection, + 'assetFactory' => $this->assetFactory, + 'logger' => $logger, + ] + ); + $this->adapter = $this->createMock(AdapterInterface::class); + $resourceConnection->method('getConnection')->willReturn($this->adapter); + + $this->selectStub = $this->createMock(Select::class); + $this->selectStub->method('from')->willReturnSelf(); + $this->selectStub->method('where')->willReturnSelf(); + $this->adapter->method('select')->willReturn($this->selectStub); + + $this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock(); + } + + /** + * Test successful get media asset by id command execution. + */ + public function testSuccessfulGetByIdExecution(): void + { + $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); + $this->adapter->method('query')->willReturn($this->statementMock); + + $mediaAssetStub = $this->getMockBuilder(AssetInterface::class)->getMock(); + $this->assetFactory->expects($this->once())->method('create')->willReturn($mediaAssetStub); + + $this->assertEquals( + $mediaAssetStub, + $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID) + ); + } +} From 061d5a31391088b058f1735872c0895b9c5098b9 Mon Sep 17 00:00:00 2001 From: Alexander Shkurko Date: Wed, 13 Nov 2019 16:29:14 +0200 Subject: [PATCH 07/19] Change the way the setup method is called for GetById command test --- ...IdExceptionDuringMediaAssetInitializationTest.php | 2 +- .../Command/GetByIdExceptionNoSuchEntityTest.php | 9 ++------- .../Asset/Command/GetByIdExceptionOnGetDataTest.php | 12 ++++++++++-- .../Model/Asset/Command/GetByIdSuccessfulTest.php | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php index bb586db60dad8..0d0bfc510b518 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php @@ -19,7 +19,7 @@ use Zend\Db\Adapter\Driver\Pdo\Statement; /** - * Test the GetById command model with exception during media asset initialization + * Test the GetById command with exception during media asset initialization */ class GetByIdExceptionDuringMediaAssetInitializationTest extends \PHPUnit\Framework\TestCase { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php index d6df9ca422e06..52d1c3f82f8f3 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php @@ -52,11 +52,6 @@ class GetByIdExceptionNoSuchEntityTest extends \PHPUnit\Framework\TestCase */ private $statementMock; - /** - * @var LoggerInterface|MockObject - */ - private $logger; - /** * Initialize basic test class mocks */ @@ -64,14 +59,14 @@ protected function setUp(): void { $resourceConnection = $this->createMock(ResourceConnection::class); $this->assetFactory = $this->createMock(AssetInterfaceFactory::class); - $this->logger = $this->createMock(LoggerInterface::class); + $logger = $this->createMock(LoggerInterface::class); $this->getMediaAssetById = (new ObjectManager($this))->getObject( GetById::class, [ 'resourceConnection' => $resourceConnection, 'assetFactory' => $this->assetFactory, - 'logger' => $this->logger, + 'logger' => $logger, ] ); $this->adapter = $this->createMock(AdapterInterface::class); diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php index 958a5f3ccb609..a709c2d214bda 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php @@ -41,6 +41,11 @@ class GetByIdExceptionOnGetDataTest extends \PHPUnit\Framework\TestCase */ private $selectStub; + /** + * @var LoggerInterface|MockObject + */ + private $logger; + /** * @var Statement|MockObject */ @@ -53,14 +58,14 @@ protected function setUp(): void { $resourceConnection = $this->createMock(ResourceConnection::class); $assetFactory = $this->createMock(AssetInterfaceFactory::class); - $logger = $this->createMock(LoggerInterface::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->getMediaAssetById = (new ObjectManager($this))->getObject( GetById::class, [ 'resourceConnection' => $resourceConnection, 'assetFactory' => $assetFactory, - 'logger' => $logger, + 'logger' => $this->logger, ] ); $this->adapter = $this->createMock(AdapterInterface::class); @@ -83,6 +88,9 @@ public function testExceptionDuringGetMediaAssetData(): void $this->adapter->method('query')->willThrowException(new \Exception()); $this->expectException(IntegrationException::class); + $this->logger->expects($this->any()) + ->method('critical') + ->willReturnSelf(); $this->getMediaAssetById->execute(self::MEDIA_ASSET_STUB_ID); } diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php index 72e44027469cd..c300d4f121bd2 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php @@ -19,9 +19,9 @@ use Zend\Db\Adapter\Driver\Pdo\Statement; /** - * Test the GetById command model + * Test the GetById command successful scenario */ -class GetByIdTest extends \PHPUnit\Framework\TestCase +class GetByIdSuccessfulTest extends \PHPUnit\Framework\TestCase { private const MEDIA_ASSET_STUB_ID = 1; From c2209fb509134062507130d47154394ef786403d Mon Sep 17 00:00:00 2001 From: Alexander Shkurko Date: Wed, 13 Nov 2019 16:33:01 +0200 Subject: [PATCH 08/19] Remove not used const --- .../Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php index 52d1c3f82f8f3..0ca9b3a3ffc8a 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php @@ -25,8 +25,6 @@ class GetByIdExceptionNoSuchEntityTest extends \PHPUnit\Framework\TestCase { private const MEDIA_ASSET_STUB_ID = 1; - private const MEDIA_ASSET_DATA = ['id' => 1]; - /** * @var GetById|MockObject */ From 16fa4c4a6d4fd2e49cfbecef7a3fae11f18613cc Mon Sep 17 00:00:00 2001 From: Fabricio Sobral Date: Thu, 14 Nov 2019 20:50:50 -0300 Subject: [PATCH 09/19] changes in menujs file into iu module --- lib/web/jquery/ui-modules/menu.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/web/jquery/ui-modules/menu.js b/lib/web/jquery/ui-modules/menu.js index 6d575b0462a9d..82a9b54f69e46 100644 --- a/lib/web/jquery/ui-modules/menu.js +++ b/lib/web/jquery/ui-modules/menu.js @@ -440,10 +440,7 @@ define([ return; } - this.timer = this._delay(function () { - this._close(); - this._open(submenu); - }, this.delay); + this._open(submenu); }, _open: function (submenu) { From d0167a0029358c0324abdf3a8f6313bf66cff2ff Mon Sep 17 00:00:00 2001 From: Fabricio Sobral Date: Fri, 15 Nov 2019 23:59:29 -0300 Subject: [PATCH 10/19] fixed resize logo mobile --- .../Magento/blank/Magento_Theme/web/css/source/_module.less | 1 + .../Magento/luma/Magento_Theme/web/css/source/_module.less | 1 + 2 files changed, 2 insertions(+) diff --git a/app/design/frontend/Magento/blank/Magento_Theme/web/css/source/_module.less b/app/design/frontend/Magento/blank/Magento_Theme/web/css/source/_module.less index b314bcf5b3473..3faa8ca965410 100644 --- a/app/design/frontend/Magento/blank/Magento_Theme/web/css/source/_module.less +++ b/app/design/frontend/Magento/blank/Magento_Theme/web/css/source/_module.less @@ -89,6 +89,7 @@ img { display: block; + height: auto; } .page-print & { diff --git a/app/design/frontend/Magento/luma/Magento_Theme/web/css/source/_module.less b/app/design/frontend/Magento/luma/Magento_Theme/web/css/source/_module.less index b841f2206e1d9..438fb55d32e5c 100644 --- a/app/design/frontend/Magento/luma/Magento_Theme/web/css/source/_module.less +++ b/app/design/frontend/Magento/luma/Magento_Theme/web/css/source/_module.less @@ -148,6 +148,7 @@ img { display: block; + height: auto; } .page-print & { From 4b79d4dbcd50487674697dc73c21dc45299e7d87 Mon Sep 17 00:00:00 2001 From: Evgenii Kalashnikov Date: Sat, 16 Nov 2019 19:05:00 +0300 Subject: [PATCH 11/19] upload media files fix --- .../Test/Unit/Model/Import/ProductTest.php | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php index f85d33edb5d8c..427ea25d98368 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php @@ -410,7 +410,7 @@ protected function _objectConstructor() $this->_filesystem->expects($this->once()) ->method('getDirectoryWrite') ->with(DirectoryList::ROOT) - ->will($this->returnValue(self::MEDIA_DIRECTORY)); + ->willReturn($this->_mediaDirectory); $this->validator->expects($this->any())->method('init'); return $this; @@ -1229,6 +1229,56 @@ public function testParseAttributesWithWrappedValuesWillReturnsLowercasedAttribu $this->assertArrayNotHasKey('PARAM2', $attributes); } + /** + * @param bool $isRead + * @param bool $isWrite + * @param string $message + * @dataProvider fillUploaderObjectDataProvider + */ + public function testFillUploaderObject($isRead, $isWrite, $message) + { + $fileUploaderMock = $this + ->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class) + ->disableOriginalConstructor() + ->getMock(); + + $fileUploaderMock + ->method('setTmpDir') + ->with('pub/media/import') + ->willReturn($isRead); + + $fileUploaderMock + ->method('setDestDir') + ->with('pub/media/catalog/product') + ->willReturn($isWrite); + + $this->_mediaDirectory + ->method('getRelativePath') + ->willReturnMap( + [ + ['import', 'import'], + ['catalog/product', 'catalog/product'], + ] + ); + + $this->_mediaDirectory + ->method('create') + ->with('pub/media/catalog/product'); + + $this->_uploaderFactory + ->expects($this->once()) + ->method('create') + ->willReturn($fileUploaderMock); + + try { + $this->importProduct->getUploader(); + $this->assertNotNull($this->getPropertyValue($this->importProduct, '_fileUploader')); + } catch (\Magento\Framework\Exception\LocalizedException $e) { + $this->assertNull($this->getPropertyValue($this->importProduct, '_fileUploader')); + $this->assertEquals($message, $e->getMessage()); + } + } + /** * Test that errors occurred during importing images are logged. * @@ -1275,6 +1325,20 @@ function ($name) use ($throwException, $exception) { ); } + /** + * Data provider for testFillUploaderObject. + * + * @return array + */ + public function fillUploaderObjectDataProvider() + { + return [ + [false, true, 'File directory \'pub/media/import\' is not readable.'], + [true, false, 'File directory \'pub/media/catalog/product\' is not writable.'], + [true, true, ''], + ]; + } + /** * Data provider for testUploadMediaFiles. * From d8e1a7166e97da1f1a750bd585a653b8a62b5c1f Mon Sep 17 00:00:00 2001 From: Evgenii Kalashnikov Date: Sat, 16 Nov 2019 23:29:10 +0300 Subject: [PATCH 12/19] upload media files fix --- .../Test/Unit/Model/Import/ProductTest.php | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php index 427ea25d98368..40041fe90db96 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php @@ -284,9 +284,11 @@ protected function setUp() ->getMock(); $this->storeResolver = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Product\StoreResolver::class) - ->setMethods([ - 'getStoreCodeToId', - ]) + ->setMethods( + [ + 'getStoreCodeToId', + ] + ) ->disableOriginalConstructor() ->getMock(); $this->skuProcessor = @@ -596,9 +598,13 @@ public function testGetMultipleValueSeparatorDefault() public function testGetMultipleValueSeparatorFromParameters() { $expectedSeparator = 'value'; - $this->setPropertyValue($this->importProduct, '_parameters', [ - \Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => $expectedSeparator, - ]); + $this->setPropertyValue( + $this->importProduct, + '_parameters', + [ + \Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => $expectedSeparator, + ] + ); $this->assertEquals( $expectedSeparator, @@ -618,9 +624,13 @@ public function testGetEmptyAttributeValueConstantDefault() public function testGetEmptyAttributeValueConstantFromParameters() { $expectedSeparator = '__EMPTY__VALUE__TEST__'; - $this->setPropertyValue($this->importProduct, '_parameters', [ - \Magento\ImportExport\Model\Import::FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT => $expectedSeparator, - ]); + $this->setPropertyValue( + $this->importProduct, + '_parameters', + [ + \Magento\ImportExport\Model\Import::FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT => $expectedSeparator, + ] + ); $this->assertEquals( $expectedSeparator, @@ -632,9 +642,12 @@ public function testDeleteProductsForReplacement() { $importProduct = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() - ->setMethods([ - 'setParameters', '_deleteProducts' - ]) + ->setMethods( + [ + 'setParameters', + '_deleteProducts' + ] + ) ->getMock(); $importProduct->expects($this->once())->method('setParameters')->with( @@ -764,9 +777,13 @@ public function testGetProductWebsites() 'key 3' => 'val', ]; $expectedResult = array_keys($productValue); - $this->setPropertyValue($this->importProduct, 'websitesCache', [ - $productSku => $productValue - ]); + $this->setPropertyValue( + $this->importProduct, + 'websitesCache', + [ + $productSku => $productValue + ] + ); $actualResult = $this->importProduct->getProductWebsites($productSku); @@ -785,9 +802,13 @@ public function testGetProductCategories() 'key 3' => 'val', ]; $expectedResult = array_keys($productValue); - $this->setPropertyValue($this->importProduct, 'categoriesCache', [ - $productSku => $productValue - ]); + $this->setPropertyValue( + $this->importProduct, + 'categoriesCache', + [ + $productSku => $productValue + ] + ); $actualResult = $this->importProduct->getProductCategories($productSku); @@ -1112,9 +1133,13 @@ public function testValidateRowSetAttributeSetCodeIntoRowData() ->disableOriginalConstructor() ->getMock(); $productType->expects($this->once())->method('isRowValid')->with($expectedRowData); - $this->setPropertyValue($importProduct, '_productTypeModels', [ - $newSku['type_id'] => $productType - ]); + $this->setPropertyValue( + $importProduct, + '_productTypeModels', + [ + $newSku['type_id'] => $productType + ] + ); //suppress option validation $this->_rewriteGetOptionEntityInImportProduct($importProduct); From 16aabf76e99e00ba58ea133e4c140698acc17f17 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Mon, 18 Nov 2019 11:48:49 +0530 Subject: [PATCH 13/19] Reverted PR 25022 --- .../backend/web/css/source/forms/_controls.less | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/design/adminhtml/Magento/backend/web/css/source/forms/_controls.less b/app/design/adminhtml/Magento/backend/web/css/source/forms/_controls.less index ab4bac919ee5f..c6f39e8e8840d 100644 --- a/app/design/adminhtml/Magento/backend/web/css/source/forms/_controls.less +++ b/app/design/adminhtml/Magento/backend/web/css/source/forms/_controls.less @@ -59,15 +59,15 @@ .admin__control-select { &:extend(.abs-form-control-pattern all); .lib-css(appearance, none, 1); - background-image+: url('../images/arrows-bg.svg') !important; + background-image+: url('../images/arrows-bg.svg'); background-position+: ~'calc(100% - 12px)' -34px; background-size+: auto; - background-image+: linear-gradient(@color-gray89, @color-gray89) !important; + background-image+: linear-gradient(@color-gray89, @color-gray89); background-position+: 100%; background-size+: @field-control__height 100%; - background-image+: linear-gradient(@field-control__border-color,@field-control__border-color) !important; + background-image+: linear-gradient(@field-control__border-color,@field-control__border-color); background-position+: ~'calc(100% - @{field-control__height})' 0; background-size+: 1px 100%; @@ -86,13 +86,13 @@ } &:active { - background-image+: url('../images/arrows-bg.svg') !important; + background-image+: url('../images/arrows-bg.svg'); background-position+: ~'calc(100% - 12px)' 13px; - background-image+: linear-gradient(@color-gray89, @color-gray89) !important; + background-image+: linear-gradient(@color-gray89, @color-gray89); background-position+: 100%; - background-image+: linear-gradient(@field-control__focus__border-color, @field-control__focus__border-color) !important; + background-image+: linear-gradient(@field-control__focus__border-color, @field-control__focus__border-color); background-position+: ~'calc(100% - @{field-control__height})' 0; border-color: @field-control__focus__border-color; } From 64482d1392ea7963760c57b83c818c76a2f18501 Mon Sep 17 00:00:00 2001 From: Benjamin Rosenberger Date: Mon, 18 Nov 2019 15:11:57 +0100 Subject: [PATCH 14/19] add indexer id to output add additional id column to bin/magento indexer:status command in order to have that information ready --- .../Magento/Indexer/Console/Command/IndexerStatusCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index cefb070f60b74..f5125fddf34b2 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -34,7 +34,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $table = new Table($output); - $table->setHeaders(['Title', 'Status', 'Update On', 'Schedule Status', 'Schedule Updated']); + $table->setHeaders(['ID', 'Title', 'Status', 'Update On', 'Schedule Status', 'Schedule Updated']); $rows = []; @@ -43,6 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $view = $indexer->getView(); $rowData = [ + 'ID' => $indexer->getId(), 'Title' => $indexer->getTitle(), 'Status' => $this->getStatus($indexer), 'Update On' => $indexer->isScheduled() ? 'Schedule' : 'Save', From 51526cfa1f92a31888936c9965bf3b8e839119b5 Mon Sep 17 00:00:00 2001 From: Benjamin Rosenberger Date: Mon, 18 Nov 2019 15:29:01 +0100 Subject: [PATCH 15/19] fix unit test to scope with new table column adapt test to contain new id column --- .../Command/IndexerStatusCommandTest.php | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 8498bd183af21..2aa55950e762e 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -96,7 +96,7 @@ public function testExecuteAll(array $indexers) $linesOutput = array_filter(explode(PHP_EOL, $commandTester->getDisplay())); - $spacer = '+----------------+------------------+-----------+-------------------------+---------------------+'; + $spacer = '+-----------+----------------+------------------+-----------+-------------------------+---------------------+'; $this->assertCount(8, $linesOutput, 'There should be 8 lines output. 3 Spacers, 1 header, 4 content.'); $this->assertEquals($linesOutput[0], $spacer, "Lines 0, 2, 7 should be spacer lines"); @@ -104,39 +104,44 @@ public function testExecuteAll(array $indexers) $this->assertEquals($linesOutput[7], $spacer, "Lines 0, 2, 7 should be spacer lines"); $headerValues = array_values(array_filter(explode('|', $linesOutput[1]))); - $this->assertEquals('Title', trim($headerValues[0])); - $this->assertEquals('Status', trim($headerValues[1])); - $this->assertEquals('Update On', trim($headerValues[2])); - $this->assertEquals('Schedule Status', trim($headerValues[3])); - $this->assertEquals('Schedule Updated', trim($headerValues[4])); + $this->assertEquals('ID', trim($headerValues[0])); + $this->assertEquals('Title', trim($headerValues[1])); + $this->assertEquals('Status', trim($headerValues[2])); + $this->assertEquals('Update On', trim($headerValues[3])); + $this->assertEquals('Schedule Status', trim($headerValues[4])); + $this->assertEquals('Schedule Updated', trim($headerValues[5])); $indexer1 = array_values(array_filter(explode('|', $linesOutput[3]))); - $this->assertEquals('Title_indexer1', trim($indexer1[0])); - $this->assertEquals('Ready', trim($indexer1[1])); - $this->assertEquals('Schedule', trim($indexer1[2])); - $this->assertEquals('idle (10 in backlog)', trim($indexer1[3])); - $this->assertEquals('2017-01-01 11:11:11', trim($indexer1[4])); + $this->assertEquals('indexer_1', trim($indexer1[0])); + $this->assertEquals('Title_indexer1', trim($indexer1[1])); + $this->assertEquals('Ready', trim($indexer1[2])); + $this->assertEquals('Schedule', trim($indexer1[3])); + $this->assertEquals('idle (10 in backlog)', trim($indexer1[4])); + $this->assertEquals('2017-01-01 11:11:11', trim($indexer1[5])); $indexer2 = array_values(array_filter(explode('|', $linesOutput[4]))); - $this->assertEquals('Title_indexer2', trim($indexer2[0])); - $this->assertEquals('Reindex required', trim($indexer2[1])); - $this->assertEquals('Save', trim($indexer2[2])); - $this->assertEquals('', trim($indexer2[3])); + $this->assertEquals('indexer_2', trim($indexer2[0])); + $this->assertEquals('Title_indexer2', trim($indexer2[1])); + $this->assertEquals('Reindex required', trim($indexer2[2])); + $this->assertEquals('Save', trim($indexer2[3])); $this->assertEquals('', trim($indexer2[4])); + $this->assertEquals('', trim($indexer2[5])); $indexer3 = array_values(array_filter(explode('|', $linesOutput[5]))); - $this->assertEquals('Title_indexer3', trim($indexer3[0])); - $this->assertEquals('Processing', trim($indexer3[1])); - $this->assertEquals('Schedule', trim($indexer3[2])); - $this->assertEquals('idle (100 in backlog)', trim($indexer3[3])); - $this->assertEquals('2017-01-01 11:11:11', trim($indexer3[4])); + $this->assertEquals('indexer_3', trim($indexer3[0])); + $this->assertEquals('Title_indexer3', trim($indexer3[1])); + $this->assertEquals('Processing', trim($indexer3[2])); + $this->assertEquals('Schedule', trim($indexer3[3])); + $this->assertEquals('idle (100 in backlog)', trim($indexer3[4])); + $this->assertEquals('2017-01-01 11:11:11', trim($indexer3[5])); $indexer4 = array_values(array_filter(explode('|', $linesOutput[6]))); - $this->assertEquals('Title_indexer4', trim($indexer4[0])); - $this->assertEquals('unknown', trim($indexer4[1])); - $this->assertEquals('Schedule', trim($indexer4[2])); - $this->assertEquals('running (20 in backlog)', trim($indexer4[3])); - $this->assertEquals('2017-01-01 11:11:11', trim($indexer4[4])); + $this->assertEquals('indexer_4', trim($indexer4[0])); + $this->assertEquals('Title_indexer4', trim($indexer4[1])); + $this->assertEquals('unknown', trim($indexer4[2])); + $this->assertEquals('Schedule', trim($indexer4[3])); + $this->assertEquals('running (20 in backlog)', trim($indexer4[4])); + $this->assertEquals('2017-01-01 11:11:11', trim($indexer4[5])); } /** From e2596bb7a5945cafba61fadcfc71669ad3a3df62 Mon Sep 17 00:00:00 2001 From: Benjamin Rosenberger Date: Tue, 19 Nov 2019 06:58:34 +0100 Subject: [PATCH 16/19] fix code styling errors --- .../Console/Command/IndexerStatusCommand.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index f5125fddf34b2..561ff759a4a59 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -5,11 +5,11 @@ */ namespace Magento\Indexer\Console\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; use Magento\Framework\Indexer; use Magento\Framework\Mview; use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * Command for displaying status of indexers. @@ -17,7 +17,7 @@ class IndexerStatusCommand extends AbstractIndexerManageCommand { /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -29,7 +29,9 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc + * @param InputInterface $input + * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -60,15 +62,20 @@ protected function execute(InputInterface $input, OutputInterface $output) $rows[] = $rowData; } - usort($rows, function ($comp1, $comp2) { - return strcmp($comp1['Title'], $comp2['Title']); - }); + usort( + $rows, + function ($comp1, $comp2) { + return strcmp($comp1['Title'], $comp2['Title']); + } + ); $table->addRows($rows); $table->render(); } /** + * Returns the current status of the indexer + * * @param Indexer\IndexerInterface $indexer * @return string */ @@ -90,6 +97,8 @@ private function getStatus(Indexer\IndexerInterface $indexer) } /** + * Returns the pending count of the view + * * @param Mview\ViewInterface $view * @return string */ From ecfc973d69d025954e81cf52451c32764c2afb33 Mon Sep 17 00:00:00 2001 From: Benjamin Rosenberger Date: Tue, 19 Nov 2019 06:59:37 +0100 Subject: [PATCH 17/19] fix code stylings --- .../Test/Unit/Console/Command/IndexerStatusCommandTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 2aa55950e762e..963a0b21c1f96 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -96,7 +96,8 @@ public function testExecuteAll(array $indexers) $linesOutput = array_filter(explode(PHP_EOL, $commandTester->getDisplay())); - $spacer = '+-----------+----------------+------------------+-----------+-------------------------+---------------------+'; + $spacer = '+-----------+----------------+------------------+-----------+-------------------------+' + . '---------------------+'; $this->assertCount(8, $linesOutput, 'There should be 8 lines output. 3 Spacers, 1 header, 4 content.'); $this->assertEquals($linesOutput[0], $spacer, "Lines 0, 2, 7 should be spacer lines"); From b011040ca0c09b1feebd270e875e3faa142ecd2d Mon Sep 17 00:00:00 2001 From: Benjamin Rosenberger Date: Wed, 20 Nov 2019 06:23:33 +0100 Subject: [PATCH 18/19] :ok_hand: adding type hints as suggested by review --- .../Magento/Indexer/Console/Command/IndexerStatusCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index 561ff759a4a59..4ecacb68705be 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -65,6 +65,10 @@ protected function execute(InputInterface $input, OutputInterface $output) usort( $rows, function ($comp1, $comp2) { + /** + * @var array $comp1 + * @var array $comp2 + */ return strcmp($comp1['Title'], $comp2['Title']); } ); From 2e27790a4330a8017f6cb2154d9f48a1a550dac8 Mon Sep 17 00:00:00 2001 From: Benjamin Rosenberger Date: Wed, 20 Nov 2019 12:25:35 +0100 Subject: [PATCH 19/19] :ok_hand: change type hint to parameter type --- .../Indexer/Console/Command/IndexerStatusCommand.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index 4ecacb68705be..26feb38392e5f 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -64,11 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output) usort( $rows, - function ($comp1, $comp2) { - /** - * @var array $comp1 - * @var array $comp2 - */ + function (array $comp1, array $comp2) { return strcmp($comp1['Title'], $comp2['Title']); } );