From 433c3cd97c327b6130fa34ad2aad15659facafe3 Mon Sep 17 00:00:00 2001 From: Marius Strajeru Date: Wed, 8 Nov 2017 13:31:46 +0200 Subject: [PATCH 1/2] #11936:required attribute set id filter on attribute group repository getList --- .../Eav/Model/Attribute/GroupRepository.php | 10 ---- .../Model/Attribute/GroupRepositoryTest.php | 58 +------------------ 2 files changed, 2 insertions(+), 66 deletions(-) diff --git a/app/code/Magento/Eav/Model/Attribute/GroupRepository.php b/app/code/Magento/Eav/Model/Attribute/GroupRepository.php index 9d0fa78668382..e0b5ac309ba7c 100644 --- a/app/code/Magento/Eav/Model/Attribute/GroupRepository.php +++ b/app/code/Magento/Eav/Model/Attribute/GroupRepository.php @@ -117,16 +117,6 @@ public function save(\Magento\Eav\Api\Data\AttributeGroupInterface $group) */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { - $attributeSetId = $this->retrieveAttributeSetIdFromSearchCriteria($searchCriteria); - if (!$attributeSetId) { - throw InputException::requiredField('attribute_set_id'); - } - try { - $this->setRepository->get($attributeSetId); - } catch (\Exception $exception) { - throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); - } - /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\Collection $collection */ $collection = $this->groupListFactory->create(); $this->joinProcessor->process($collection); diff --git a/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php b/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php index c07122e049a74..9b0f9704887bb 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Attribute/GroupRepositoryTest.php @@ -266,8 +266,6 @@ public function testSaveThrowExceptionIfProvidedGroupDoesNotExist() */ public function testGetList() { - $attributeSetId = 'filter'; - $filterInterfaceMock = $this->getMockBuilder(\Magento\Framework\Api\Search\FilterGroup::class) ->disableOriginalConstructor() ->setMethods([ @@ -275,24 +273,18 @@ public function testGetList() 'getValue', ]) ->getMock(); - $filterInterfaceMock->expects($this->once()) - ->method('getField') - ->willReturn('attribute_set_id'); - $filterInterfaceMock->expects($this->once()) - ->method('getValue') - ->willReturn($attributeSetId); $filterGroupMock = $this->getMockBuilder(\Magento\Framework\Api\Search\FilterGroup::class) ->disableOriginalConstructor() ->getMock(); - $filterGroupMock->expects($this->once()) + $filterGroupMock->expects($this->any()) ->method('getFilters') ->willReturn([$filterInterfaceMock]); $searchCriteriaMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaInterface::class) ->disableOriginalConstructor() ->getMock(); - $searchCriteriaMock->expects($this->once()) + $searchCriteriaMock->expects($this->any()) ->method('getFilterGroups') ->willReturn([$filterGroupMock]); @@ -324,52 +316,6 @@ public function testGetList() $this->assertEquals($searchResultsMock, $this->model->getList($searchCriteriaMock)); } - /** - * Test get list with invalid input exception - * - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage attribute_set_id is a required field. - * @throws \Magento\Framework\Exception\InputException - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @return void - */ - public function testGetListWithInvalidInputException() - { - $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class); - $searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([]); - $this->model->getList($searchCriteriaMock); - } - - /** - * Test get list with no such entity exception - * - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage No such entity with attributeSetId = filter - * @throws \Magento\Framework\Exception\InputException - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @return void - */ - public function testGetListWithNoSuchEntityException() - { - $attributeSetId = 'filter'; - $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class); - $filterGroupMock = $this->createMock(\Magento\Framework\Api\Search\FilterGroup::class); - $filterInterfaceMock = $this->createMock(\Magento\Framework\Api\Filter::class); - - $searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]); - - $filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterInterfaceMock]); - $filterInterfaceMock->expects($this->once())->method('getField')->willReturn('attribute_set_id'); - $filterInterfaceMock->expects($this->once())->method('getValue')->willReturn($attributeSetId); - - $searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([]); - $this->setRepositoryMock->expects($this->once()) - ->method('get') - ->with($attributeSetId) - ->willThrowException(new \Exception()); - $this->model->getList($searchCriteriaMock); - } - /** * Test get * From 7be92a872300f949d349e442c3d8e1045609d8b1 Mon Sep 17 00:00:00 2001 From: Marius Strajeru Date: Wed, 20 Dec 2017 14:36:29 +0200 Subject: [PATCH 2/2] mark method retrieveAttributeSetIdFromSearchCriteria as deprecated --- app/code/Magento/Eav/Model/Attribute/GroupRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Eav/Model/Attribute/GroupRepository.php b/app/code/Magento/Eav/Model/Attribute/GroupRepository.php index e0b5ac309ba7c..0714f8efac88c 100644 --- a/app/code/Magento/Eav/Model/Attribute/GroupRepository.php +++ b/app/code/Magento/Eav/Model/Attribute/GroupRepository.php @@ -178,6 +178,7 @@ public function deleteById($groupId) /** * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return null|string + * @deprecated */ protected function retrieveAttributeSetIdFromSearchCriteria( \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria