Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'customer_group_id';

/**
* Resource initialization
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,62 @@
*/
namespace Magento\Customer\Model\ResourceModel\Group\Grid;

class Collection extends \Magento\Customer\Model\ResourceModel\Group\Collection
use Magento\Customer\Model\ResourceModel\Group\Collection as GroupCollection;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Search\AggregationInterface;

/**
* Collection for displaying grid of customer groups
*/
class Collection extends GroupCollection implements SearchResultInterface
{
/**
* @var AggregationInterface
*/
protected $aggregations;

/**
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param string $mainTable
* @param string $eventPrefix
* @param string $eventObject
* @param string $resourceModel
* @param string $model
* @param \Magento\Framework\DB\Adapter\AdapterInterface|string|null $connection
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
\Magento\Framework\Event\ManagerInterface $eventManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
$connection = null,
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
) {
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
}

/**
* Resource initialization
* @return $this
Expand All @@ -19,4 +73,78 @@ protected function _initSelect()
$this->addTaxClass();
return $this;
}

/**
* @return AggregationInterface
*/
public function getAggregations()
{
return $this->aggregations;
}

/**
* @param AggregationInterface $aggregations
* @return $this
*/
public function setAggregations($aggregations)
{
$this->aggregations = $aggregations;
return $this;
}

/**
* Get search criteria.
*
* @return \Magento\Framework\Api\SearchCriteriaInterface|null
*/
public function getSearchCriteria()
{
return null;
}

/**
* Set search criteria.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
{
return $this;
}

/**
* Get total count.
*
* @return int
*/
public function getTotalCount()
{
return $this->getSize();
}

/**
* Set total count.
*
* @param int $totalCount
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setTotalCount($totalCount)
{
return $this;
}

/**
* Set items list.
*
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setItems(array $items = null)
{
return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Customer\Test\Unit\Model\ResourceModel\Group\Grid;

use Magento\Customer\Model\ResourceModel\Group\Grid\Collection;
use Magento\Framework\Api\Search\AggregationInterface;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Psr\Log\LoggerInterface;
use Magento\Framework\DB\Select;

/**
* CollectionTest contains unit tests for \Magento\Customer\Model\ResourceModel\Group\Grid\Collection class
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CollectionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var EntityFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityFactoryMock;

/**
* @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $loggerMock;

/**
* @var FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $fetchStrategyMock;

/**
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $eventManagerMock;

/**
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $connectionMock;

/**
* @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject
*/
protected $resourceMock;

/**
* @var AggregationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $aggregationsMock;

/**
* @var Select
*/
protected $selectMock;

/**
* @var Collection
*/
protected $model;

/**
* SetUp method
*
* @return void
*/
protected function setUp()
{
$this->entityFactoryMock = $this->getMockBuilder(EntityFactoryInterface::class)
->getMockForAbstractClass();
$this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
->getMockForAbstractClass();
$this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)
->getMockForAbstractClass();
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
->getMockForAbstractClass();
$this->resourceMock = $this->getMockBuilder(AbstractDb::class)
->disableOriginalConstructor()
->getMock();
$this->aggregationsMock = $this->getMockBuilder(AggregationInterface::class)
->getMockForAbstractClass();
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
->getMockForAbstractClass();
$this->selectMock = $this->getMockBuilder(Select::class)
->disableOriginalConstructor()
->getMock();

$this->resourceMock->expects($this->any())
->method('getConnection')
->willReturn($this->connectionMock);
$this->connectionMock->expects($this->once())
->method('select')
->willReturn($this->selectMock);

$this->model = (new ObjectManager($this))->getObject(Collection::class, [
'entityFactory' => $this->entityFactoryMock,
'logger' => $this->loggerMock,
'fetchStrategy' => $this->fetchStrategyMock,
'eventManager' => $this->eventManagerMock,
'mainTable' => null,
'eventPrefix' => 'test_event_prefix',
'eventObject' => 'test_event_object',
'resourceModel' => null,
'resource' => $this->resourceMock,
]);
}

/**
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::getAggregations
*/
public function testSetGetAggregations()
{
$this->model->setAggregations($this->aggregationsMock);
$this->assertInstanceOf(AggregationInterface::class, $this->model->getAggregations());
}

/**
* @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria
*/
public function testSetSearchCriteria()
{
$this->assertEquals($this->model, $this->model->setSearchCriteria());
}
}
Loading