21 use Magento\Eav\Api\Data\AttributeGroupInterfaceFactory;
33 private $objectManager;
48 private $productBuilderMock;
53 private $resultJsonFactoryMock;
63 private $attributeSetRepositoryMock;
68 private $attributeSetInterfaceMock;
73 private $searchCriteriaBuilderMock;
78 private $searchCriteriaMock;
83 private $attributeGroupRepositoryMock;
88 private $attributeGroupSearchResultsMock;
93 private $attributeGroupInterfaceFactoryMock;
98 private $attributeGroupInterfaceMock;
108 $this->contextMock = $this->getMockBuilder(Context::class)
109 ->disableOriginalConstructor()
111 $this->productBuilderMock = $this->getMockBuilder(ProductBuilder::class)
112 ->disableOriginalConstructor()
114 $this->resultJsonFactoryMock = $this->getMockBuilder(JsonFactory::class)
115 ->disableOriginalConstructor()
116 ->setMethods([
'create'])
118 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
119 ->setMethods([
'getParam',
'setParam'])
120 ->getMockForAbstractClass();
121 $this->contextMock->expects($this->once())
122 ->method(
'getRequest')
123 ->willReturn($this->requestMock);
124 $this->attributeSetRepositoryMock = $this->getMockBuilder(AttributeSetRepositoryInterface::class)
125 ->setMethods([
'get'])
126 ->getMockForAbstractClass();
127 $this->attributeSetInterfaceMock = $this->getMockBuilder(AttributeSetInterface::class)
128 ->getMockForAbstractClass();
129 $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)
130 ->disableOriginalConstructor()
131 ->setMethods([
'addFilter',
'create',
'setPageSize',
'addSortOrder'])
132 ->getMockForAbstractClass();
133 $this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)
134 ->disableOriginalConstructor()
136 $this->attributeGroupRepositoryMock = $this->getMockBuilder(AttributeGroupRepositoryInterface::class)
137 ->setMethods([
'getList'])
138 ->getMockForAbstractClass();
139 $this->attributeGroupSearchResultsMock = $this->getMockBuilder(AttributeGroupSearchResultsInterface::class)
140 ->setMethods([
'getItems'])
141 ->getMockForAbstractClass();
142 $this->attributeGroupInterfaceFactoryMock = $this->getMockBuilder(AttributeGroupInterfaceFactory::class)
143 ->setMethods([
'create'])
144 ->disableOriginalConstructor()
146 $this->attributeGroupInterfaceMock = $this->getMockBuilder(AttributeGroupInterface::class)
147 ->setMethods([
'getExtensionAttributes'])
148 ->getMockForAbstractClass();
149 $this->jsonMock = $this->getMockBuilder(Json::class)
150 ->disableOriginalConstructor()
153 $this->controller = $this->objectManager->getObject(
154 AddAttributeToTemplate::class,
156 'context' => $this->contextMock,
157 'productBuilder' => $this->productBuilderMock,
158 'resultJsonFactory' => $this->resultJsonFactoryMock,
162 $this->objectManager->setBackwardCompatibleProperty(
164 'attributeSetRepository',
165 $this->attributeSetRepositoryMock
167 $this->objectManager->setBackwardCompatibleProperty(
169 'searchCriteriaBuilder',
170 $this->searchCriteriaBuilderMock
172 $this->objectManager->setBackwardCompatibleProperty(
174 'attributeGroupRepository',
175 $this->attributeGroupRepositoryMock
177 $this->objectManager->setBackwardCompatibleProperty(
179 'attributeGroupFactory',
180 $this->attributeGroupInterfaceFactoryMock
186 $groupCode =
'attributes';
187 $groupName =
'Attributes';
188 $groupSortOrder =
'15';
191 'selected' => [
"178"],
196 ->expects($this->any())
200 [
'groupCode',
null, $groupCode],
201 [
'groupName',
null, $groupName],
202 [
'groupSortOrder',
null, $groupSortOrder],
204 [
'attributeIds', [], $attributeIds]
208 $this->attributeSetRepositoryMock->expects($this->once())
210 ->willReturn($this->attributeSetInterfaceMock);
212 $this->searchCriteriaBuilderMock->expects($this->any())
213 ->method(
'addFilter')
215 $this->searchCriteriaBuilderMock->expects($this->any())
217 ->willReturn($this->searchCriteriaMock);
218 $this->searchCriteriaBuilderMock->expects($this->once())
219 ->method(
'setPageSize')
221 $this->searchCriteriaBuilderMock->expects($this->never())
222 ->method(
'addSortOrder')
225 $this->attributeGroupRepositoryMock->expects($this->once())
227 ->willReturn($this->attributeGroupSearchResultsMock);
228 $this->attributeGroupSearchResultsMock->expects($this->once())
232 $this->attributeGroupInterfaceFactoryMock->expects($this->once())
234 ->willReturn($this->attributeGroupInterfaceMock);
235 $this->attributeGroupInterfaceMock->expects($this->once())
236 ->method(
'getExtensionAttributes')
239 $this->resultJsonFactoryMock->expects($this->once())
241 ->willReturn($this->jsonMock);
242 $this->jsonMock->expects($this->once())->method(
'setJsonData')
245 $this->controller->execute();
testExecuteWithoutAttributeGroupItems()