Просмотр исходного кода

ZF-11483
Zend_Captcha
Zend_Captcha_Image does not repect doctype when producing image tag


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24145 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 лет назад
Родитель
Сommit
027b1899f1
2 измененных файлов с 20 добавлено и 1 удалено
  1. 5 1
      library/Zend/Captcha/Image.php
  2. 15 0
      tests/Zend/Captcha/ImageTest.php

+ 5 - 1
library/Zend/Captcha/Image.php

@@ -599,7 +599,11 @@ class Zend_Captcha_Image extends Zend_Captcha_Word
      */
     public function render(Zend_View_Interface $view = null, $element = null)
     {
+        $endTag = ' />';
+        if (($view instanceof Zend_View_Abstract) && !$view->doctype()->isXhtml()) {
+            $endTag = '>';
+        }
         return '<img width="' . $this->getWidth() . '" height="' . $this->getHeight() . '" alt="' . $this->getImgAlt()
-             . '" src="' . $this->getImgUrl() . $this->getId() . $this->getSuffix() . '" />';
+             . '" src="' . $this->getImgUrl() . $this->getId() . $this->getSuffix() . '"' . $endTag;
     }
 }

+ 15 - 0
tests/Zend/Captcha/ImageTest.php

@@ -346,6 +346,21 @@ class Zend_Captcha_ImageTest extends PHPUnit_Framework_TestCase
         $input = array("id" => $this->captcha->getId(), "input" => $this->captcha->getWord());
         $this->assertTrue($this->element->isValid($input));
     }
+    
+    /**
+     * @group ZF-11483
+     */
+    public function testImageTagRenderedProperlyBasedUponDoctype()
+    {
+        $this->testCaptchaIsRendered();        
+        $view = new Zend_View();
+        
+        $view->doctype('XHTML1_STRICT');        
+        $this->assertRegExp('#/>$#', $this->captcha->render($view));
+        
+        $view->doctype('HTML4_STRICT');        
+        $this->assertRegExp('#[^/]>$#', $this->captcha->render($view));
+    }
 }
 
 class Zend_Captcha_ImageTest_SessionContainer