Skip to content

Commit 4eb0223

Browse files
author
Stanislav Idolov
authored
ENGCOM-1312: [Improvement] Implement customer group grid on ui component #13501
2 parents f1a4d02 + 1480d23 commit 4eb0223

File tree

11 files changed

+648
-54
lines changed

11 files changed

+648
-54
lines changed

app/code/Magento/Customer/Model/ResourceModel/Group/Collection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
1414
{
15+
/**
16+
* @var string
17+
*/
18+
protected $_idFieldName = 'customer_group_id';
19+
1520
/**
1621
* Resource initialization
1722
*

app/code/Magento/Customer/Model/ResourceModel/Group/Grid/Collection.php

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,62 @@
77
*/
88
namespace Magento\Customer\Model\ResourceModel\Group\Grid;
99

10-
class Collection extends \Magento\Customer\Model\ResourceModel\Group\Collection
10+
use Magento\Customer\Model\ResourceModel\Group\Collection as GroupCollection;
11+
use Magento\Framework\Api\Search\SearchResultInterface;
12+
use Magento\Framework\Search\AggregationInterface;
13+
14+
/**
15+
* Collection for displaying grid of customer groups
16+
*/
17+
class Collection extends GroupCollection implements SearchResultInterface
1118
{
19+
/**
20+
* @var AggregationInterface
21+
*/
22+
protected $aggregations;
23+
24+
/**
25+
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
26+
* @param \Psr\Log\LoggerInterface $logger
27+
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
28+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
29+
* @param string $mainTable
30+
* @param string $eventPrefix
31+
* @param string $eventObject
32+
* @param string $resourceModel
33+
* @param string $model
34+
* @param \Magento\Framework\DB\Adapter\AdapterInterface|string|null $connection
35+
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
36+
*
37+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
38+
*/
39+
public function __construct(
40+
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
41+
\Psr\Log\LoggerInterface $logger,
42+
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
43+
\Magento\Framework\Event\ManagerInterface $eventManager,
44+
$mainTable,
45+
$eventPrefix,
46+
$eventObject,
47+
$resourceModel,
48+
$model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
49+
$connection = null,
50+
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
51+
) {
52+
parent::__construct(
53+
$entityFactory,
54+
$logger,
55+
$fetchStrategy,
56+
$eventManager,
57+
$connection,
58+
$resource
59+
);
60+
$this->_eventPrefix = $eventPrefix;
61+
$this->_eventObject = $eventObject;
62+
$this->_init($model, $resourceModel);
63+
$this->setMainTable($mainTable);
64+
}
65+
1266
/**
1367
* Resource initialization
1468
* @return $this
@@ -19,4 +73,78 @@ protected function _initSelect()
1973
$this->addTaxClass();
2074
return $this;
2175
}
76+
77+
/**
78+
* @return AggregationInterface
79+
*/
80+
public function getAggregations()
81+
{
82+
return $this->aggregations;
83+
}
84+
85+
/**
86+
* @param AggregationInterface $aggregations
87+
* @return $this
88+
*/
89+
public function setAggregations($aggregations)
90+
{
91+
$this->aggregations = $aggregations;
92+
return $this;
93+
}
94+
95+
/**
96+
* Get search criteria.
97+
*
98+
* @return \Magento\Framework\Api\SearchCriteriaInterface|null
99+
*/
100+
public function getSearchCriteria()
101+
{
102+
return null;
103+
}
104+
105+
/**
106+
* Set search criteria.
107+
*
108+
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
109+
* @return $this
110+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
111+
*/
112+
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
113+
{
114+
return $this;
115+
}
116+
117+
/**
118+
* Get total count.
119+
*
120+
* @return int
121+
*/
122+
public function getTotalCount()
123+
{
124+
return $this->getSize();
125+
}
126+
127+
/**
128+
* Set total count.
129+
*
130+
* @param int $totalCount
131+
* @return $this
132+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
133+
*/
134+
public function setTotalCount($totalCount)
135+
{
136+
return $this;
137+
}
138+
139+
/**
140+
* Set items list.
141+
*
142+
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
143+
* @return $this
144+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
145+
*/
146+
public function setItems(array $items = null)
147+
{
148+
return $this;
149+
}
22150
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Group\Grid;
10+
11+
use Magento\Customer\Model\ResourceModel\Group\Grid\Collection;
12+
use Magento\Framework\Api\Search\AggregationInterface;
13+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
14+
use Magento\Framework\Data\Collection\EntityFactoryInterface;
15+
use Magento\Framework\DB\Adapter\AdapterInterface;
16+
use Magento\Framework\Event\ManagerInterface;
17+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
18+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Psr\Log\LoggerInterface;
20+
use Magento\Framework\DB\Select;
21+
22+
/**
23+
* CollectionTest contains unit tests for \Magento\Customer\Model\ResourceModel\Group\Grid\Collection class
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
*/
26+
class CollectionTest extends \PHPUnit\Framework\TestCase
27+
{
28+
/**
29+
* @var EntityFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $entityFactoryMock;
32+
33+
/**
34+
* @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $loggerMock;
37+
38+
/**
39+
* @var FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $fetchStrategyMock;
42+
43+
/**
44+
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
protected $eventManagerMock;
47+
48+
/**
49+
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
protected $connectionMock;
52+
53+
/**
54+
* @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
protected $resourceMock;
57+
58+
/**
59+
* @var AggregationInterface|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
protected $aggregationsMock;
62+
63+
/**
64+
* @var Select
65+
*/
66+
protected $selectMock;
67+
68+
/**
69+
* @var Collection
70+
*/
71+
protected $model;
72+
73+
/**
74+
* SetUp method
75+
*
76+
* @return void
77+
*/
78+
protected function setUp()
79+
{
80+
$this->entityFactoryMock = $this->getMockBuilder(EntityFactoryInterface::class)
81+
->getMockForAbstractClass();
82+
$this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
83+
->getMockForAbstractClass();
84+
$this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)
85+
->getMockForAbstractClass();
86+
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
87+
->getMockForAbstractClass();
88+
$this->resourceMock = $this->getMockBuilder(AbstractDb::class)
89+
->disableOriginalConstructor()
90+
->getMock();
91+
$this->aggregationsMock = $this->getMockBuilder(AggregationInterface::class)
92+
->getMockForAbstractClass();
93+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
94+
->getMockForAbstractClass();
95+
$this->selectMock = $this->getMockBuilder(Select::class)
96+
->disableOriginalConstructor()
97+
->getMock();
98+
99+
$this->resourceMock->expects($this->any())
100+
->method('getConnection')
101+
->willReturn($this->connectionMock);
102+
$this->connectionMock->expects($this->once())
103+
->method('select')
104+
->willReturn($this->selectMock);
105+
106+
$this->model = (new ObjectManager($this))->getObject(Collection::class, [
107+
'entityFactory' => $this->entityFactoryMock,
108+
'logger' => $this->loggerMock,
109+
'fetchStrategy' => $this->fetchStrategyMock,
110+
'eventManager' => $this->eventManagerMock,
111+
'mainTable' => null,
112+
'eventPrefix' => 'test_event_prefix',
113+
'eventObject' => 'test_event_object',
114+
'resourceModel' => null,
115+
'resource' => $this->resourceMock,
116+
]);
117+
}
118+
119+
/**
120+
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria
121+
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::getAggregations
122+
*/
123+
public function testSetGetAggregations()
124+
{
125+
$this->model->setAggregations($this->aggregationsMock);
126+
$this->assertInstanceOf(AggregationInterface::class, $this->model->getAggregations());
127+
}
128+
129+
/**
130+
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria
131+
*/
132+
public function testSetSearchCriteria()
133+
{
134+
$this->assertEquals($this->model, $this->model->setSearchCriteria());
135+
}
136+
}

0 commit comments

Comments
 (0)