@@ -160,4 +160,53 @@ public function testExecute()
160
160
161
161
$ this ->observer ->execute (new \Magento \Framework \Event \Observer (['controller_action ' => $ controller ]));
162
162
}
163
+
164
+ /**
165
+ * @return void
166
+ */
167
+ public function testExecuteWithCustomerIdNull ()
168
+ {
169
+ $ customerId = null ;
170
+ $ captchaValue = 'some-value ' ;
171
+
172
+ $ captcha = $ this ->createMock (\Magento \Captcha \Model \DefaultModel::class);
173
+ $ captcha ->expects ($ this ->once ())
174
+ ->method ('isRequired ' )
175
+ ->willReturn (true );
176
+ $ captcha ->expects ($ this ->once ())
177
+ ->method ('isCorrect ' )
178
+ ->with ($ captchaValue )
179
+ ->willReturn (false );
180
+
181
+ $ this ->helperMock ->expects ($ this ->once ())
182
+ ->method ('getCaptcha ' )
183
+ ->with (\Magento \Captcha \Observer \CheckUserEditObserver::FORM_ID )
184
+ ->willReturn ($ captcha );
185
+
186
+ $ request = $ this ->createMock (\Magento \Framework \App \Request \Http::class);
187
+ $ request ->expects ($ this ->any ())
188
+ ->method ('getPost ' )
189
+ ->with (\Magento \Captcha \Helper \Data::INPUT_NAME_FIELD_VALUE , null )
190
+ ->willReturn ([\Magento \Captcha \Observer \CheckUserEditObserver::FORM_ID => $ captchaValue ]);
191
+
192
+ $ controller = $ this ->createMock (\Magento \Framework \App \Action \Action::class);
193
+ $ controller ->expects ($ this ->any ())->method ('getRequest ' )->will ($ this ->returnValue ($ request ));
194
+
195
+ $ this ->captchaStringResolverMock ->expects ($ this ->once ())
196
+ ->method ('resolve ' )
197
+ ->with ($ request , \Magento \Captcha \Observer \CheckUserEditObserver::FORM_ID )
198
+ ->willReturn ($ captchaValue );
199
+
200
+ $ customerDataMock = $ this ->createMock (\Magento \Customer \Model \Data \Customer::class);
201
+
202
+ $ this ->customerSessionMock ->expects ($ this ->once ())
203
+ ->method ('getCustomerId ' )
204
+ ->willReturn ($ customerId );
205
+
206
+ $ this ->customerSessionMock ->expects ($ this ->atLeastOnce ())
207
+ ->method ('getCustomer ' )
208
+ ->willReturn ($ customerDataMock );
209
+
210
+ $ this ->observer ->execute (new \Magento \Framework \Event \Observer (['controller_action ' => $ controller ]));
211
+ }
163
212
}
0 commit comments