Skip to content

Commit e508120

Browse files
committed
Added unit test for CaptchaStringResolver
1 parent 33393e2 commit e508120

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Captcha\Test\Unit\Observer;
7+
8+
use Magento\Captcha\Helper\Data as CaptchaDataHelper;
9+
use Magento\Captcha\Observer\CaptchaStringResolver;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
13+
class CaptchaStringResolverTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var ObjectManager
17+
*/
18+
private $objectManagerHelper;
19+
20+
/**
21+
* @var CaptchaStringResolver
22+
*/
23+
private $captchaStringResolver;
24+
25+
/**
26+
* @var HttpRequest|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $requestMock;
29+
30+
protected function setUp()
31+
{
32+
$this->objectManagerHelper = new ObjectManager($this);
33+
$this->requestMock = $this->createMock(HttpRequest::class);
34+
$this->captchaStringResolver = $this->objectManagerHelper->getObject(CaptchaStringResolver::class);
35+
}
36+
37+
public function testResolveWithFormIdSet()
38+
{
39+
$formId = 'contact_us';
40+
$captchaValue = 'some-value';
41+
42+
$this->requestMock->expects($this->once())
43+
->method('getPost')
44+
->with(CaptchaDataHelper::INPUT_NAME_FIELD_VALUE)
45+
->willReturn([$formId => $captchaValue]);
46+
47+
self::assertEquals(
48+
$this->captchaStringResolver->resolve($this->requestMock, $formId),
49+
$captchaValue
50+
);
51+
}
52+
53+
public function testResolveWithNoFormIdInRequest()
54+
{
55+
$formId = 'contact_us';
56+
57+
$this->requestMock->expects($this->once())
58+
->method('getPost')
59+
->with(CaptchaDataHelper::INPUT_NAME_FIELD_VALUE)
60+
->willReturn([]);
61+
62+
self::assertEquals(
63+
$this->captchaStringResolver->resolve($this->requestMock, $formId),
64+
''
65+
);
66+
}
67+
}

0 commit comments

Comments
 (0)