Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SendFriendTest.php
Go to the documentation of this file.
1 <?php
8 
10 
15 class SendFriendTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $model;
21 
25  protected $cookieManagerMock;
26 
31 
32  protected function setUp()
33  {
34  $objectManager = new ObjectManager($this);
35  $this->sendfriendDataMock = $this->getMockBuilder(\Magento\SendFriend\Helper\Data::class)
36  ->disableOriginalConstructor()
37  ->getMock();
38  $this->cookieManagerMock = $this->createMock(\Magento\Framework\Stdlib\CookieManagerInterface::class);
39 
40  $this->model = $objectManager->getObject(
41  \Magento\SendFriend\Model\SendFriend::class,
42  [
43  'sendfriendData' => $this->sendfriendDataMock,
44  'cookieManager' => $this->cookieManagerMock,
45  ]
46  );
47  }
48 
50  {
51  $cookieName = 'testCookieName';
52  $this->sendfriendDataMock->expects($this->once())->method('getLimitBy')->with()->will(
53  $this->returnValue(\Magento\SendFriend\Helper\Data::CHECK_COOKIE)
54  );
55  $this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will(
56  $this->returnValue($cookieName)
57  );
58 
59  $this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName);
60  $this->assertEquals(0, $this->model->getSentCount());
61  }
62 
63  public function testSentCountByCookies()
64  {
65  $cookieName = 'testCookieName';
66  $this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will(
67  $this->returnValue($cookieName)
68  );
69 
70  $this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName);
71  $this->cookieManagerMock->expects($this->once())->method('setSensitiveCookie');
72  $sendFriendClass = new \ReflectionClass(\Magento\SendFriend\Model\SendFriend::class);
73  $method = $sendFriendClass->getMethod('_sentCountByCookies');
74  $method->setAccessible(true);
75  $method->invokeArgs($this->model, [true]);
76  }
77 }
$objectManager
Definition: bootstrap.php:17
$method
Definition: info.phtml:13