CaptchaFactoryTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Captcha\Test\Unit\Model;
  7. class CaptchaFactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**@var \PHPUnit_Framework_MockObject_MockObject */
  10. protected $_objectManagerMock;
  11. /** @var \Magento\Captcha\Model\CaptchaFactory */
  12. protected $_model;
  13. protected function setUp()
  14. {
  15. $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  16. $this->_model = new \Magento\Captcha\Model\CaptchaFactory($this->_objectManagerMock);
  17. }
  18. public function testCreatePositive()
  19. {
  20. $captchaType = 'default';
  21. $defaultCaptchaMock = $this->createMock(\Magento\Captcha\Model\DefaultModel::class);
  22. $this->_objectManagerMock->expects(
  23. $this->once()
  24. )->method(
  25. 'create'
  26. )->with(
  27. $this->equalTo('Magento\Captcha\Model\\' . ucfirst($captchaType))
  28. )->will(
  29. $this->returnValue($defaultCaptchaMock)
  30. );
  31. $this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
  32. }
  33. public function testCreateNegative()
  34. {
  35. $captchaType = 'wrong_instance';
  36. $defaultCaptchaMock = $this->createMock(\stdClass::class);
  37. $this->_objectManagerMock->expects(
  38. $this->once()
  39. )->method(
  40. 'create'
  41. )->with(
  42. $this->equalTo('Magento\Captcha\Model\\' . ucfirst($captchaType))
  43. )->will(
  44. $this->returnValue($defaultCaptchaMock)
  45. );
  46. $this->expectException('InvalidArgumentException');
  47. $this->expectExceptionMessage('Magento\Captcha\Model\\' . ucfirst($captchaType) .
  48. ' does not implement \Magento\Captcha\Model\CaptchaInterface');
  49. $this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
  50. }
  51. }