Skip to content

Commit 16b737e

Browse files
author
Cari Spruiell
committed
MAGETWO-38818: [Add join processors to search service] Tax Module - II
- Add joinProcessor to Tax/Model/TaxClass/Repository.php - updated associated unit test - added integration test
1 parent f57388c commit 16b737e

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

app/code/Magento/Tax/Model/TaxClass/Repository.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,36 @@ class Repository implements \Magento\Tax\Api\TaxClassRepositoryInterface
6262
*/
6363
protected $taxClassResource;
6464

65+
/**
66+
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
67+
*/
68+
protected $joinProcessor;
69+
6570
/**
6671
* @param SearchCriteriaBuilder $searchCriteriaBuilder
6772
* @param FilterBuilder $filterBuilder
6873
* @param TaxClassCollectionFactory $taxClassCollectionFactory
6974
* @param \Magento\Tax\Api\Data\TaxClassSearchResultsInterfaceFactory $searchResultsFactory
7075
* @param ClassModelRegistry $classModelRegistry
7176
* @param \Magento\Tax\Model\Resource\TaxClass $taxClassResource
77+
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
7278
*/
7379
public function __construct(
7480
SearchCriteriaBuilder $searchCriteriaBuilder,
7581
FilterBuilder $filterBuilder,
7682
TaxClassCollectionFactory $taxClassCollectionFactory,
7783
\Magento\Tax\Api\Data\TaxClassSearchResultsInterfaceFactory $searchResultsFactory,
7884
ClassModelRegistry $classModelRegistry,
79-
\Magento\Tax\Model\Resource\TaxClass $taxClassResource
85+
\Magento\Tax\Model\Resource\TaxClass $taxClassResource,
86+
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
8087
) {
8188
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
8289
$this->filterBuilder = $filterBuilder;
8390
$this->taxClassCollectionFactory = $taxClassCollectionFactory;
8491
$this->searchResultsFactory = $searchResultsFactory;
8592
$this->classModelRegistry = $classModelRegistry;
8693
$this->taxClassResource = $taxClassResource;
94+
$this->joinProcessor = $joinProcessor;
8795
}
8896

8997
/**
@@ -195,6 +203,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
195203
$searchResults->setSearchCriteria($searchCriteria);
196204
/** @var TaxClassCollection $collection */
197205
$collection = $this->taxClassCollectionFactory->create();
206+
$this->joinProcessor->process($collection);
198207
foreach ($searchCriteria->getFilterGroups() as $group) {
199208
$this->addFilterGroupToCollection($group, $collection);
200209
}

app/code/Magento/Tax/Test/Unit/Model/TaxClass/RepositoryTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
4747
*/
4848
protected $taxClassCollectionFactory;
4949

50+
/**
51+
* @var \PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
protected $extensionAttributesJoinProcessorMock;
54+
55+
/**
5056
/**
5157
* @return void
5258
*/
@@ -85,13 +91,23 @@ protected function setUp()
8591
);
8692

8793
$this->taxClassResourceMock = $this->getMock('\Magento\Tax\Model\Resource\TaxClass', [], [], '', false);
94+
95+
$this->extensionAttributesJoinProcessorMock = $this->getMock(
96+
'\Magento\Framework\Api\ExtensionAttribute\JoinProcessor',
97+
['process'],
98+
[],
99+
'',
100+
false
101+
);
102+
88103
$this->model = $this->objectManager->getObject(
89104
'Magento\Tax\Model\TaxClass\Repository',
90105
[
91106
'classModelRegistry' => $this->classModelRegistryMock,
92107
'taxClassResource' => $this->taxClassResourceMock,
93108
'searchResultsFactory' => $this->searchResultFactory,
94-
'taxClassCollectionFactory' => $this->taxClassCollectionFactory
109+
'taxClassCollectionFactory' => $this->taxClassCollectionFactory,
110+
'joinProcessor' => $this->extensionAttributesJoinProcessorMock
95111
]
96112
);
97113
}
@@ -187,6 +203,10 @@ public function testGetList()
187203
$collection = $this->getMock('\Magento\Tax\Model\Resource\TaxClass\Collection', [], [], '', false);
188204
$sortOrder = $this->getMock('\Magento\Framework\Api\SortOrder', [], [], '', false);
189205

206+
$this->extensionAttributesJoinProcessorMock->expects($this->once())
207+
->method('process')
208+
->with($collection);
209+
190210
$searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
191211
$filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
192212
$filter->expects($this->atLeastOnce())->method('getConditionType')->willReturn('eq');

dev/tests/integration/testsuite/Magento/Tax/Model/TaxClass/RepositoryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ public function testGet()
112112
$this->assertEquals(TaxClassManagementInterface::TYPE_CUSTOMER, $data->getClassType());
113113
}
114114

115+
/**
116+
* @magentoDbIsolation enabled
117+
*/
118+
public function testGetList()
119+
{
120+
$taxClassName = 'Get Me';
121+
$taxClassDataObject = $this->taxClassFactory->create();
122+
$taxClassDataObject->setClassName($taxClassName)
123+
->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER);
124+
$taxClassId = $this->taxClassRepository->save($taxClassDataObject);
125+
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
126+
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create('Magento\Framework\Api\SearchCriteriaBuilder');
127+
/** @var \Magento\Tax\Api\Data\TaxClassSearchResultsInterface */
128+
$searchResult = $this->taxClassRepository->getList($searchCriteriaBuilder->create());
129+
$items = $searchResult->getItems();
130+
/** @var \Magento\Tax\Api\Data\TaxClassInterface */
131+
$taxClass = array_pop($items);
132+
$this->assertInstanceOf('Magento\Tax\Api\Data\TaxClassInterface', $taxClass);
133+
$this->assertEquals($taxClassName, $taxClass->getClassName());
134+
$this->assertEquals($taxClassId, $taxClass->getClassId());
135+
$this->assertEquals(TaxClassManagementInterface::TYPE_CUSTOMER, $taxClass->getClassType());
136+
}
137+
115138
/**
116139
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
117140
* @expectedExceptionMessage No such entity with class_id = -9999

0 commit comments

Comments
 (0)