Example #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);
 }
Example #2
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('getAssociatedProductIds')->will($this->returnValue([2]));
     $product->expects($this->any())->method('hasData')->with('_cache_instance_used_product_attribute_ids')->will($this->returnValue(true));
     $extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)->setMethods(['getConfigurableProductOptions', 'getConfigurableProductLinks'])->getMockForAbstractClass();
     $this->entityMetadata->expects($this->exactly(2))->method('getLinkField')->willReturn('link');
     $dataMap = [['extension_attributes', null, $extensionAttributes], ['_cache_instance_used_product_attribute_ids', null, 1], ['link', null, 1]];
     $product->expects($this->any())->method('getData')->willReturnMap($dataMap);
     $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\\ResourceModel\\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);
 }
Example #3
0
 public function testSaveProductRelationsNoChildren()
 {
     $childrenIds = $this->_product->getTypeInstance()->getChildrenIds(1);
     $this->assertNotEmpty(reset($childrenIds));
     $this->_product->setAssociatedProductIds([]);
     $this->_model->save($this->_product);
     $this->_product->load(1);
     $this->assertEquals([[]], $this->_product->getTypeInstance()->getChildrenIds(1));
 }