Index: tests/Zend/Validate/PostCodeTest.php =================================================================== --- tests/Zend/Validate/PostCodeTest.php (revision 22533) +++ tests/Zend/Validate/PostCodeTest.php (working copy) @@ -131,7 +131,7 @@ $this->_validator->setLocale('gez_ER'); $this->fail(); } catch (Zend_Validate_Exception $e) { - $this->assertContains('Unable to detect a format', $e->getMessage()); + $this->assertContains('Unable to detect a postcode format', $e->getMessage()); } } @@ -164,14 +164,14 @@ $this->_validator->setFormat(null); $this->fail(); } catch (Zend_Validate_Exception $e) { - $this->assertContains('a not empty string', $e->getMessage()); + $this->assertContains('A postcode-format string has to be given', $e->getMessage()); } try { $this->_validator->setFormat(''); $this->fail(); } catch (Zend_Validate_Exception $e) { - $this->assertContains('a not empty string', $e->getMessage()); + $this->assertContains('A postcode-format string has to be given', $e->getMessage()); } } @@ -182,7 +182,52 @@ { $this->assertFalse($this->_validator->isValid('hello')); $message = $this->_validator->getMessages(); - $this->assertContains('not appear to be an postal code', $message['postcodeNoMatch']); + $this->assertContains('not appear to be a postal code', $message['postcodeNoMatch']); + } + + /** + * Tests for specification of Great Britain postal codes from + * http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/address/postcode.aspx + * + * @return null + * + * @dataProvider gbPostalCodeProvider + * + * @group ZF-10106 + */ + public function testGbPostalCodesValidateCorrectly($postalCode, $valid) + { + $this->_validator->setLocale('en_GB'); + if ($valid) { + $this->assertTrue($this->_validator->isValid($postalCode)); + } else { + $this->assertFalse($this->_validator->isValid($postalCode)); + } + } + + /** + * Returns a variety of valid and invalid Great Britain Postal codes + * to test the validator + * + * @return array + */ + public static function gbPostalCodeProvider() + { + return array( + array('IP14 4EG', true), // specific postal code in defect report + array('M1 1AA', true), // AN NAA format + array('M60 1NW', true), // ANN NAA + array('CR2 6XH', true), // AAN NAA + array('DN55 1PT', true), // AANN NAA + array('W1A 1HQ', true), // ANA NAA + array('EC1A 1BB', true), // AANA NAA + array('QC1A 1BB', false), // Q is not used in the first position + array('V1A 1HQ', false), // V is not used in the first position + array('X1 1AA', false), // X is not used in the first position + array('CI2 6XH', false), // I is not used in the second position + array('IJ14 4EG', false), // J is not used in the second position + array('DZ55 1PT', false), // Z is not used in the second position + ); } } Index: library/Zend/Validate/PostCode.php =================================================================== --- library/Zend/Validate/PostCode.php (revision 22533) +++ library/Zend/Validate/PostCode.php (working copy) @@ -133,7 +133,7 @@ } $format = Zend_Locale::getTranslation( - $locale->getRegion(), + $region, 'postaltoterritory', $this->_locale ); Index: library/Zend/Locale/Data/postalCodeData.xml =================================================================== --- library/Zend/Locale/Data/postalCodeData.xml (revision 22533) +++ library/Zend/Locale/Data/postalCodeData.xml (working copy) @@ -3,7 +3,7 @@ - GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4} + GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|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