diff --git a/app/code/Magento/Directory/etc/zip_codes.xml b/app/code/Magento/Directory/etc/zip_codes.xml index 18e13ca5bb48b..c4899636b4b30 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 ad2e6c6c4e235..d09879131a353 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,24 @@ public function testPostCodesThrowsExceptionIfCountryDoesNotExist() $this->validator->validate('12345', 'INVALID-CODE'); } + public function testInvalidCanadaZipCode() { + $resultOnlyDigits = $this->validator->validate('12345', 'CA'); + $resultMoreCharactersThanNeeded = $this->validator->validate('A1B2C3D', 'CA'); + $resultLessCharactersThanNeeded = $this->validator->validate('A1B2C', 'CA'); + $resultMoreThanOneSpace = $this->validator->validate('A1B 2C3', 'CA'); + $this->assertFalse($resultOnlyDigits); + $this->assertFalse($resultMoreCharactersThanNeeded); + $this->assertFalse($resultLessCharactersThanNeeded); + $this->assertFalse($resultMoreThanOneSpace); + } + + public function testValidCanadaZipCode() { + $resultPattern1 = $this->validator->validate('A1B2C3', 'CA'); + $resultPattern2 = $this->validator->validate('A1B 2C3', 'CA'); + $this->assertTrue($resultPattern1); + $this->assertTrue($resultPattern2); + } + /** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength)