Skip to content

Commit e56ab24

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-69621' into 2.1-develop-pr30
2 parents 5ba9ee9 + 66473c3 commit e56ab24

File tree

2 files changed

+60
-1
lines changed
  • app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes
  • dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Attributes

2 files changed

+60
-1
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public function __construct(
4141
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
4242
$this->request = $request;
4343
$this->collection = $collectionFactory->create();
44-
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
4544
}
4645

4746
/**
4847
* {@inheritdoc}
4948
*/
5049
public function getData()
5150
{
51+
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
52+
$this->collection->getSelect()->setPart('order', []);
53+
5254
$items = [];
5355
foreach ($this->getCollection()->getItems() as $attribute) {
5456
$items[] = $attribute->toArray();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Ui\DataProvider\Product\Attributes;
8+
9+
/**
10+
* Test sorting in product attribute grid
11+
*/
12+
class ListingTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/** @var \Magento\Catalog\Ui\DataProvider\Product\Attributes\Listing */
15+
private $dataProvider;
16+
17+
/** @var \Magento\Framework\App\RequestInterface */
18+
private $request;
19+
20+
protected function setUp()
21+
{
22+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
23+
/** @var \Magento\Framework\App\RequestInterface $request */
24+
$this->request = $objectManager->get(\Magento\Framework\App\RequestInterface::class);
25+
26+
/** Default Attribute Set Id is equal 4 */
27+
$this->request->setParams(['template_id' => 4]);
28+
29+
$this->dataProvider = $objectManager->create(
30+
\Magento\Catalog\Ui\DataProvider\Product\Attributes\Listing::class,
31+
[
32+
'name' => 'product_attributes_grid_data_source',
33+
'primaryFieldName' => 'attribute_id',
34+
'requestFieldName' => 'id',
35+
'request' => $this->request,
36+
]
37+
);
38+
}
39+
40+
public function testGetDataSortedAsc()
41+
{
42+
$this->dataProvider->addOrder('attribute_code', 'asc');
43+
$data = $this->dataProvider->getData();
44+
$this->assertEquals(2, $data['totalRecords']);
45+
$this->assertEquals('color', $data['items'][0]['attribute_code']);
46+
$this->assertEquals('manufacturer', $data['items'][1]['attribute_code']);
47+
}
48+
49+
public function testGetDataSortedDesc()
50+
{
51+
$this->dataProvider->addOrder('attribute_code', 'desc');
52+
$data = $this->dataProvider->getData();
53+
$this->assertEquals(2, $data['totalRecords']);
54+
$this->assertEquals('manufacturer', $data['items'][0]['attribute_code']);
55+
$this->assertEquals('color', $data['items'][1]['attribute_code']);
56+
}
57+
}

0 commit comments

Comments
 (0)