Skip to content

Commit 20e49f7

Browse files
committed
Merge branch 'customer-grid-ui-component' of github.com:simpleadm/magento2 into customer-grid-ui-component
# Conflicts: # app/code/Magento/Customer/etc/di.xml
2 parents b7c76e3 + cd26450 commit 20e49f7

File tree

7 files changed

+582
-43
lines changed

7 files changed

+582
-43
lines changed

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: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Group\Grid;
7+
8+
use Magento\Customer\Model\ResourceModel\Group\Grid\Collection;
9+
use Magento\Framework\Api\Search\AggregationInterface;
10+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
11+
use Magento\Framework\Data\Collection\EntityFactoryInterface;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\Event\ManagerInterface;
14+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use Psr\Log\LoggerInterface;
17+
use Magento\Framework\DB\Select;
18+
19+
/**
20+
* CollectionTest contains unit tests for \Magento\Customer\Model\ResourceModel\Group\Grid\Collection class
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
23+
class CollectionTest extends \PHPUnit\Framework\TestCase
24+
{
25+
/**
26+
* @var EntityFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $entityFactoryMock;
29+
30+
/**
31+
* @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $loggerMock;
34+
35+
/**
36+
* @var FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $fetchStrategyMock;
39+
40+
/**
41+
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
protected $eventManagerMock;
44+
45+
/**
46+
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
protected $connectionMock;
49+
50+
/**
51+
* @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
protected $resourceMock;
54+
55+
/**
56+
* @var AggregationInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
protected $aggregationsMock;
59+
60+
/**
61+
* @var Select
62+
*/
63+
protected $selectMock;
64+
65+
/**
66+
* @var Collection
67+
*/
68+
protected $model;
69+
70+
protected function setUp()
71+
{
72+
$this->entityFactoryMock = $this->getMockBuilder(EntityFactoryInterface::class)
73+
->getMockForAbstractClass();
74+
$this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
75+
->getMockForAbstractClass();
76+
$this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)
77+
->getMockForAbstractClass();
78+
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
79+
->getMockForAbstractClass();
80+
$this->resourceMock = $this->getMockBuilder(AbstractDb::class)
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$this->aggregationsMock = $this->getMockBuilder(AggregationInterface::class)
84+
->getMockForAbstractClass();
85+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
86+
->getMockForAbstractClass();
87+
$this->selectMock = $this->getMockBuilder(Select::class)
88+
->disableOriginalConstructor()
89+
->getMock();
90+
91+
$this->resourceMock->expects($this->any())
92+
->method('getConnection')
93+
->willReturn($this->connectionMock);
94+
$this->connectionMock->expects($this->once())
95+
->method('select')
96+
->willReturn($this->selectMock);
97+
98+
$this->model = (new ObjectManager($this))->getObject(Collection::class, [
99+
'entityFactory' => $this->entityFactoryMock,
100+
'logger' => $this->loggerMock,
101+
'fetchStrategy' => $this->fetchStrategyMock,
102+
'eventManager' => $this->eventManagerMock,
103+
'mainTable' => null,
104+
'eventPrefix' => 'test_event_prefix',
105+
'eventObject' => 'test_event_object',
106+
'resourceModel' => null,
107+
'resource' => $this->resourceMock,
108+
]);
109+
}
110+
111+
/**
112+
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria
113+
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::getAggregations
114+
*/
115+
public function testSetGetAggregations()
116+
{
117+
$this->model->setAggregations($this->aggregationsMock);
118+
$this->assertInstanceOf(AggregationInterface::class, $this->model->getAggregations());
119+
}
120+
121+
/**
122+
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria
123+
*/
124+
public function testSetSearchCriteria()
125+
{
126+
$this->assertEquals($this->model, $this->model->setSearchCriteria());
127+
}
128+
}

0 commit comments

Comments
 (0)