示例#1
0
 public function testGetLinkForWrongCustomer()
 {
     $this->objectManager->expects($this->at(0))->method('get')->with('Magento\\Customer\\Model\\Session')->willReturn($this->session);
     $this->request->expects($this->once())->method('getParam')->with('id', 0)->willReturn('some_id');
     $this->objectManager->expects($this->at(1))->method('create')->with('Magento\\Downloadable\\Model\\Link\\Purchased\\Item')->willReturn($this->linkPurchasedItem);
     $this->linkPurchasedItem->expects($this->once())->method('load')->with('some_id', 'link_hash')->willReturnSelf();
     $this->linkPurchasedItem->expects($this->once())->method('getId')->willReturn(5);
     $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Data')->willReturn($this->helperData);
     $this->helperData->expects($this->once())->method('getIsShareable')->with($this->linkPurchasedItem)->willReturn(false);
     $this->session->expects($this->once())->method('getCustomerId')->willReturn('customer_id');
     $this->objectManager->expects($this->at(3))->method('create')->with('Magento\\Downloadable\\Model\\Link\\Purchased')->willReturn($this->linkPurchased);
     $this->linkPurchasedItem->expects($this->once())->method('getPurchasedId')->willReturn('purchased_id');
     $this->linkPurchased->expects($this->once())->method('load')->with('purchased_id')->willReturnSelf();
     $this->linkPurchased->expects($this->once())->method('getCustomerId')->willReturn('other_customer_id');
     $this->messageManager->expects($this->once())->method('addNotice')->with("We can't find the link you requested.");
     $this->redirect->expects($this->once())->method('redirect')->with($this->response, '*/customer/products', []);
     $this->assertEquals($this->response, $this->link->execute());
 }