public function testAroundSaveWithOptions() { $productSku = "configurable_sku"; $this->productInterfaceMock->expects($this->once())->method('getTypeId')->willReturn(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE); //two options with id 5 and 6 $options = $this->setupOptions([5, 6]); //two existing options with id 4 and 5 $this->setupExistingOptions([4, 5]); $this->productMock->expects($this->any())->method('getSku')->will($this->returnValue($productSku)); $this->productOptionRepositoryMock->expects($this->at(0))->method('save')->with($productSku, $options[0]); $this->productOptionRepositoryMock->expects($this->at(1))->method('save')->with($productSku, $options[1]); $this->productOptionRepositoryMock->expects($this->at(2))->method('deleteById')->with($productSku, 4); $configurableProductTypeMock = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock(); $configurableProductTypeMock->expects($this->once())->method('resetConfigurableAttributes')->with($this->productMock)->willReturnSelf(); $this->productMock->expects($this->any())->method('getTypeInstance')->willReturn($configurableProductTypeMock); $newProductMock = $this->setupReload($productSku); $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productInterfaceMock)); }
/** * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Products "5" and "4" have the same set of attribute values. */ public function testAroundSaveWithLinksWithDuplicateAttributes() { $links = [4, 5]; $attributeCode = 'color'; $attributeId = 23; $this->option->expects(static::once())->method('getAttributeId')->willReturn($attributeId); $this->product->expects(static::once())->method('getTypeId')->willReturn(Configurable::TYPE_CODE); $this->result->expects(static::once())->method('getExtensionAttributes')->willReturn($this->extensionAttributes); $this->extensionAttributes->expects(static::once())->method('getConfigurableProductOptions')->willReturn([$this->option]); $this->extensionAttributes->expects(static::once())->method('getConfigurableProductLinks')->willReturn($links); $this->productAttributeRepository->expects(static::once())->method('get')->willReturn($this->eavAttribute); $this->eavAttribute->expects(static::once())->method('getAttributeCode')->willReturn($attributeCode); $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->setMethods(['load', 'getData', '__wakeup'])->getMock(); $this->productFactory->expects(static::exactly(2))->method('create')->willReturn($product); $product->expects(static::exactly(2))->method('load')->willReturnSelf(); $product->expects(static::exactly(4))->method('getData')->with($attributeCode)->willReturn($attributeId); $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product); }