Exemple #1
0
 public function testCreateNegative()
 {
     $captchaType = 'wrong_instance';
     $defaultCaptchaMock = $this->getMock('stdClass');
     $this->_objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Captcha\\Model\\' . ucfirst($captchaType)))->will($this->returnValue($defaultCaptchaMock));
     $this->setExpectedException('InvalidArgumentException', 'Magento\\Captcha\\Model\\' . ucfirst($captchaType) . ' does not implement \\Magento\\Captcha\\Model\\ModelInterface');
     $this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
 }
Exemple #2
0
 /**
  * Get Captcha
  *
  * @param string $formId
  * @return \Magento\Captcha\Model\ModelInterface
  */
 public function getCaptcha($formId)
 {
     if (!array_key_exists($formId, $this->_captcha)) {
         $captchaType = ucfirst($this->getConfig('type'));
         if (!$captchaType) {
             $captchaType = self::DEFAULT_CAPTCHA_TYPE;
         } elseif ($captchaType == 'Default') {
             $captchaType = $captchaType . 'Model';
         }
         $this->_captcha[$formId] = $this->_factory->create($captchaType, $formId);
     }
     return $this->_captcha[$formId];
 }