public function testRemove()
 {
     $productSku = 'productSku';
     $optionId = 3;
     $this->productRepositoryMock->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->productMock));
     $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(ConfigurableType::TYPE_CODE));
     $this->productTypeMock->expects($this->once())->method('getConfigurableAttributeCollection')->with($this->equalTo($this->productMock))->will($this->returnValue($this->attributeCollectionMock));
     $this->attributeCollectionMock->expects($this->once())->method('getItemById')->with($this->equalTo($optionId))->will($this->returnValue($this->attributeMock));
     $this->attributeMock->expects($this->once())->method('delete');
     $this->assertTrue($this->writeService->remove($productSku, $optionId));
 }
Exemplo n.º 2
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage Requested option doesn't exist: 3
  */
 public function testGetNoSuchEntityException()
 {
     $productSku = 'oneSku';
     $optionId = 3;
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(ConfigurableType::TYPE_CODE));
     $this->productType->expects($this->once())->method('getConfigurableAttributeCollection')->with($this->equalTo($this->product))->will($this->returnValue($this->configurableAttributeCollection));
     $this->configurableAttributeCollection->expects($this->once())->method('addFieldToFilter')->with(self::ATTRIBUTE_ID_FIELD_NAME, $optionId)->will($this->returnSelf());
     $this->configurableAttributeCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->option));
     $this->option->expects($this->once())->method('getId')->will($this->returnValue(null));
     $this->attributeResource->expects($this->once())->method('getIdFieldName')->will($this->returnValue(self::ATTRIBUTE_ID_FIELD_NAME));
     $this->configurableAttributeCollection->expects($this->once())->method('getResource')->will($this->returnValue($this->attributeResource));
     $this->model->get($productSku, $optionId);
 }
Exemplo n.º 3
0
 public function testGetModelFromData()
 {
     $data = ['data'];
     $id = 33;
     $this->configurableAttribute->expects($this->any())->method('getData')->will($this->returnValue($data));
     $this->configurableAttribute->expects($this->once())->method('setData')->with($this->equalTo($data));
     $this->configurableAttribute->expects($this->once())->method('addData')->with($this->equalTo($data));
     $this->configurableAttribute->expects($this->any())->method('getId')->will($this->returnValue($id));
     $this->configurableAttribute->expects($this->once())->method('setId')->with($this->equalTo($id));
     $this->configurableAttribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($id));
     $this->configurableAttribute->expects($this->once())->method('setAttributeId')->with($this->equalTo($id));
     $this->configurableAttribute->expects($this->any())->method('getValues')->will($this->returnValue($data));
     $this->configurableAttribute->expects($this->any())->method('setValues')->with($this->equalTo($data));
     $this->option->expects($this->any())->method('getValues')->will($this->returnValue([$this->value]));
     $this->option->expects($this->any())->method('__toArray')->will($this->returnValue($data));
     $this->valueConverter->expects($this->any())->method('convertArrayFromData')->with($this->equalTo($this->value))->will($this->returnValue($data[0]));
     $result = $this->converter->getModelFromData($this->option, $this->configurableAttribute);
     $this->assertEquals($this->configurableAttribute, $result);
 }