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()); }