SendFriendTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SendFriend\Test\Unit\Model;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. /**
  9. * Test SendFriend
  10. *
  11. */
  12. class SendFriendTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\SendFriend\Model\SendFriend
  16. */
  17. protected $model;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Stdlib\CookieManagerInterface
  20. */
  21. protected $cookieManagerMock;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $sendfriendDataMock;
  26. protected function setUp()
  27. {
  28. $objectManager = new ObjectManager($this);
  29. $this->sendfriendDataMock = $this->getMockBuilder(\Magento\SendFriend\Helper\Data::class)
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->cookieManagerMock = $this->createMock(\Magento\Framework\Stdlib\CookieManagerInterface::class);
  33. $this->model = $objectManager->getObject(
  34. \Magento\SendFriend\Model\SendFriend::class,
  35. [
  36. 'sendfriendData' => $this->sendfriendDataMock,
  37. 'cookieManager' => $this->cookieManagerMock,
  38. ]
  39. );
  40. }
  41. public function testGetSentCountWithCheckCookie()
  42. {
  43. $cookieName = 'testCookieName';
  44. $this->sendfriendDataMock->expects($this->once())->method('getLimitBy')->with()->will(
  45. $this->returnValue(\Magento\SendFriend\Helper\Data::CHECK_COOKIE)
  46. );
  47. $this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will(
  48. $this->returnValue($cookieName)
  49. );
  50. $this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName);
  51. $this->assertEquals(0, $this->model->getSentCount());
  52. }
  53. public function testSentCountByCookies()
  54. {
  55. $cookieName = 'testCookieName';
  56. $this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will(
  57. $this->returnValue($cookieName)
  58. );
  59. $this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName);
  60. $this->cookieManagerMock->expects($this->once())->method('setSensitiveCookie');
  61. $sendFriendClass = new \ReflectionClass(\Magento\SendFriend\Model\SendFriend::class);
  62. $method = $sendFriendClass->getMethod('_sentCountByCookies');
  63. $method->setAccessible(true);
  64. $method->invokeArgs($this->model, [true]);
  65. }
  66. }