12 use Magento\Catalog\Model\ProductFactory;
18 use PHPUnit_Framework_MockObject_MockObject as MockObject;
29 private $productAttributeRepository;
34 private $productFactory;
49 private $productRepository;
54 private $extensionAttributes;
59 private $eavAttribute;
73 $this->productAttributeRepository = $this->getMockForAbstractClass(ProductAttributeRepositoryInterface::class);
75 $this->productFactory = $this->getMockBuilder(ProductFactory::class)
76 ->disableOriginalConstructor()
77 ->setMethods([
'create'])
80 $this->product = $this->getMockBuilder(Product::class)
81 ->disableOriginalConstructor()
82 ->setMethods([
'getTypeId',
'getExtensionAttributes'])
85 $this->result = $this->getMockBuilder(Product::class)
86 ->disableOriginalConstructor()
87 ->setMethods([
'getExtensionAttributes'])
90 $this->productRepository = $this->getMockForAbstractClass(ProductRepositoryInterface::class);
92 $this->extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
93 ->disableOriginalConstructor()
94 ->setMethods([
'getConfigurableProductOptions',
'getConfigurableProductLinks'])
95 ->getMockForAbstractClass();
97 $this->eavAttribute = $this->getMockForAbstractClass(ProductAttributeInterface::class);
99 $this->option = $this->getMockForAbstractClass(OptionInterface::class);
102 ProductRepositorySave::class,
104 'productAttributeRepository' => $this->productAttributeRepository,
105 'productFactory' => $this->productFactory
112 $this->product->expects(static::once())
113 ->method(
'getTypeId')
114 ->willReturn(
'simple');
115 $this->product->expects(static::never())
116 ->method(
'getExtensionAttributes');
120 $this->plugin->afterSave($this->productRepository, $this->result, $this->product)
126 $this->product->expects(static::once())
127 ->method(
'getTypeId')
130 $this->result->expects(static::once())
131 ->method(
'getExtensionAttributes')
132 ->willReturn($this->extensionAttributes);
134 $this->extensionAttributes->expects(static::once())
135 ->method(
'getConfigurableProductOptions')
137 $this->extensionAttributes->expects(static::once())
138 ->method(
'getConfigurableProductLinks')
141 $this->productAttributeRepository->expects(static::never())
146 $this->plugin->afterSave($this->productRepository, $this->result, $this->product)
157 $this->product->expects(static::once())
158 ->method(
'getTypeId')
161 $this->result->expects(static::once())
162 ->method(
'getExtensionAttributes')
163 ->willReturn($this->extensionAttributes);
164 $this->extensionAttributes->expects(static::once())
165 ->method(
'getConfigurableProductOptions')
167 $this->extensionAttributes->expects(static::once())
168 ->method(
'getConfigurableProductLinks')
171 $this->productAttributeRepository->expects(static::never())
174 $product = $this->getMockBuilder(Product::class)
175 ->disableOriginalConstructor()
176 ->setMethods([
'load',
'getData',
'__wakeup'])
179 $this->productFactory->expects(static::exactly(2))
181 ->willReturn($product);
183 $product->expects(static::exactly(2))
186 $product->expects(static::never())
189 $this->plugin->afterSave($this->productRepository, $this->result, $this->product);
198 $simpleProductId = 4;
199 $links = [$simpleProductId, 5];
203 $this->option->expects(static::once())
204 ->method(
'getAttributeId')
205 ->willReturn($attributeId);
207 $this->product->expects(static::once())
208 ->method(
'getTypeId')
211 $this->result->expects(static::once())
212 ->method(
'getExtensionAttributes')
213 ->willReturn($this->extensionAttributes);
214 $this->extensionAttributes->expects(static::once())
215 ->method(
'getConfigurableProductOptions')
216 ->willReturn([$this->option]);
217 $this->extensionAttributes->expects(static::once())
218 ->method(
'getConfigurableProductLinks')
221 $this->productAttributeRepository->expects(static::once())
223 ->willReturn($this->eavAttribute);
225 $this->eavAttribute->expects(static::once())
226 ->method(
'getAttributeCode')
229 $product = $this->getMockBuilder(Product::class)
230 ->disableOriginalConstructor()
231 ->setMethods([
'load',
'getData',
'__wakeup'])
234 $this->productFactory->expects(static::once())
236 ->willReturn($product);
237 $product->expects(static::once())
239 ->with($simpleProductId)
241 $product->expects(static::once())
246 $this->plugin->afterSave($this->productRepository, $this->result, $this->product);
259 $this->option->expects(static::once())
260 ->method(
'getAttributeId')
261 ->willReturn($attributeId);
263 $this->product->expects(static::once())
264 ->method(
'getTypeId')
267 $this->result->expects(static::once())
268 ->method(
'getExtensionAttributes')
269 ->willReturn($this->extensionAttributes);
270 $this->extensionAttributes->expects(static::once())
271 ->method(
'getConfigurableProductOptions')
272 ->willReturn([$this->option]);
273 $this->extensionAttributes->expects(static::once())
274 ->method(
'getConfigurableProductLinks')
277 $this->productAttributeRepository->expects(static::once())
279 ->willReturn($this->eavAttribute);
281 $this->eavAttribute->expects(static::once())
282 ->method(
'getAttributeCode')
285 $product = $this->getMockBuilder(Product::class)
286 ->disableOriginalConstructor()
287 ->setMethods([
'load',
'getData',
'__wakeup'])
290 $this->productFactory->expects(static::exactly(2))
292 ->willReturn($product);
293 $product->expects(static::exactly(2))
296 $product->expects(static::exactly(4))
299 ->willReturn($attributeId);
301 $this->plugin->afterSave($this->productRepository, $this->result, $this->product);
testAfterSaveWithLinksWithMissingAttribute()
testAfterSaveWithLinksWithDuplicateAttributes()
testAfterSaveWhenProductIsSimple()
testAfterSaveWithoutOptions()