Skip to content

Commit

Permalink
ENGCOM-993: [Forwardport] #13899 Solve Canada Zip Code pattern #14215
Browse files Browse the repository at this point in the history
 - Merge Pull Request #14215 from AlexWorking/magento2:2.3-develop-PR-port-13930
 - Merged commits:
   1. c87b104
   2. ac37727
   3. bda63c7
   4. cb04f93
  • Loading branch information
magento-engcom-team committed Mar 21, 2018
2 parents 447a24d + cb04f93 commit 087eabc
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 087eabc

Please sign in to comment.