25 'font' =>
'linlibertine',
26 'mode' =>
'after_fail',
27 'forms' =>
'user_forgotpassword,user_create',
28 'failed_attempts_login' =>
'3',
29 'failed_attempts_ip' =>
'1000',
32 'symbols' =>
'ABCDEFGHJKMnpqrstuvwxyz23456789',
33 'case_sensitive' =>
'0',
34 'shown_to_logged_in_user' => [
'contact_us' => 1],
37 'user_forgotpassword',
53 'label' =>
'LinLibertine',
54 'path' =>
'lib/internal/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf',
91 $this->_storeManager = $this->createPartialMock(\
Magento\Store\Model\StoreManager::class, [
'getStore']);
92 $this->_storeManager->expects(
101 $this->_objectManager = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
102 $this->_objectManager->expects(
107 $this->returnValueMap(
110 \
Magento\Customer\Model\Session::class => $this->session,
115 $this->_resLogFactory = $this->createPartialMock(
119 $this->_resLogFactory->expects(
127 $this->_object = new \Magento\Captcha\Model\DefaultModel(
130 $this->_resLogFactory,
140 $this->assertEquals($this->_object->getBlockName(), \Magento\Captcha\Block\Captcha\DefaultCaptcha::class);
148 $this->assertTrue($this->_object->isRequired());
156 self::$_defaultConfig[
'case_sensitive'] =
'1';
157 $this->assertEquals($this->_object->isCaseSensitive(),
'1');
158 self::$_defaultConfig[
'case_sensitive'] =
'0';
159 $this->assertEquals($this->_object->isCaseSensitive(),
'0');
167 $this->assertEquals($this->_object->getFont(), $this->_fontPath[
'LinLibertine'][
'path']);
176 $this->assertEquals($this->_object->getTimeout(), self::$_defaultConfig[
'timeout'] * 60);
184 self::$_defaultConfig[
'case_sensitive'] =
'1';
185 $this->assertFalse($this->_object->isCorrect(
'abcdef5'));
187 $this->_object->getSession()->setData($sessionData);
188 self::$_defaultConfig[
'case_sensitive'] =
'0';
189 $this->assertTrue($this->_object->isCorrect(
'abcdef5'));
198 $this->_object->getImgSrc(),
199 'http://localhost/pub/media/captcha/base/' . $this->_object->getId() .
'.png' 208 $captcha = new \Magento\Captcha\Model\DefaultModel(
211 $this->_resLogFactory,
217 $this->assertEquals(
$captcha->getSession()->getData(
'user_create_show_captcha'), 1);
225 $this->assertEquals($this->_object->getWord(),
'AbCdEf5');
226 $this->_object->getSession()->setData(
227 [
'user_create_word' => [
'data' =>
'AbCdEf5',
'expires' =>
time() - 360]]
229 $this->assertNull($this->_object->getWord());
239 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
240 $sessionArgs =
$helper->getConstructArguments(
241 \
Magento\Customer\Model\Session::class,
242 [
'storage' =>
new \
Magento\Framework\Session\Storage()]
244 $session = $this->getMockBuilder(\
Magento\Customer\Model\Session::class)
245 ->setMethods([
'isLoggedIn',
'getUserCreateWord'])
246 ->setConstructorArgs($sessionArgs)
248 $session->expects($this->any())->method(
'isLoggedIn')->will($this->returnValue(
false));
250 $session->setData([
'user_create_word' => [
'data' =>
'AbCdEf5',
'expires' =>
time() + self::EXPIRE_FRAME]]);
260 $helper = $this->getMockBuilder(
261 \
Magento\Captcha\Helper\Data::class
262 )->disableOriginalConstructor()->setMethods(
263 [
'getConfig',
'getFonts',
'_getWebsiteCode',
'getImgUrl']
271 $this->returnCallback(
'Magento\Captcha\Test\Unit\Model\DefaultTest::getConfigNodeStub')
274 $helper->expects($this->any())->method(
'getFonts')->will($this->returnValue($this->_fontPath));
276 $helper->expects($this->any())->method(
'_getWebsiteCode')->will($this->returnValue(
'base'));
283 $this->returnValue(
'http://localhost/pub/media/captcha/base/')
297 [
'countAttemptsByRemoteAddress',
'countAttemptsByUserLogin',
'logAttempt',
'__wakeup']
302 $resourceModel->expects($this->any())->method(
'countAttemptsByRemoteAddress')->will($this->returnValue(0));
304 $resourceModel->expects($this->any())->method(
'countAttemptsByUserLogin')->will($this->returnValue(3));
316 $args = func_get_args();
317 $hashName = $args[0];
319 if (array_key_exists($hashName, self::$_defaultConfig)) {
320 return self::$_defaultConfig[$hashName];
323 throw new \InvalidArgumentException(
'Unknow id = ' . $hashName);
333 $store = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
'isAdmin',
'getBaseUrl']);
334 $store->expects($this->any())->method(
'getBaseUrl')->will($this->returnValue(
'http://localhost/pub/media/'));
335 $store->expects($this->any())->method(
'isAdmin')->will($this->returnValue(
false));
346 $captcha = new \Magento\Captcha\Model\DefaultModel(
349 $this->_resLogFactory,
352 $this->assertEquals($expectedResult,
$captcha->isShownToLoggedInUser());
361 [
true,
'contact_us'],
362 [
false,
'user_create'],
363 [
false,
'user_forgotpassword']
testIsShownToLoggedInUser($expectedResult, $formId)
static getConfigNodeStub()
isShownToLoggedInUserDataProvider()