/** * Enter description here... * * @return Purchased */ public function getLinks() { $this->_purchased = $this->_purchasedFactory->create()->load($this->getItem()->getOrder()->getId(), 'order_id'); $purchasedLinks = $this->_itemsFactory->create()->addFieldToFilter('order_item_id', $this->getItem()->getOrderItem()->getId()); $this->_purchased->setPurchasedItems($purchasedLinks); return $this->_purchased; }
public function testGetLinks() { $item = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods(['getId'])->getMock(); $linkPurchased = $this->getMockBuilder('Magento\\Downloadable\\Model\\Link\\Purchased')->disableOriginalConstructor()->setMethods(['load'])->getMock(); $itemCollection = $this->getMockBuilder('Magento\\Downloadable\\Model\\ResourceModel\\Link\\Purchased\\Item\\Collection')->disableOriginalConstructor()->setMethods(['addFieldToFilter'])->getMock(); $this->block->setData('item', $item); $this->purchasedFactory->expects($this->once())->method('create')->willReturn($linkPurchased); $linkPurchased->expects($this->once())->method('load')->with('itemId', 'order_item_id')->willReturnSelf(); $item->expects($this->any())->method('getId')->willReturn('itemId'); $this->itemsFactory->expects($this->once())->method('create')->willReturn($itemCollection); $itemCollection->expects($this->once())->method('addFieldToFilter')->with('order_item_id', 'itemId')->willReturnSelf(); $this->assertEquals($linkPurchased, $this->block->getLinks()); }
/** * @return \Magento\Downloadable\Model\Link\Purchased */ protected function _createPurchasedModel() { return $this->_purchasedFactory->create(); }