浏览代码

ZF-11522: Allow changing label on Zend_Captcha_Dumb

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24747 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 年之前
父节点
当前提交
a85bc8eabb
共有 2 个文件被更改,包括 41 次插入1 次删除
  1. 24 1
      library/Zend/Captcha/Dumb.php
  2. 17 0
      tests/Zend/Captcha/DumbTest.php

+ 24 - 1
library/Zend/Captcha/Dumb.php

@@ -37,6 +37,29 @@ require_once 'Zend/Captcha/Word.php';
 class Zend_Captcha_Dumb extends Zend_Captcha_Word
 {
     /**
+     * CAPTCHA label
+     * @type string
+     */
+    protected $_label = 'Please type this word backwards';
+    
+    /**
+     * Set the label for the CAPTCHA
+     * @param string $label
+     */
+    public function setLabel($label)
+    {
+        $this->_label = $label;
+    }
+    
+    /**
+     * Retrieve the label for the CAPTCHA
+     * @return string
+     */
+    public function getLabel()
+    {
+        return $this->_label;
+    }
+    /**
      * Render the captcha
      *
      * @param  Zend_View_Interface $view
@@ -45,7 +68,7 @@ class Zend_Captcha_Dumb extends Zend_Captcha_Word
      */
     public function render(Zend_View_Interface $view = null, $element = null)
     {
-        return 'Please type this word backwards: <b>'
+        return $this->getLabel() . ': <b>'
              . strrev($this->getWord())
              . '</b>';
     }

+ 17 - 0
tests/Zend/Captcha/DumbTest.php

@@ -91,6 +91,23 @@ class Zend_Captcha_DumbTest extends PHPUnit_Framework_TestCase
         $this->assertContains(strrev($word), $html);
         $this->assertNotContains($word, $html);
     }
+
+    /**
+     * @group ZF-11522
+     */
+    public function testDefaultLabelIsUsedWhenNoAlternateLabelSet()
+    {
+        $this->assertEquals('Please type this word backwards', $this->captcha->getLabel());
+    }
+
+    /**
+     * @group ZF-11522
+     */
+    public function testChangeLabelViaSetterMethod()
+    {
+        $this->captcha->setLabel('Testing');
+        $this->assertEquals('Testing', $this->captcha->getLabel());
+    }
 }
 
 class Zend_Captcha_DumbTest_SessionContainer