Skip to content

Commit ce9fba4

Browse files
author
Stanislav Idolov
authored
ENGCOM-696: #13899 Solve Canada Zip Code pattern #13930
2 parents 9d27268 + 4343d86 commit ce9fba4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

app/code/Magento/Directory/etc/zip_codes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<zip countryCode="CA">
8282
<codes>
8383
<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>
84+
<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>
8485
</codes>
8586
</zip>
8687
<zip countryCode="IC">

dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,48 @@ public function testPostCodesThrowsExceptionIfCountryDoesNotExist()
4242
$this->validator->validate('12345', 'INVALID-CODE');
4343
}
4444

45+
/**
46+
* @dataProvider getCanadaInvalidPostCodes
47+
*/
48+
public function testInvalidCanadaZipCode($countryId, $invalidPostCode)
49+
{
50+
$this->assertFalse($this->validator->validate($invalidPostCode, $countryId));
51+
}
52+
53+
/**
54+
* @dataProvider getCanadaValidPostCodes
55+
*/
56+
public function testValidCanadaZipCode($countryId, $validPostCode)
57+
{
58+
$this->assertTrue($this->validator->validate($validPostCode, $countryId));
59+
}
60+
61+
/**
62+
* @return array
63+
*/
64+
public function getCanadaInvalidPostCodes()
65+
{
66+
return [
67+
['countryId' => 'CA', 'postcode' => '12345'],
68+
['countryId' => 'CA', 'postcode' => 'A1B2C3D'],
69+
['countryId' => 'CA', 'postcode' => 'A1B2C'],
70+
['countryId' => 'CA', 'postcode' => 'A1B 2C3'],
71+
];
72+
}
73+
74+
/**
75+
* @return array
76+
*/
77+
public function getCanadaValidPostCodes()
78+
{
79+
return [
80+
['countryId' => 'CA', 'postcode' => 'A1B2C3'],
81+
['countryId' => 'CA', 'postcode' => 'A1B 2C3'],
82+
['countryId' => 'CA', 'postcode' => 'Z9Y 8X7'],
83+
['countryId' => 'CA', 'postcode' => 'Z9Y8X7'],
84+
];
85+
}
86+
4587
/**
4688
* @return array
4789
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

0 commit comments

Comments
 (0)