Skip to content

Commit

Permalink
ENGCOM-696: #13899 Solve Canada Zip Code pattern #13930
Browse files Browse the repository at this point in the history
 - Merge Pull Request #13930 from magentomxcommunity/magento2:issue#13899
 - Merged commits:
   1. c6d128f
   2. 7c5ddee
   3. fa8b884
   4. 8fae90b
  • Loading branch information
magento-engcom-team committed Mar 3, 2018
2 parents 9a43f02 + 8fae90b commit 4343d86
Show file tree
Hide file tree
Showing 2 changed files with 43 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,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)
Expand Down

0 comments on commit 4343d86

Please sign in to comment.