From 05fcdd1a52c674ea09a34960cea71e73488fbc99 Mon Sep 17 00:00:00 2001 From: Magento EngCom Team Date: Tue, 23 Jan 2018 11:00:40 -0600 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#12077 to 2.3-develop branch Applied pull request patch https://github.com/magento/magento2/pull/12077.patch (created by @RomaKis) based on commit(s): 1. 774799a545500aa2867b53a34028c747050ca1e2 Fixed GitHub Issues in 2.3-develop branch: - magento/magento2#10628: Color attribute swatches are not visible if sorting is enabled (reported by @akashkarev) --- .../Catalog/Model/ResourceModel/Config.php | 3 +- .../Unit/Model/ResourceModel/ConfigTest.php | 107 ++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Config.php b/app/code/Magento/Catalog/Model/ResourceModel/Config.php index 7fb13265cd130..7b5d4e09a3599 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Config.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Config.php @@ -149,8 +149,7 @@ public function getAttributesUsedForSortBy() ['main_table' => $this->getTable('eav_attribute')] )->join( ['additional_table' => $this->getTable('catalog_eav_attribute')], - 'main_table.attribute_id = additional_table.attribute_id', - [] + 'main_table.attribute_id = additional_table.attribute_id' )->joinLeft( ['al' => $this->getTable('eav_attribute_label')], 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $this->getStoreId(), diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php new file mode 100644 index 0000000000000..abbcef942373e --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php @@ -0,0 +1,107 @@ +resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class); + $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class); + + $this->model = $objectManager->getObject( + \Magento\Catalog\Model\ResourceModel\Config::class, + [ + 'resource' => $this->resource, + 'storeManager' => $this->storeManager, + 'eavConfig' => $this->eavConfig, + ] + ); + + parent::setUp(); + } + + public function testGetAttributesUsedForSortBy() + { + $expression = 'someExpression'; + $storeId = 1; + $entityTypeId = 4; + + $connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class); + $selectMock = $this->createMock(\Magento\Framework\DB\Select::class); + $storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class); + $entityTypeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class); + + $this->resource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock); + + $connectionMock->expects($this->once())->method('getCheckSql') + ->with('al.value IS NULL', 'main_table.frontend_label', 'al.value') + ->willReturn($expression); + $connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($selectMock); + + $this->resource->expects($this->exactly(3))->method('getTableName')->withConsecutive( + ['eav_attribute'], + ['catalog_eav_attribute'], + ['eav_attribute_label'] + )->willReturnOnConsecutiveCalls('eav_attribute', 'catalog_eav_attribute', 'eav_attribute_label'); + + $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock); + $storeMock->expects($this->once())->method('getId')->willReturn($storeId); + + $this->eavConfig->expects($this->once())->method('getEntityType')->willReturn($entityTypeMock); + $entityTypeMock->expects($this->once())->method('getId')->willReturn($entityTypeId); + + $selectMock->expects($this->once())->method('from') + ->with(['main_table' => 'eav_attribute'])->willReturn($selectMock); + $selectMock->expects($this->once())->method('join')->with( + ['additional_table' => 'catalog_eav_attribute'], + 'main_table.attribute_id = additional_table.attribute_id' + )->willReturn($selectMock); + $selectMock->expects($this->once())->method('joinLeft') + ->with( + ['al' => 'eav_attribute_label'], + 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $storeId, + ['store_label' => $expression] + )->willReturn($selectMock); + $selectMock->expects($this->exactly(2))->method('where')->withConsecutive( + ['main_table.entity_type_id = ?', $entityTypeId], + ['additional_table.used_for_sort_by = ?', 1] + )->willReturn($selectMock); + + $connectionMock->expects($this->once())->method('fetchAll')->with($selectMock); + + $this->model->getAttributesUsedForSortBy(); + } +}