Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PreventClearCheckoutSessionObserverTest.php
Go to the documentation of this file.
1 <?php
9 
10 class PreventClearCheckoutSessionObserverTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
21 
25  protected $sessionHelperMock;
26 
30  protected $helperMock;
31 
35  protected $observerMock;
36 
40  protected $eventMock;
41 
45  protected $actionMock;
46 
50  protected $customerMock;
51 
52  protected function setUp()
53  {
54  $eventMethods = ['getControllerAction', 'dispatch', '__wakeUp'];
55  $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
56  $this->sessionHelperMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
57  $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
58  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
59  $this->eventMock = $this->createPartialMock(\Magento\Framework\Event::class, $eventMethods);
60  $this->actionMock = $this->createMock(\Magento\Persistent\Controller\Index::class);
61  $this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($this->eventMock));
62  $this->model = new \Magento\Persistent\Observer\PreventClearCheckoutSessionObserver(
63  $this->sessionHelperMock,
64  $this->helperMock,
65  $this->customerSessionMock
66  );
67  }
68 
70  {
71  $this->eventMock
72  ->expects($this->once())
73  ->method('getControllerAction')
74  ->will($this->returnValue($this->actionMock));
75  $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
76  $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
77  $this->helperMock->expects($this->never())->method('isShoppingCartPersist');
78  $this->actionMock->expects($this->once())->method('setClearCheckoutSession')->with(false);
79  $this->model->execute($this->observerMock);
80  }
81 
83  {
84  $this->eventMock
85  ->expects($this->once())
86  ->method('getControllerAction')
87  ->will($this->returnValue($this->actionMock));
88  $this->sessionHelperMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
89  $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
90  $this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(false));
91  $this->actionMock->expects($this->once())->method('setClearCheckoutSession')->with(false);
92  $this->model->execute($this->observerMock);
93  }
94 
96  {
97  $this->eventMock
98  ->expects($this->once())
99  ->method('getControllerAction');
100  $this->sessionHelperMock->expects($this->never())->method('isPersistent');
101  $this->actionMock->expects($this->never())->method('setClearCheckoutSession');
102  $this->model->execute($this->observerMock);
103  }
104 }