Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SendTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class SendTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $model;
17 
21  protected $sendfriendMock;
22 
26  protected $urlBuilderMock;
27 
31  protected $requestMock;
32 
33  protected function setUp()
34  {
35  $objectManager = new ObjectManager($this);
36 
37  $this->sendfriendMock = $this->getMockBuilder(\Magento\SendFriend\Model\SendFriend::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  $this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
41  ->disableOriginalConstructor()
42  ->getMockForAbstractClass();
43  $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
44  ->disableOriginalConstructor()
45  ->getMockForAbstractClass();
46 
47  $this->model = $objectManager->getObject(
48  \Magento\SendFriend\Block\Send::class,
49  [
50  'sendfriend' => $this->sendfriendMock,
51  'urlBuilder' => $this->urlBuilderMock,
52  'request' => $this->requestMock,
53  ]
54  );
55  }
56 
57  public function testGetSendUrl()
58  {
59  $this->requestMock->expects($this->exactly(2))
60  ->method('getParam')
61  ->willReturnMap(
62  [
63  ['id', null, '1'],
64  ['cat_id', null, '2'],
65  ]
66  );
67 
68  $this->urlBuilderMock->expects($this->once())
69  ->method('getUrl')
70  ->with('sendfriend/product/sendmail', ['id' => 1, 'cat_id' => 2])
71  ->willReturn('url');
72 
73  $this->assertEquals('url', $this->model->getSendUrl());
74  }
75 
82  public function testCanSend($isExceedLimit, $result)
83  {
84  $this->sendfriendMock->expects($this->once())
85  ->method('isExceedLimit')
86  ->willReturn($isExceedLimit);
87 
88  $this->assertEquals($result, $this->model->canSend());
89  }
90 
94  public function dataProviderCanSend()
95  {
96  return [
97  [true, false],
98  [false, true],
99  ];
100  }
101 }
$objectManager
Definition: bootstrap.php:17
testCanSend($isExceedLimit, $result)
Definition: SendTest.php:82