CustomerDataTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Persistent\Test\Unit\Model\Plugin;
  7. class CustomerDataTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Persistent\Model\Plugin\CustomerData
  11. */
  12. protected $plugin;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $helperMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $customerSessionMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $persistentSessionMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $subjectMock;
  29. protected function setUp()
  30. {
  31. $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
  32. $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
  33. $this->persistentSessionMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
  34. $this->subjectMock = $this->createMock(\Magento\Customer\CustomerData\Customer::class);
  35. $this->plugin = new \Magento\Persistent\Model\Plugin\CustomerData(
  36. $this->helperMock,
  37. $this->customerSessionMock,
  38. $this->persistentSessionMock
  39. );
  40. }
  41. public function testAroundGetSectionDataForPersistentSession()
  42. {
  43. $result = 'result';
  44. $proceed = function () use ($result) {
  45. return $result;
  46. };
  47. $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
  48. $this->helperMock->expects($this->once())->method('isEnabled')->willReturn(true);
  49. $this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(true);
  50. $this->assertEquals([], $this->plugin->aroundGetSectionData($this->subjectMock, $proceed));
  51. }
  52. public function testAroundGetSectionData()
  53. {
  54. $result = 'result';
  55. $proceed = function () use ($result) {
  56. return $result;
  57. };
  58. $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
  59. $this->helperMock->expects($this->once())->method('isEnabled')->willReturn(true);
  60. $this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(false);
  61. $this->assertEquals($result, $this->plugin->aroundGetSectionData($this->subjectMock, $proceed));
  62. }
  63. }