Esempio n. 1
0
 public function testPrepareJsonAttributes()
 {
     $options = [];
     $attributeId = 1;
     $attributeCode = 'test_attribute';
     $attributeLabel = 'Test';
     $pricingValue = 100;
     $amount = 120;
     $modifiedValue = 140;
     $valueIndex = 2;
     $optionId = 1;
     $expected = ['priceOptions' => [$attributeId => ['id' => $attributeId, 'code' => $attributeCode, 'label' => $attributeLabel, 'options' => [0 => ['id' => $valueIndex, 'label' => $attributeLabel, 'price' => $modifiedValue, 'oldPrice' => $modifiedValue, 'inclTaxPrice' => $modifiedValue, 'exclTaxPrice' => $pricingValue, 'products' => []]]]], 'defaultValues' => [$attributeId => $optionId]];
     $attributePrices = [['is_percent' => false, 'pricing_value' => $pricingValue, 'value_index' => $valueIndex, 'label' => $attributeLabel]];
     $configurableAttributes = [$this->getAttributeMock($attributeId, $attributeCode, $attributeLabel, $attributePrices)];
     $configuredValueMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock();
     $configuredValueMock->expects($this->any())->method('getData')->will($this->returnValue($optionId));
     $configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock();
     $configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->equalTo($this->saleableItemMock))->will($this->returnValue($configurableAttributes));
     $this->saleableItemMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($configurableProduct));
     $this->saleableItemMock->expects($this->any())->method('setParentId');
     $this->saleableItemMock->expects($this->any())->method('hasPreconfiguredValues')->will($this->returnValue(true));
     $this->saleableItemMock->expects($this->any())->method('getPreconfiguredValues')->will($this->returnValue($configuredValueMock));
     $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo($pricingValue), $this->equalTo($this->saleableItemMock))->will($this->returnValue($amount));
     $this->calculatorMock->expects($this->any())->method('getAmount')->will($this->returnValue($this->getModifiedAmountMock($modifiedValue, $pricingValue)));
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('convertPrice')->with($this->equalTo($modifiedValue))->will($this->returnArgument(0));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     $result = $this->attribute->prepareAttributes($options);
     $this->assertEquals($expected, $result);
 }