Skip to content

Commit d904690

Browse files
Merge forwardport of #12105 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12105.patch (created by @tzyganu) based on commit(s): 1. 433c3cd 2. 7be92a8 Fixed GitHub Issues in 2.3-develop branch: - #11936: required attribute set id filter on attribute group repository getList (reported by @tzyganu)
2 parents ab2e579 + aa267f4 commit d904690

File tree

2 files changed

+3
-66
lines changed

2 files changed

+3
-66
lines changed

app/code/Magento/Eav/Model/Attribute/GroupRepository.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ public function save(\Magento\Eav\Api\Data\AttributeGroupInterface $group)
117117
*/
118118
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
119119
{
120-
$attributeSetId = $this->retrieveAttributeSetIdFromSearchCriteria($searchCriteria);
121-
if (!$attributeSetId) {
122-
throw InputException::requiredField('attribute_set_id');
123-
}
124-
try {
125-
$this->setRepository->get($attributeSetId);
126-
} catch (\Exception $exception) {
127-
throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
128-
}
129-
130120
/** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\Collection $collection */
131121
$collection = $this->groupListFactory->create();
132122
$this->joinProcessor->process($collection);
@@ -188,6 +178,7 @@ public function deleteById($groupId)
188178
/**
189179
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
190180
* @return null|string
181+
* @deprecated
191182
*/
192183
protected function retrieveAttributeSetIdFromSearchCriteria(
193184
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria

app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -266,33 +266,25 @@ public function testSaveThrowExceptionIfProvidedGroupDoesNotExist()
266266
*/
267267
public function testGetList()
268268
{
269-
$attributeSetId = 'filter';
270-
271269
$filterInterfaceMock = $this->getMockBuilder(\Magento\Framework\Api\Search\FilterGroup::class)
272270
->disableOriginalConstructor()
273271
->setMethods([
274272
'getField',
275273
'getValue',
276274
])
277275
->getMock();
278-
$filterInterfaceMock->expects($this->once())
279-
->method('getField')
280-
->willReturn('attribute_set_id');
281-
$filterInterfaceMock->expects($this->once())
282-
->method('getValue')
283-
->willReturn($attributeSetId);
284276

285277
$filterGroupMock = $this->getMockBuilder(\Magento\Framework\Api\Search\FilterGroup::class)
286278
->disableOriginalConstructor()
287279
->getMock();
288-
$filterGroupMock->expects($this->once())
280+
$filterGroupMock->expects($this->any())
289281
->method('getFilters')
290282
->willReturn([$filterInterfaceMock]);
291283

292284
$searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaInterface::class)
293285
->disableOriginalConstructor()
294286
->getMock();
295-
$searchCriteriaMock->expects($this->once())
287+
$searchCriteriaMock->expects($this->any())
296288
->method('getFilterGroups')
297289
->willReturn([$filterGroupMock]);
298290

@@ -324,52 +316,6 @@ public function testGetList()
324316
$this->assertEquals($searchResultsMock, $this->model->getList($searchCriteriaMock));
325317
}
326318

327-
/**
328-
* Test get list with invalid input exception
329-
*
330-
* @expectedException \Magento\Framework\Exception\InputException
331-
* @expectedExceptionMessage attribute_set_id is a required field.
332-
* @throws \Magento\Framework\Exception\InputException
333-
* @throws \Magento\Framework\Exception\NoSuchEntityException
334-
* @return void
335-
*/
336-
public function testGetListWithInvalidInputException()
337-
{
338-
$searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class);
339-
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([]);
340-
$this->model->getList($searchCriteriaMock);
341-
}
342-
343-
/**
344-
* Test get list with no such entity exception
345-
*
346-
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
347-
* @expectedExceptionMessage No such entity with attributeSetId = filter
348-
* @throws \Magento\Framework\Exception\InputException
349-
* @throws \Magento\Framework\Exception\NoSuchEntityException
350-
* @return void
351-
*/
352-
public function testGetListWithNoSuchEntityException()
353-
{
354-
$attributeSetId = 'filter';
355-
$searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class);
356-
$filterGroupMock = $this->createMock(\Magento\Framework\Api\Search\FilterGroup::class);
357-
$filterInterfaceMock = $this->createMock(\Magento\Framework\Api\Filter::class);
358-
359-
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
360-
361-
$filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterInterfaceMock]);
362-
$filterInterfaceMock->expects($this->once())->method('getField')->willReturn('attribute_set_id');
363-
$filterInterfaceMock->expects($this->once())->method('getValue')->willReturn($attributeSetId);
364-
365-
$searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([]);
366-
$this->setRepositoryMock->expects($this->once())
367-
->method('get')
368-
->with($attributeSetId)
369-
->willThrowException(new \Exception());
370-
$this->model->getList($searchCriteriaMock);
371-
}
372-
373319
/**
374320
* Test get
375321
*

0 commit comments

Comments
 (0)