Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RemovePersistentCookieOnRegisterObserverTest.php
Go to the documentation of this file.
1 <?php
9 
10 use \Magento\Persistent\Observer\RemovePersistentCookieOnRegisterObserver;
11 
12 class RemovePersistentCookieOnRegisterObserverTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $model;
18 
23 
28 
33 
37  protected $quoteManagerMock;
38 
42  protected $observerMock;
43 
47  protected $sessionModelMock;
48 
49  protected function setUp()
50  {
51  $this->persistentSessionMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
52  $this->sessionModelMock = $this->createMock(\Magento\Persistent\Model\Session::class);
53  $this->persistentDataMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
54  $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
55  $this->quoteManagerMock = $this->createMock(\Magento\Persistent\Model\QuoteManager::class);
56  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
57 
59  $this->persistentSessionMock,
60  $this->persistentDataMock,
61  $this->customerSessionMock,
62  $this->quoteManagerMock
63  );
64  }
65 
67  {
68  $this->persistentDataMock->expects($this->once())
69  ->method('canProcess')->with($this->observerMock)->will($this->returnValue(false));
70  $this->persistentSessionMock->expects($this->never())->method('getSession');
71 
72  $this->model->execute($this->observerMock);
73  }
74 
76  {
77  $this->persistentDataMock->expects($this->once())
78  ->method('canProcess')->with($this->observerMock)->will($this->returnValue(true));
79  $this->persistentSessionMock->expects($this->once())->method('isPersistent')->will($this->returnValue(false));
80 
81  $this->persistentSessionMock->expects($this->never())->method('getSession');
82 
83  $this->model->execute($this->observerMock);
84  }
85 
87  {
88  $this->persistentDataMock->expects($this->once())
89  ->method('canProcess')->with($this->observerMock)->will($this->returnValue(true));
90  $this->persistentSessionMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
91  $this->persistentSessionMock->expects($this->once())
92  ->method('getSession')->will($this->returnValue($this->sessionModelMock));
93  $this->sessionModelMock->expects($this->once())->method('removePersistentCookie')->will($this->returnSelf());
94  $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
95  $this->customerSessionMock->expects($this->once())
96  ->method('setCustomerId')->with(null)->will($this->returnSelf());
97  $this->customerSessionMock->expects($this->once())
98  ->method('setCustomerGroupId')->with(null)->will($this->returnSelf());
99  $this->quoteManagerMock->expects($this->once())->method('setGuest');
100 
101  $this->model->execute($this->observerMock);
102  }
103 
104  public function testExecute()
105  {
106  $this->persistentDataMock->expects($this->once())
107  ->method('canProcess')->with($this->observerMock)->will($this->returnValue(true));
108  $this->persistentSessionMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
109  $this->persistentSessionMock->expects($this->once())
110  ->method('getSession')->will($this->returnValue($this->sessionModelMock));
111  $this->sessionModelMock->expects($this->once())->method('removePersistentCookie')->will($this->returnSelf());
112  $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
113  $this->customerSessionMock->expects($this->never())->method('setCustomerId');
114  $this->customerSessionMock->expects($this->never())->method('setCustomerGroupId');
115  $this->quoteManagerMock->expects($this->once())->method('setGuest');
116 
117  $this->model->execute($this->observerMock);
118  }
119 }