Merge pull request #23269 from marcochiesi/patch-1

Added validation for Italian postcodes
This commit is contained in:
Mike Jolley 2019-04-15 14:10:01 +01:00 committed by GitHub
commit 6c6785c844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -64,6 +64,7 @@ class WC_Validation {
break;
case 'ES':
case 'FR':
case 'IT':
$valid = (bool) preg_match( '/^([0-9]{5})$/i', $postcode );
break;
case 'GB':

View File

@ -1,8 +1,12 @@
<?php
/**
* Unit tests for validation.
*
* @package WooCommerce\Tests\Util
*/
/**
* Class Validation.
* @package WooCommerce\Tests\Util
* Class WC_Tests_Validation.
* @since 2.3
*/
class WC_Tests_Validation extends WC_Unit_Test_Case {
@ -35,6 +39,9 @@ class WC_Tests_Validation extends WC_Unit_Test_Case {
/**
* Test is_phone().
*
* @param mixed $assert Expected value.
* @param mixed $values Actual value.
*
* @dataProvider data_provider_test_is_phone
* @since 2.3
*/
@ -48,12 +55,11 @@ class WC_Tests_Validation extends WC_Unit_Test_Case {
* @since 2.4
*/
public function data_provider_test_is_postcode() {
$generic = array(
$it = array(
array( true, WC_Validation::is_postcode( '99999', 'IT' ) ),
array( true, WC_Validation::is_postcode( '99999', 'IT' ) ),
array( true, WC_Validation::is_postcode( '9999', 'IT' ) ),
array( true, WC_Validation::is_postcode( 'ABC 999', 'IT' ) ),
array( true, WC_Validation::is_postcode( 'ABC-999', 'IT' ) ),
array( false, WC_Validation::is_postcode( '9999', 'IT' ) ),
array( false, WC_Validation::is_postcode( 'ABC 999', 'IT' ) ),
array( false, WC_Validation::is_postcode( 'ABC-999', 'IT' ) ),
array( false, WC_Validation::is_postcode( 'ABC_123', 'IT' ) ),
);
@ -92,12 +98,15 @@ class WC_Tests_Validation extends WC_Unit_Test_Case {
array( false, WC_Validation::is_postcode( '0A0A0A', 'CA' ) ),
);
return array_merge( $generic, $gb, $us, $ch, $br, $ca );
return array_merge( $it, $gb, $us, $ch, $br, $ca );
}
/**
* Test is_postcode().
*
* @param mixed $assert Expected value.
* @param mixed $values Actual value.
*
* @dataProvider data_provider_test_is_postcode
* @since 2.4
*/
@ -129,6 +138,9 @@ class WC_Tests_Validation extends WC_Unit_Test_Case {
/**
* Test is_gb_postcode().
*
* @param mixed $assert Expected value.
* @param mixed $values Actual value.
*
* @dataProvider data_provider_test_is_gb_postcode
* @since 2.4
*/
@ -155,6 +167,9 @@ class WC_Tests_Validation extends WC_Unit_Test_Case {
/**
* Test format_postcode().
*
* @param mixed $assert Expected value.
* @param mixed $values Actual value.
*
* @dataProvider data_provider_test_format_postcode
* @since 2.4
*/