Skip to content

Commit

Permalink
⏫ Forwardport of #12077 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/12077.patch (created by @RomaKis) based on commit(s):
  1. 774799a

Fixed GitHub Issues in 2.3-develop branch:
  - #10628: Color attribute swatches are not visible if sorting is enabled (reported by @akashkarev)
  • Loading branch information
magento-engcom-team committed Jan 23, 2018
1 parent 8e77e2f commit 05fcdd1
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/code/Magento/Catalog/Model/ResourceModel/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
107 changes: 107 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Model\ResourceModel;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Test for Magento\Catalog\Model\ResourceModel\Config
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Catalog\Model\ResourceModel\Config
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $resource;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $storeManager;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $eavConfig;

protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->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();
}
}

0 comments on commit 05fcdd1

Please sign in to comment.