Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/3144' into develop

Forward port #3144
  • Loading branch information...
commit 0ee49305a626d6113df53871b4984fb2482d9b2b 2 parents 9fcdb41 + 2af7bfb
@weierophinney weierophinney authored
View
19 library/Zend/Form/View/Helper/Captcha/AbstractWord.php
@@ -43,7 +43,7 @@
/**
* Set value for captchaPosition
*
- * @param mixed $captchaPosition
+ * @param mixed $captchaPosition
* @throws Exception\InvalidArgumentException
* @return self
*/
@@ -60,6 +60,7 @@ public function setCaptchaPosition($captchaPosition)
));
}
$this->captchaPosition = $captchaPosition;
+
return $this;
}
@@ -76,12 +77,13 @@ public function getCaptchaPosition()
/**
* Set separator string for captcha and inputs
*
- * @param string $separator
+ * @param string $separator
* @return AbstractWord
*/
public function setSeparator($separator)
{
$this->separator = (string) $separator;
+
return $this;
}
@@ -104,7 +106,7 @@ public function getSeparator()
*
* More specific renderers will consume this and render it.
*
- * @param ElementInterface $element
+ * @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
@@ -155,13 +157,18 @@ public function __invoke(ElementInterface $element = null)
* Render the hidden input with the captcha identifier
*
* @param CaptchaAdapter $captcha
- * @param array $attributes
+ * @param array $attributes
* @return string
*/
protected function renderCaptchaHidden(CaptchaAdapter $captcha, array $attributes)
{
$attributes['type'] = 'hidden';
$attributes['name'] .= '[id]';
+
+ if (isset($attributes['id'])) {
+ $attributes['id'] .= '-hidden';
+ }
+
if (method_exists($captcha, 'getId')) {
$attributes['value'] = $captcha->getId();
} elseif (array_key_exists('value', $attributes)) {
@@ -175,6 +182,7 @@ protected function renderCaptchaHidden(CaptchaAdapter $captcha, array $attribute
$this->createAttributesString($attributes),
$closingBracket
);
+
return $hidden;
}
@@ -182,7 +190,7 @@ protected function renderCaptchaHidden(CaptchaAdapter $captcha, array $attribute
* Render the input for capturing the captcha value from the client
*
* @param CaptchaAdapter $captcha
- * @param array $attributes
+ * @param array $attributes
* @return string
*/
protected function renderCaptchaInput(CaptchaAdapter $captcha, array $attributes)
@@ -198,6 +206,7 @@ protected function renderCaptchaInput(CaptchaAdapter $captcha, array $attributes
$this->createAttributesString($attributes),
$closingBracket
);
+
return $input;
}
}
View
7 library/Zend/Form/View/Helper/Captcha/Image.php
@@ -24,7 +24,7 @@ class Image extends AbstractWord
/**
* Render the captcha
*
- * @param ElementInterface $element
+ * @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
@@ -47,6 +47,11 @@ public function render(ElementInterface $element)
'alt' => $captcha->getImgAlt(),
'src' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(),
);
+
+ if ($element->hasAttribute('id')) {
+ $imgAttributes['id'] = $element->getAttribute('id') . '-image';
+ }
+
$closingBracket = $this->getInlineClosingBracket();
$img = sprintf(
'<img %s%s',
View
15 tests/ZendTest/Form/View/Helper/FormCaptchaTest.php
@@ -62,12 +62,14 @@ protected function getTmpDir()
if (null === $this->tmpDir) {
$this->tmpDir = sys_get_temp_dir();
}
+
return $this->tmpDir;
}
public function getElement()
{
$element = new CaptchaElement('foo');
+
return $element;
}
@@ -85,8 +87,11 @@ public function testPassingElementWithDumbCaptchaRendersCorrectly()
));
$element = $this->getElement();
$element->setCaptcha($captcha);
+ $element->setAttribute('id', 'foo');
$markup = $this->helper->render($element);
$this->assertContains($captcha->getLabel(), $markup);
+ $this->assertRegExp('#<[^>]*(id="' . $element->getAttribute('id') . '")[^>]*(type="text")[^>]*>#', $markup);
+ $this->assertRegExp('#<[^>]*(id="' . $element->getAttribute('id') . '-hidden")[^>]*(type="hidden")[^>]*>#', $markup);
}
public function testPassingElementWithFigletCaptchaRendersCorrectly()
@@ -96,14 +101,18 @@ public function testPassingElementWithFigletCaptchaRendersCorrectly()
));
$element = $this->getElement();
$element->setCaptcha($captcha);
+ $element->setAttribute('id', 'foo');
$markup = $this->helper->render($element);
$this->assertContains('<pre>' . $captcha->getFiglet()->render($captcha->getWord()) . '</pre>', $markup);
+ $this->assertRegExp('#<[^>]*(id="' . $element->getAttribute('id') . '")[^>]*(type="text")[^>]*>#', $markup);
+ $this->assertRegExp('#<[^>]*(id="' . $element->getAttribute('id') . '-hidden")[^>]*(type="hidden")[^>]*>#', $markup);
}
public function testPassingElementWithImageCaptchaRendersCorrectly()
{
if (!extension_loaded('gd')) {
$this->markTestSkipped('The GD extension is not available.');
+
return;
}
if (!function_exists("imagepng")) {
@@ -125,10 +134,16 @@ public function testPassingElementWithImageCaptchaRendersCorrectly()
));
$element = $this->getElement();
$element->setCaptcha($captcha);
+ $element->setAttribute('id', 'foo');
+
$markup = $this->helper->render($element);
+
$this->assertContains('<img ', $markup);
$this->assertContains($captcha->getImgUrl(), $markup);
$this->assertContains($captcha->getId(), $markup);
+ $this->assertRegExp('#<img[^>]*(id="' . $element->getAttribute('id') . '-image")[^>]*>#', $markup);
+ $this->assertRegExp('#<input[^>]*(id="' . $element->getAttribute('id') . '")[^>]*(type="text")[^>]*>#', $markup);
+ $this->assertRegExp('#<input[^>]*(id="' . $element->getAttribute('id') . '-hidden")[^>]*(type="hidden")[^>]*>#', $markup);
}
public function testPassingElementWithReCaptchaRendersCorrectly()
Please sign in to comment.
Something went wrong with that request. Please try again.