Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynchronizePersistentInfoObserverTest.php
Go to the documentation of this file.
1 <?php
9 
10 class SynchronizePersistentInfoObserverTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
20  protected $helperMock;
21 
25  protected $sessionHelperMock;
26 
31 
35  protected $observerMock;
36 
40  protected $eventManagerMock;
41 
45  protected $sessionMock;
46 
50  protected $requestMock;
51 
52  protected function setUp()
53  {
54  $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
55  $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
56  $this->sessionHelperMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
57  $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
58  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
59  $eventMethods = ['getRequest', '__wakeUp'];
60  $this->eventManagerMock = $this->createPartialMock(\Magento\Framework\Event::class, $eventMethods);
61  $this->sessionMock = $this->createMock(\Magento\Persistent\Model\Session::class);
62  $this->model = new \Magento\Persistent\Observer\SynchronizePersistentInfoObserver(
63  $this->helperMock,
64  $this->sessionHelperMock,
65  $this->customerSessionMock
66  );
67  }
68 
70  {
71  $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
72  $this->sessionHelperMock->expects($this->never())->method('getSession');
73  $this->model->execute($this->observerMock);
74  }
75 
77  {
78  $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
79  $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
80  $this->sessionHelperMock
81  ->expects($this->once())
82  ->method('getSession')
83  ->will($this->returnValue($this->sessionMock));
84  $this->observerMock
85  ->expects($this->once())
86  ->method('getEvent')
87  ->will($this->returnValue($this->eventManagerMock));
88  $this->eventManagerMock
89  ->expects($this->once())
90  ->method('getRequest')
91  ->will($this->returnValue($this->requestMock));
92  $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
93  $this->requestMock
94  ->expects($this->once())
95  ->method('getFullActionName')
96  ->will($this->returnValue('customer_account_logout'));
97  $this->sessionMock->expects($this->once())->method('save');
98  $this->model->execute($this->observerMock);
99  }
100 }