65 $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
66 $this->_helper = $this->createMock(\
Magento\Captcha\Helper\Data::class);
67 $this->_actionFlag = $this->createMock(\
Magento\Framework\
App\ActionFlag::class);
68 $this->_messageManager = $this->createMock(\
Magento\Framework\Message\ManagerInterface::class);
69 $this->_session = $this->createMock(\
Magento\Framework\Session\SessionManager::class);
70 $this->_urlManager = $this->createMock(\
Magento\Framework\Url::class);
71 $this->captchaStringResolver = $this->createMock(\
Magento\Captcha\Observer\CaptchaStringResolver::class);
72 $this->redirect = $this->createMock(\
Magento\Framework\
App\
Response\RedirectInterface::class);
73 $this->checkUserCreateObserver = $this->_objectManager->getObject(
74 \
Magento\Captcha\Observer\CheckUserCreateObserver::class,
76 'helper' => $this->_helper,
77 'actionFlag' => $this->_actionFlag,
78 'messageManager' => $this->_messageManager,
79 'session' => $this->_session,
80 'urlManager' => $this->_urlManager,
81 'redirect' => $this->redirect,
82 'captchaStringResolver' => $this->captchaStringResolver
85 $this->_captcha = $this->createMock(\
Magento\Captcha\Model\DefaultModel::class);
90 $formId =
'user_create';
91 $captchaValue =
'some-value';
92 $warningMessage =
'Incorrect CAPTCHA';
93 $redirectRoutePath =
'*/*/create';
94 $redirectUrl =
'http://magento.com/customer/account/create/';
98 $this->redirect->expects(
105 $this->returnValue($redirectUrl)
109 $response->expects($this->once())->method(
'setRedirect')->with($redirectUrl);
111 $this->_urlManager->expects(
117 [
'_nosecret' =>
true]
119 $this->returnValue($redirectUrl)
123 $controller->expects($this->any())->method(
'getRequest')->will($this->returnValue(
$request));
125 $this->_captcha->expects($this->any())->method(
'isRequired')->will($this->returnValue(
true));
126 $this->_captcha->expects(
133 $this->returnValue(
false)
135 $this->captchaStringResolver->expects(
143 $this->returnValue($captchaValue)
145 $this->_helper->expects(
152 $this->returnValue($this->_captcha)
154 $this->_messageManager->expects($this->once())->method(
'addError')->with($warningMessage);
155 $this->_actionFlag->expects(
161 \
Magento\Framework\
App\Action\Action::FLAG_NO_DISPATCH,
165 $this->checkUserCreateObserver->execute(
testCheckUserCreateRedirectsError()