From c87b10465a4b051a5c6cf54668ed143417c6a0b9 Mon Sep 17 00:00:00 2001 From: Tadeo Barranco Date: Fri, 2 Mar 2018 15:55:05 -0600 Subject: [PATCH 1/4] #13899 Solve Zipcode pattern for Canada --- app/code/Magento/Directory/etc/zip_codes.xml | 1 + .../Model/Country/Postcode/ValidatorTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/code/Magento/Directory/etc/zip_codes.xml b/app/code/Magento/Directory/etc/zip_codes.xml index d70dee8abc15b..286278ac7ecb4 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 45a5473176e3c..8aa1f7313c7eb 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) From ac377279fb55dc1f8301239bb381ed9b8dd68573 Mon Sep 17 00:00:00 2001 From: Tadeo Barranco Date: Fri, 2 Mar 2018 16:08:25 -0600 Subject: [PATCH 2/4] #13899 Improve unit test --- .../Model/Country/Postcode/ValidatorTest.php | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) 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 8aa1f7313c7eb..f0c7d4e1ff483 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,17 +42,16 @@ 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); + /** + * @dataProvider getCanadaInvalidPostCodes + */ + public function testInvalidCanadaZipCode($countryId, $invalidPostCode) { + $this->assertFalse($this->validator->validate($invalidPostCode, $countryId)); } + /** + * + */ public function testValidCanadaZipCode() { $resultPattern1 = $this->validator->validate('A1B2C3', 'CA'); $resultPattern2 = $this->validator->validate('A1B 2C3', 'CA'); @@ -60,6 +59,18 @@ public function testValidCanadaZipCode() { $this->assertTrue($resultPattern2); } + /** + * @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 * @SuppressWarnings(PHPMD.ExcessiveMethodLength) From bda63c768690b1a6d90a63e9b63dcaebf5247581 Mon Sep 17 00:00:00 2001 From: Tadeo Barranco Date: Fri, 2 Mar 2018 16:09:26 -0600 Subject: [PATCH 3/4] #13899 Improve unit test --- .../Model/Country/Postcode/ValidatorTest.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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 f0c7d4e1ff483..82318a3ec5068 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 @@ -50,13 +50,10 @@ public function testInvalidCanadaZipCode($countryId, $invalidPostCode) { } /** - * + * @dataProvider getCanadaValidPostCodes */ - public function testValidCanadaZipCode() { - $resultPattern1 = $this->validator->validate('A1B2C3', 'CA'); - $resultPattern2 = $this->validator->validate('A1B 2C3', 'CA'); - $this->assertTrue($resultPattern1); - $this->assertTrue($resultPattern2); + public function testValidCanadaZipCode($countryId, $validPostCode) { + $this->assertTrue($this->validator->validate($validPostCode, $countryId)); } /** @@ -71,6 +68,18 @@ public function getCanadaInvalidPostCodes() { ]; } + /** + * @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) From cb04f93530361abc63cab78253b426044f79d8a7 Mon Sep 17 00:00:00 2001 From: Tadeo Barranco Date: Fri, 2 Mar 2018 16:38:57 -0600 Subject: [PATCH 4/4] Fixing failures in the test file --- .../Model/Country/Postcode/ValidatorTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 82318a3ec5068..d75f49995f441 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 @@ -45,21 +45,24 @@ public function testPostCodesThrowsExceptionIfCountryDoesNotExist() /** * @dataProvider getCanadaInvalidPostCodes */ - public function testInvalidCanadaZipCode($countryId, $invalidPostCode) { + public function testInvalidCanadaZipCode($countryId, $invalidPostCode) + { $this->assertFalse($this->validator->validate($invalidPostCode, $countryId)); } /** * @dataProvider getCanadaValidPostCodes */ - public function testValidCanadaZipCode($countryId, $validPostCode) { + public function testValidCanadaZipCode($countryId, $validPostCode) + { $this->assertTrue($this->validator->validate($validPostCode, $countryId)); } /** * @return array */ - public function getCanadaInvalidPostCodes() { + public function getCanadaInvalidPostCodes() + { return [ ['countryId' => 'CA', 'postcode' => '12345'], ['countryId' => 'CA', 'postcode' => 'A1B2C3D'], @@ -71,7 +74,8 @@ public function getCanadaInvalidPostCodes() { /** * @return array */ - public function getCanadaValidPostCodes() { + public function getCanadaValidPostCodes() + { return [ ['countryId' => 'CA', 'postcode' => 'A1B2C3'], ['countryId' => 'CA', 'postcode' => 'A1B 2C3'],