diff --git a/app/code/Magento/Directory/etc/zip_codes.xml b/app/code/Magento/Directory/etc/zip_codes.xml index d70dee8abc15b..286278ac7ecb4 100644 --- a/app/code/Magento/Directory/etc/zip_codes.xml +++ b/app/code/Magento/Directory/etc/zip_codes.xml @@ -81,6 +81,7 @@ ^[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}\s[0-9]{1}[a-zA-z]{1}[0-9]{1}$ + ^[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}[0-9]{1}$ diff --git a/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php b/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php index 45a5473176e3c..d75f49995f441 100644 --- a/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php +++ b/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php @@ -42,6 +42,48 @@ public function testPostCodesThrowsExceptionIfCountryDoesNotExist() $this->validator->validate('12345', 'INVALID-CODE'); } + /** + * @dataProvider getCanadaInvalidPostCodes + */ + public function testInvalidCanadaZipCode($countryId, $invalidPostCode) + { + $this->assertFalse($this->validator->validate($invalidPostCode, $countryId)); + } + + /** + * @dataProvider getCanadaValidPostCodes + */ + public function testValidCanadaZipCode($countryId, $validPostCode) + { + $this->assertTrue($this->validator->validate($validPostCode, $countryId)); + } + + /** + * @return array + */ + public function getCanadaInvalidPostCodes() + { + return [ + ['countryId' => 'CA', 'postcode' => '12345'], + ['countryId' => 'CA', 'postcode' => 'A1B2C3D'], + ['countryId' => 'CA', 'postcode' => 'A1B2C'], + ['countryId' => 'CA', 'postcode' => 'A1B 2C3'], + ]; + } + + /** + * @return array + */ + public function getCanadaValidPostCodes() + { + return [ + ['countryId' => 'CA', 'postcode' => 'A1B2C3'], + ['countryId' => 'CA', 'postcode' => 'A1B 2C3'], + ['countryId' => 'CA', 'postcode' => 'Z9Y 8X7'], + ['countryId' => 'CA', 'postcode' => 'Z9Y8X7'], + ]; + } + /** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength)