Esempio n. 1
0
 /**
  * Test `Save` method
  */
 public function testSave()
 {
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['getIsDuplicate', 'dataHasChangedFor', 'getConfigurableAttributesData', 'getStoreId', 'getId', 'getData', 'hasData', 'getAssociatedProductIds', '__wakeup', '__sleep'])->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue('false'));
     $product->expects($this->any())->method('getConfigurableAttributesData')->will($this->returnValue($this->attributeData));
     $product->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(true));
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2]));
     $product->expects($this->any())->method('hasData')->with('_cache_instance_used_product_attribute_ids')->will($this->returnValue(true));
     $product->expects($this->any())->method('getData')->with('_cache_instance_used_product_attribute_ids')->will($this->returnValue([1]));
     $attribute = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->disableOriginalConstructor()->setMethods(['addData', 'setStoreId', 'setProductId', 'save', '__wakeup', '__sleep'])->getMock();
     $expectedAttributeData = $this->attributeData[1];
     unset($expectedAttributeData['id']);
     $attribute->expects($this->once())->method('addData')->with($expectedAttributeData)->will($this->returnSelf());
     $attribute->expects($this->once())->method('setStoreId')->with(1)->will($this->returnSelf());
     $attribute->expects($this->once())->method('setProductId')->with(1)->will($this->returnSelf());
     $attribute->expects($this->once())->method('save')->will($this->returnSelf());
     $this->_configurableAttributeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($attribute));
     $attributeCollection = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Attribute\\Collection')->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor()->getMock();
     $this->_attributeCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($attributeCollection));
     $this->_typeConfigurableFactory->expects($this->once())->method('create')->will($this->returnSelf());
     $this->_typeConfigurableFactory->expects($this->once())->method('saveProducts')->withAnyParameters()->will($this->returnSelf());
     $this->_model->save($product);
 }