Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
CaptchaStringResolverTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Captcha\Helper\Data as CaptchaDataHelper;
12 use Magento\Framework\App\Request\Http as HttpRequest;
14 
15 class CaptchaStringResolverTest extends \PHPUnit\Framework\TestCase
16 {
20  private $objectManagerHelper;
21 
25  private $captchaStringResolver;
26 
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 
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 }