Skip to content

Commit 852665a

Browse files
author
Stanislav Idolov
authored
ENGCOM-1943: Added unit test for CaptchaStringResolver #15986
2 parents 02aaccb + 444f5c7 commit 852665a

File tree

1 file changed

+69
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)