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

[ZF-6511] Zend_Validate_Identical:

- NOT_SAME message more informative

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15608 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 лет назад
Родитель
Сommit
6947db49df

+ 1 - 1
documentation/manual/en/module_specs/Zend_Validate-Messages.xml

@@ -447,7 +447,7 @@
                 <row>
                     <entry morerows="1" valign="middle">Identical</entry>
                     <entry>NOT_SAME</entry>
-                    <entry>Tokens do not match</entry>
+                    <entry>The token '%token%' does not match the given token '%value%'</entry>
                 </row>
                 <row>
                     <entry>MISSING_TOKEN</entry>

+ 13 - 7
library/Zend/Validate/Identical.php

@@ -30,24 +30,30 @@ require_once 'Zend/Validate/Abstract.php';
  */
 class Zend_Validate_Identical extends Zend_Validate_Abstract
 {
-    /**#@+
+    /**
      * Error codes
      * @const string
      */
     const NOT_SAME      = 'notSame';
     const MISSING_TOKEN = 'missingToken';
-    /**#@-*/
 
     /**
      * Error messages
      * @var array
      */
     protected $_messageTemplates = array(
-        self::NOT_SAME      => 'Tokens do not match',
+        self::NOT_SAME      => "The token '%token%' does not match the given token '%value%'",
         self::MISSING_TOKEN => 'No token was provided to match against',
     );
 
     /**
+     * @var array
+     */
+    protected $_messageVariables = array(
+        'token' => '_token'
+    );
+
+    /**
      * Original token against which to validate
      * @var string
      */
@@ -68,8 +74,8 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract
 
     /**
      * Set token against which to compare
-     * 
-     * @param  string $token 
+     *
+     * @param  string $token
      * @return Zend_Validate_Identical
      */
     public function setToken($token)
@@ -80,7 +86,7 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract
 
     /**
      * Retrieve token
-     * 
+     *
      * @return string
      */
     public function getToken()
@@ -91,7 +97,7 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract
     /**
      * Defined by Zend_Validate_Interface
      *
-     * Returns true if and only if a token has been set and the provided value 
+     * Returns true if and only if a token has been set and the provided value
      * matches that token.
      *
      * @param  string $value

+ 13 - 0
tests/Zend/Validate/IdenticalTest.php

@@ -100,6 +100,19 @@ class Zend_Validate_IdenticalTest extends PHPUnit_Framework_TestCase
         $this->validator->setToken('foo');
         $this->assertTrue($this->validator->isValid('foo'));
     }
+
+    /**
+     * @see ZF-6511
+     */
+    public function testNotSameMessageContainsTokenAndValue()
+    {
+        $this->testValidatingAgainstTokenWithNonMatchingValueReturnsFalse();
+        $messages = $this->validator->getMessages();
+        $this->assertTrue(array_key_exists('notSame', $messages));
+        $this->assertContains('foo', $messages['notSame']);
+        $this->assertContains('bar', $messages['notSame']);
+        $this->assertContains('does not match', $messages['notSame']);
+    }
 }
 
 // Call Zend_Validate_IdenticalTest::main() if this source file is executed directly.