CaptchaStringResolverTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Captcha\Test\Unit\Observer;
  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. class CaptchaStringResolverTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var ObjectManager
  16. */
  17. private $objectManagerHelper;
  18. /**
  19. * @var CaptchaStringResolver
  20. */
  21. private $captchaStringResolver;
  22. /**
  23. * @var HttpRequest|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $requestMock;
  26. protected function setUp()
  27. {
  28. $this->objectManagerHelper = new ObjectManager($this);
  29. $this->requestMock = $this->createMock(HttpRequest::class);
  30. $this->captchaStringResolver = $this->objectManagerHelper->getObject(CaptchaStringResolver::class);
  31. }
  32. public function testResolveWithFormIdSet()
  33. {
  34. $formId = 'contact_us';
  35. $captchaValue = 'some-value';
  36. $this->requestMock->expects($this->once())
  37. ->method('getPost')
  38. ->with(CaptchaDataHelper::INPUT_NAME_FIELD_VALUE)
  39. ->willReturn([$formId => $captchaValue]);
  40. self::assertEquals(
  41. $this->captchaStringResolver->resolve($this->requestMock, $formId),
  42. $captchaValue
  43. );
  44. }
  45. public function testResolveWithNoFormIdInRequest()
  46. {
  47. $formId = 'contact_us';
  48. $this->requestMock->expects($this->once())
  49. ->method('getPost')
  50. ->with(CaptchaDataHelper::INPUT_NAME_FIELD_VALUE)
  51. ->willReturn([]);
  52. self::assertEquals(
  53. $this->captchaStringResolver->resolve($this->requestMock, $formId),
  54. ''
  55. );
  56. }
  57. }