48 $this->helperMock = $this->createMock(\
Magento\Captcha\Helper\Data::class);
49 $this->actionFlagMock = $this->createMock(\
Magento\Framework\
App\ActionFlag::class);
50 $this->messageManagerMock = $this->createMock(\
Magento\Framework\Message\ManagerInterface::class);
51 $this->redirectMock = $this->createMock(\
Magento\Framework\
App\
Response\RedirectInterface::class);
52 $this->captchaStringResolverMock = $this->createMock(\
Magento\Captcha\Observer\CaptchaStringResolver::class);
53 $this->authenticationMock = $this->getMockBuilder(AuthenticationInterface::class)
54 ->disableOriginalConstructor()
57 $this->customerSessionMock = $this->createPartialMock(
58 \
Magento\Customer\Model\Session::class,
59 [
'getCustomerId',
'getCustomer',
'logout',
'start']
61 $this->scopeConfigMock = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
63 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
65 \
Magento\Captcha\Observer\CheckUserEditObserver::class,
67 'helper' => $this->helperMock,
68 'actionFlag' => $this->actionFlagMock,
69 'messageManager' => $this->messageManagerMock,
70 'redirect' => $this->redirectMock,
71 'captchaStringResolver' => $this->captchaStringResolverMock,
72 'authentication' => $this->authenticationMock,
73 'customerSession' => $this->customerSessionMock,
74 'scopeConfig' => $this->scopeConfigMock,
85 $captchaValue =
'some-value';
87 $redirectUrl =
'http://magento.com/customer/account/edit/';
89 $captcha = $this->createMock(\
Magento\Captcha\Model\DefaultModel::class);
91 ->method(
'isRequired')
98 $this->helperMock->expects($this->once())
99 ->method(
'getCaptcha')
100 ->with(\
Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)
107 ->with(\
Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE,
null)
108 ->willReturn([\
Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);
111 $controller->expects($this->any())->method(
'getRequest')->will($this->returnValue(
$request));
114 $this->captchaStringResolverMock->expects($this->once())
116 ->with(
$request, \
Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)
117 ->willReturn($captchaValue);
119 $customerDataMock = $this->createMock(\
Magento\Customer\Model\Data\Customer::class);
121 $this->customerSessionMock->expects($this->once())
122 ->method(
'getCustomerId')
125 $this->customerSessionMock->expects($this->atLeastOnce())
126 ->method(
'getCustomer')
127 ->willReturn($customerDataMock);
129 $this->authenticationMock->expects($this->once())
130 ->method(
'processAuthenticationFailure')
132 $this->authenticationMock->expects($this->once())
137 $this->customerSessionMock->expects($this->once())
139 $this->customerSessionMock->expects($this->once())
142 $this->scopeConfigMock->expects($this->once())
144 ->with(
'contact/email/recipient_email')
147 $message =
__(
'The account is locked. Please wait and try again or contact %1.',
$email);
148 $this->messageManagerMock->expects($this->exactly(2))
150 ->withConsecutive([
$message], [
__(
'Incorrect CAPTCHA')]);
152 $this->actionFlagMock->expects($this->once())
154 ->with(
'', \
Magento\Framework\
App\Action\Action::FLAG_NO_DISPATCH,
true);
156 $this->redirectMock->expects($this->once())
159 ->willReturn($redirectUrl);
161 $this->observer->execute(
new \
Magento\Framework\Event\Observer([
'controller_action' =>
$controller]));
$captchaStringResolverMock