public function testAroundSaveWhenProductIsBundleWithOptions() { $this->productMock->expects($this->once())->method('getTypeId')->willReturn('bundle'); $this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtensionMock); $this->productExtensionMock->expects($this->once())->method('getBundleProductOptions')->willReturn([$this->productBundleOptionsMock]); $this->productOptionRepositoryMock->expects($this->once())->method('save')->with($this->productMock, $this->productBundleOptionsMock); $this->assertEquals($this->productMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock)); }
/** * Test the case where the product has existing options */ public function testAroundSaveWhenProductIsBundleWithOptionsAndExistingOptions() { $existOption1Id = 10; $existOption2Id = 11; $productSku = 'bundle_sku'; $existingOption1 = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface'); $existingOption1->expects($this->once())->method('getOptionId')->will($this->returnValue($existOption1Id)); $existingOption2 = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface'); $existingOption2->expects($this->once())->method('getOptionId')->will($this->returnValue($existOption2Id)); $bundleOptionExisting = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface'); $bundleOptionExisting->expects($this->once())->method('getOptionId')->will($this->returnValue($existOption1Id)); $bundleOptionNew = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface'); $bundleOptionNew->expects($this->once())->method('getOptionId')->will($this->returnValue(null)); $this->productMock->expects($this->once())->method('getTypeId')->willReturn('bundle'); $this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtensionMock); $this->productExtensionMock->expects($this->once())->method('getBundleProductOptions')->willReturn([$bundleOptionExisting, $bundleOptionNew]); $this->productMock->expects($this->exactly(2))->method('getSku')->will($this->returnValue($productSku)); $this->productOptionRepositoryMock->expects($this->once())->method('getList')->with($productSku)->will($this->returnValue([$existingOption1, $existingOption2])); $this->productOptionRepositoryMock->expects($this->at(1))->method('save')->with($this->productMock, $bundleOptionExisting); $this->productOptionRepositoryMock->expects($this->at(1))->method('save')->with($this->productMock, $bundleOptionNew); $this->productOptionRepositoryMock->expects($this->once())->method('delete')->with($existingOption2); $newProductMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->disableOriginalConstructor()->getMock(); $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku, false, null, true)->willReturn($newProductMock); $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock)); }