/**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
Beispiel #2
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 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(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->optionCollection->expects($this->once())->method('setIdFilter')->with($this->equalTo($optionId));
     $this->optionCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->optionModel));
     $this->productType->expects($this->once())->method('getOptionsCollection')->with($this->equalTo($this->product))->will($this->returnValue($this->optionCollection));
     $this->optionModel->expects($this->once())->method('getId');
     $this->model->get($productSku, $optionId);
 }
 public function testGetChildren()
 {
     $productSku = 'productSku';
     $this->getOptions();
     $this->productRepository->expects($this->any())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle'));
     $this->productType->expects($this->once())->method('setStoreFilter')->with($this->equalTo($this->storeId), $this->product);
     $this->productType->expects($this->once())->method('getSelectionsCollection')->with($this->equalTo($this->optionIds), $this->equalTo($this->product))->will($this->returnValue($this->selectionCollection));
     $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product))->will($this->returnValue($this->optionIds));
     $this->optionCollection->expects($this->once())->method('appendSelections')->with($this->equalTo($this->selectionCollection))->will($this->returnValue([$this->option]));
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$this->product]));
     $this->linkConverter->expects($this->once())->method('createDataFromModel')->with($this->equalTo($this->product), $this->equalTo($this->product))->will($this->returnValue($this->link));
     $this->assertEquals([$this->link], $this->model->getChildren($productSku));
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testRemoveChildInvalidChildSku()
 {
     $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product));
     $productSku = 'productSku';
     $optionId = 1;
     $childSku = 'childSku';
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->getRemoveOptions();
     $selection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Selection')->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku . '_invalid'));
     $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId));
     $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55));
     $selection->expects($this->any())->method('getProductId')->will($this->returnValue(1));
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection]));
     $this->model->removeChild($productSku, $optionId, $childSku);
 }