Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetRememberMeCheckedStatusObserverTest.php
Go to the documentation of this file.
1 <?php
9 
10 class SetRememberMeCheckedStatusObserverTest 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 $requestMock;
46 
47  protected function setUp()
48  {
49  $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
50  $this->helperMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
51  $this->sessionHelperMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
52  $checkoutMethods = ['setRememberMeChecked', '__wakeUp'];
53  $this->checkoutSessionMock = $this->createPartialMock(
54  \Magento\Checkout\Model\Session::class,
55  $checkoutMethods
56  );
57  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
58  $eventMethods = ['getRequest', '__wakeUp'];
59  $this->eventManagerMock = $this->createPartialMock(\Magento\Framework\Event::class, $eventMethods);
60  $this->model = new \Magento\Persistent\Observer\SetRememberMeCheckedStatusObserver(
61  $this->helperMock,
62  $this->sessionHelperMock,
63  $this->checkoutSessionMock
64  );
65  }
66 
68  {
69  $this->helperMock
70  ->expects($this->once())
71  ->method('canProcess')
72  ->with($this->observerMock)
73  ->will($this->returnValue(false));
74  $this->helperMock->expects($this->never())->method('isEnabled');
75  $this->observerMock->expects($this->never())->method('getEvent');
76  $this->model->execute($this->observerMock);
77  }
78 
80  {
81  $rememberMeCheckbox = 1;
82  $this->helperMock
83  ->expects($this->once())
84  ->method('canProcess')
85  ->with($this->observerMock)
86  ->will($this->returnValue(true));
87  $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
88  $this->helperMock->expects($this->once())->method('isRememberMeEnabled')->will($this->returnValue(true));
89 
90  $this->observerMock
91  ->expects($this->once())
92  ->method('getEvent')
93  ->will($this->returnValue($this->eventManagerMock));
94  $this->eventManagerMock
95  ->expects($this->once())
96  ->method('getRequest')
97  ->will($this->returnValue($this->requestMock));
98  $this->requestMock
99  ->expects($this->once())
100  ->method('getPost')
101  ->with('persistent_remember_me')
102  ->will($this->returnValue($rememberMeCheckbox));
103  $this->sessionHelperMock
104  ->expects($this->once())
105  ->method('setRememberMeChecked')
106  ->with((bool)$rememberMeCheckbox);
107  $this->requestMock
108  ->expects($this->once())
109  ->method('getFullActionName')
110  ->will($this->returnValue('checkout_onepage_saveBilling'));
111  $this->checkoutSessionMock
112  ->expects($this->once())
113  ->method('setRememberMeChecked')
114  ->with((bool)$rememberMeCheckbox);
115  $this->model->execute($this->observerMock);
116  }
117 
119  {
120  $rememberMeCheckbox = 1;
121  $this->helperMock
122  ->expects($this->once())
123  ->method('canProcess')
124  ->with($this->observerMock)
125  ->will($this->returnValue(true));
126  $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
127  $this->helperMock->expects($this->once())->method('isRememberMeEnabled')->will($this->returnValue(true));
128 
129  $this->observerMock
130  ->expects($this->once())
131  ->method('getEvent')
132  ->will($this->returnValue($this->eventManagerMock));
133  $this->eventManagerMock
134  ->expects($this->once())
135  ->method('getRequest')
136  ->will($this->returnValue($this->requestMock));
137  $this->requestMock
138  ->expects($this->once())
139  ->method('getPost')
140  ->with('persistent_remember_me')
141  ->will($this->returnValue($rememberMeCheckbox));
142  $this->sessionHelperMock
143  ->expects($this->once())
144  ->method('setRememberMeChecked')
145  ->with((bool)$rememberMeCheckbox);
146  $this->requestMock
147  ->expects($this->exactly(2))
148  ->method('getFullActionName')
149  ->will($this->returnValue('method_name'));
150  $this->checkoutSessionMock
151  ->expects($this->never())
152  ->method('setRememberMeChecked');
153  $this->model->execute($this->observerMock);
154  }
155 
157  {
158  $this->helperMock
159  ->expects($this->once())
160  ->method('canProcess')
161  ->with($this->observerMock)
162  ->will($this->returnValue(true));
163  $this->helperMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
164  $this->helperMock->expects($this->once())->method('isRememberMeEnabled')->will($this->returnValue(true));
165 
166  $this->observerMock
167  ->expects($this->once())
168  ->method('getEvent')
169  ->will($this->returnValue($this->eventManagerMock));
170  $this->eventManagerMock
171  ->expects($this->once())
172  ->method('getRequest');
173  $this->model->execute($this->observerMock);
174  }
175 }