Skip to content

Commit

Permalink
magento#13899 Solve Zipcode pattern for Canada
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeobarranco authored and hitesh-wagento committed Jun 12, 2018
1 parent 4d1b832 commit bc26a3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/code/Magento/Directory/etc/zip_codes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<zip countryCode="CA">
<codes>
<code id="pattern_1" active="true" example="A1B 2C3">^[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}\s[0-9]{1}[a-zA-z]{1}[0-9]{1}$</code>
<code id="pattern_2" active="true" example="A1B2C3">^[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}[0-9]{1}$</code>
</codes>
</zip>
<zip countryCode="IC">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bc26a3a

Please sign in to comment.