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

[ZF-10116] Zend_Validate_Barcode:

- fixed multi-length error message

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22540 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 15 лет назад
Родитель
Сommit
1d3755e6c5
2 измененных файлов с 23 добавлено и 0 удалено
  1. 11 0
      library/Zend/Validate/Barcode.php
  2. 12 0
      tests/Zend/Validate/BarcodeTest.php

+ 11 - 0
library/Zend/Validate/Barcode.php

@@ -194,6 +194,17 @@ class Zend_Validate_Barcode extends Zend_Validate_Abstract
         $this->_length = $adapter->getLength();
         $result        = $adapter->checkLength($value);
         if (!$result) {
+            if (is_array($this->_length)) {
+                $temp = $this->_length;
+                $this->_length = "";
+                foreach($temp as $length) {
+                    $this->_length .= "/";
+                    $this->_length .= $length;
+                }
+
+                $this->_length = substr($this->_length, 1);
+            }
+
             $this->_error(self::INVALID_LENGTH);
             return false;
         }

+ 12 - 0
tests/Zend/Validate/BarcodeTest.php

@@ -432,4 +432,16 @@ class Zend_Validate_BarcodeTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($barcode->isValid('123456'));
         $this->assertTrue($barcode->isValid('0234567'));
     }
+
+    /**
+     * @group ZF-10116
+     */
+    public function testArrayLengthMessage()
+    {
+        $barcode = new Zend_Validate_Barcode('ean8');
+        $this->assertFalse($barcode->isValid('123'));
+        $message = $barcode->getMessages();
+        $this->assertTrue(array_key_exists('barcodeInvalidLength', $message));
+        $this->assertContains("length of 7/8 characters", $message['barcodeInvalidLength']);
+    }
 }