public function testGetOptions() { $item = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\ItemInterface'); $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getLinksTitle', 'getTypeInstance'])->getMock(); $option = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface'); $productType = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Product\\Type')->disableOriginalConstructor()->setMethods(['getLinks'])->getMock(); $productLink = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link')->disableOriginalConstructor()->setMethods(['getTitle'])->getMock(); $this->productConfig->expects($this->once())->method('getOptions')->with($item); $item->expects($this->any())->method('getProduct')->willReturn($product); $item->expects($this->once())->method('getOptionByCode')->willReturn($option); $product->expects($this->once())->method('getTypeInstance')->willReturn($productType); $productType->expects($this->once())->method('getLinks')->with($product)->willReturn([1 => $productLink]); $option->expects($this->once())->method('getValue')->willReturn(1); $product->expects($this->once())->method('getLinksTitle')->willReturn('links_title'); $productLink->expects($this->once())->method('getTitle')->willReturn('title'); $this->assertEquals([['label' => 'links_title', 'value' => ['title']]], $this->helper->getOptions($item)); }
public function testGetOptions() { $optionIds = 'a:1:{i:0;i:1;}'; $selectionIds = 'a:1:{i:0;s:1:"2";}'; $selectionId = '2'; $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getTypeInstance', '__wakeup', 'getCustomOption', 'getSelectionId', 'getName', 'getPriceModel'], [], '', false); $typeInstance = $this->getMock('Magento\\Bundle\\Model\\Product\\Type', ['getOptionsByIds', 'getSelectionsByIds'], [], '', false); $priceModel = $this->getMock('Magento\\Bundle\\Model\\Product\\Price', ['getSelectionFinalTotalPrice'], [], '', false); $selectionQty = $this->getMock('Magento\\Quote\\Model\\Quote\\Item\\Option', ['getValue', '__wakeup'], [], '', false); $bundleOption = $this->getMock('Magento\\Bundle\\Model\\Option', ['getSelections', 'getTitle', '__wakeup'], [], '', false); $selectionOption = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface', ['getValue']); $collection = $this->getMock('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['appendSelections'], [], '', false); $itemOption = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface', ['getValue']); $collection2 = $this->getMock('Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', [], [], '', false); $this->escaper->expects($this->once())->method('escapeHtml')->with('name')->will($this->returnValue('name')); $this->pricingHelper->expects($this->once())->method('currency')->with(15)->will($this->returnValue('<span class="price">$15.00</span>')); $priceModel->expects($this->once())->method('getSelectionFinalTotalPrice')->will($this->returnValue(15)); $selectionQty->expects($this->any())->method('getValue')->will($this->returnValue(1)); $bundleOption->expects($this->any())->method('getSelections')->will($this->returnValue([$product])); $bundleOption->expects($this->once())->method('getTitle')->will($this->returnValue('title')); $selectionOption->expects($this->once())->method('getValue')->will($this->returnValue($selectionIds)); $collection->expects($this->once())->method('appendSelections')->with($collection2, true)->will($this->returnValue([$bundleOption])); $itemOption->expects($this->once())->method('getValue')->will($this->returnValue($optionIds)); $typeInstance->expects($this->once())->method('getOptionsByIds')->with(unserialize($optionIds), $product)->will($this->returnValue($collection)); $typeInstance->expects($this->once())->method('getSelectionsByIds')->with(unserialize($selectionIds), $product)->will($this->returnValue($collection2)); $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance)); $product->expects($this->any())->method('getCustomOption')->with('selection_qty_' . $selectionId)->will($this->returnValue($selectionQty)); $product->expects($this->any())->method('getSelectionId')->will($this->returnValue($selectionId)); $product->expects($this->once())->method('getName')->will($this->returnValue('name')); $product->expects($this->once())->method('getPriceModel')->will($this->returnValue($priceModel)); $this->item->expects($this->any())->method('getProduct')->will($this->returnValue($product)); $this->item->expects($this->at(1))->method('getOptionByCode')->with('bundle_option_ids')->will($this->returnValue($itemOption)); $this->item->expects($this->at(2))->method('getOptionByCode')->with('bundle_selection_ids')->will($this->returnValue($selectionOption)); $this->productConfiguration->expects($this->once())->method('getCustomOptions')->with($this->item)->will($this->returnValue([0 => ['label' => 'title', 'value' => 'value']])); $this->assertEquals([0 => ['label' => 'title', 'value' => [0 => '1 x name <span class="price">$15.00</span>']], 1 => ['label' => 'title', 'value' => 'value']], $this->helper->getOptions($this->item)); }