Exemplo n.º 1
0
 /**
  * Test getValue()
  */
 public function testGetValue()
 {
     $price = 100;
     $minPrice = 10;
     $optionId = 1;
     $type = 'select';
     $optionValueMax = $this->getOptionValueMock($price);
     $optionValueMin = $this->getOptionValueMock($minPrice);
     $optionItemMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Option')->disableOriginalConstructor()->setMethods(['getValues', '__wakeup', 'getIsRequire', 'getId', 'getType'])->getMock();
     $optionItemMock->expects($this->once())->method('getId')->will($this->returnValue($optionId));
     $optionItemMock->expects($this->once())->method('getType')->will($this->returnValue($type));
     $optionItemMock->expects($this->once())->method('getIsRequire')->will($this->returnValue(true));
     $optionItemMock->expects($this->any())->method('getValues')->will($this->returnValue([$optionValueMax, $optionValueMin]));
     $options = [$optionItemMock];
     $this->product->expects($this->once())->method('getOptions')->will($this->returnValue($options));
     $result = $this->object->getValue();
     $this->assertCount(1, $result);
     $this->assertArrayHasKey('option_id', $result[0]);
     $this->assertArrayHasKey('type', $result[0]);
     $this->assertArrayHasKey('min', $result[0]);
     $this->assertEquals($minPrice, $result[0]['min']);
 }
 /**
  * Test getValue()
  */
 public function testGetValue()
 {
     $option1Id = 1;
     $option1MaxPrice = 100;
     $option1MinPrice = 10;
     $option1Type = 'select';
     $option2Id = 2;
     $option2MaxPrice = 200;
     $option2MinPrice = 20;
     $option2Type = Option::OPTION_TYPE_CHECKBOX;
     $optionsData = [['id' => $option1Id, 'type' => $option1Type, 'max_option_price' => $option1MaxPrice, 'min_option_price' => $option1MinPrice, 'is_require' => true], ['id' => $option2Id, 'type' => $option2Type, 'max_option_price' => $option2MaxPrice, 'min_option_price' => $option2MinPrice, 'is_require' => false]];
     $singleValueOptionId = 3;
     $singleValueOptionPrice = '50';
     $singleValueOptionType = 'text';
     $singleValueOptions = $this->setupSingleValueOptions([['id' => $singleValueOptionId, 'type' => $singleValueOptionType, 'price' => $singleValueOptionPrice, 'price_type' => 'fixed', 'is_require' => true]]);
     $options = $this->setupOptions($optionsData);
     $options[] = $singleValueOptions[0];
     $this->product->expects($this->once())->method('getOptions')->will($this->returnValue($options));
     $expectedResult = [['option_id' => $option1Id, 'type' => $option1Type, 'min' => $option1MinPrice, 'max' => $option1MaxPrice], ['option_id' => $option2Id, 'type' => $option2Type, 'min' => 0.0, 'max' => $option2MaxPrice + $option2MinPrice], ['option_id' => $singleValueOptionId, 'type' => $singleValueOptionType, 'min' => $singleValueOptionPrice, 'max' => $singleValueOptionPrice]];
     $result = $this->object->getValue();
     $this->assertEquals($expectedResult, $result);
 }