cvs: pear /Validate package_BE.xml /Validate/Validate BE.php /Validate/tests validate_BE.phpt

From: Date: Fri, 30 Sep 2005 17:02:07 +0000
Subject: cvs: pear /Validate package_BE.xml /Validate/Validate BE.php /Validate/tests validate_BE.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35177@lists.php.net to get a copy of this message
moosh Fri Sep 30 13:02:07 2005 EDT Modified files: /pear/Validate/Validate BE.php /pear/Validate package_BE.xml /pear/Validate/tests validate_BE.phpt Log: - add last method for 1.1 - finish all tests - update package.xml before try packaging

http://cvs.php.net/diff.php/pear/Validate/Validate/BE.php?r1=1.8&r2=1.9&ty=u Index: pear/Validate/Validate/BE.php diff -u pear/Validate/Validate/BE.php:1.8 pear/Validate/Validate/BE.php:1.9 --- pear/Validate/Validate/BE.php:1.8 Fri Sep 30 05:06:40 2005 +++ pear/Validate/Validate/BE.php Fri Sep 30 13:02:04 2005 @@ -16,7 +16,7 @@ * @author Christophe Gesché <moosh@php.net> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: BE.php,v 1.8 2005/09/30 09:06:40 moosh Exp $ + * @version CVS: $Id: BE.php,v 1.9 2005/09/30 17:02:04 moosh Exp $ * @link http://pear.php.net/package/Validate_BE */ require_once 'Validate.php'; @@ -68,6 +68,57 @@ * @param string ssn to validate * @return bool true on success */ + function nationalId($nationalId) + { + $nationalId = strtr($nationalId,'-/\ :', '.....'; + $nationalId = str_replace('.','',$nationalId); + // RULE 1 : 11 digit. + if (!(bool) ereg('^[0-9]{11}$', $nationalId)) { + return false; + } + + + // RULE 2 : ssn begin with a reversed date + $year = substr($nationalId,0,2); + $month = substr($nationalId,2,2); + $day = substr($nationalId,4,2); + $number = substr($nationalId,0,9); + $check = substr($nationalId,9,2); + + /** + * Check that the date is valid + */ + if (!Validate::date("$year-$month-$day", array('format' => '%y-%m-%d'))) { + return false; + } + + // RULE 3 check is 97 - modulo 97 of all or RULES 3BIS + if ((97 - Validate::_modf($number, VALIDATE_BE_SSN_MODULUS)) == $check) { + return true; + } + + // RULE 3 BIS + // if RULE 3 check faild, prepend 2 to the number and retry + if ((97 - Validate::_modf(2000000000 + $number, VALIDATE_BE_SSN_MODULUS)) == $check) { + return true; + } + + return false; + } + + /** + * Validate a Belgian social security number + * + * The belgian social security number is on the SIS card of all belgian. + * + * A check digit is the last one, computed the standard + * _get_control_number function. + * + * @static + * @access public + * @param string ssn to validate + * @return bool true on success + */ function ssn($ssn) { // RULE 1 : 11 digit. http://cvs.php.net/diff.php/pear/Validate/package_BE.xml?r1=1.7&r2=1.8&ty=u Index: pear/Validate/package_BE.xml diff -u pear/Validate/package_BE.xml:1.7 pear/Validate/package_BE.xml:1.8 --- pear/Validate/package_BE.xml:1.7 Thu Sep 29 17:16:55 2005 +++ pear/Validate/package_BE.xml Fri Sep 30 13:02:06 2005 @@ -31,12 +31,13 @@ <release> <version>0.1.1</version> <state>alpha</state> - <date>2005-09-28</date> + <date>2005-09-30</date> <notes> * Add new method to validate structured Bank Transfert Messages + * Add new method to validate nationalId * Fixed CS * Fixed check phone was bug for mobil begining with 04 - * split test files + * split test files on per method * toggg and moosh now co-leads </notes> <filelist> @@ -47,10 +48,11 @@ </file> </dir> <dir name="tests" role="test"> - <file>validate_BE.phpt</file> + <file>validate_BE_functions.inc.php</file> <file>validate_BE_bank_codes.phpt</file> <file>validate_BE_bank_transfer_message.phpt</file> - <file>validate_BE_functions.inc.php</file> + <file>validate_BE_national_id.phpt</file> + <file>validate_BE_phone_numbers.phpt</file> <file>validate_BE_post_code.phpt</file> <file>validate_BE_post_code_strong.phpt</file> <file>validate_BE_ssn.phpt</file> http://cvs.php.net/diff.php/pear/Validate/tests/validate_BE.phpt?r1=1.2&r2=1.3&ty=u Index: pear/Validate/tests/validate_BE.phpt diff -u pear/Validate/tests/validate_BE.phpt:1.2 pear/Validate/tests/validate_BE.phpt:1.3 --- pear/Validate/tests/validate_BE.phpt:1.2 Thu Sep 29 17:16:55 2005 +++ pear/Validate/tests/validate_BE.phpt Fri Sep 30 13:02:06 2005 @@ -5,48 +5,7 @@ include (dirname(__FILE__).'/validate_BE_functions.inc.php'); require_once 'Validate/BE.php'; -echo "Test Validate_BE\n"; -echo "****************\n"; - -$phonesnumbers = array( '065 12 34 56' => 'OK'// national little zone (phone number with 6 number) - , '02 123 45 67' => 'OK'// national big zone (phone number with 6 number) - , '0485 12 34 56' => 'OK'// GSM - , '00 32 65 12 34 56' => 'OK'// national little zone (phone number with 6 number) - , '00 32 2 123 45 67' => 'OK'// national big zone (phone number with 6 number) - , '00 32 485 12 34 56' => 'OK'// GSM - , '+32 65 12 34 56' => 'OK' - , '+32 2 123 45 67' => 'OK' - , '+32 485 12 34 56' => 'OK' - , '++ 32 65 12 34 56' => 'OK' - , '++ 32 2 123 45 67' => 'OK' - , '++ 32 485 12 34 56' => 'OK' - , '02 1a3 45 67' => 'KO' - , '0485 a2 34 56' => 'KO' - , '00 32 a5 12 34 56' => 'KO' - , '00 32 a 123 45 67' => 'KO' - , '00 32 4a5 12 34 56' => 'KO' - , '017 12 34 56' => 'KO'// national little zone (phone number with 6 number) but this prefix don't exist in belgium - , '+ 32 6a 12 34 56' => 'KO' - , '+ 32 2 1a3 45 67' => 'KO' - , '+ 32 485 1a 34 56' => 'KO' - , '++ 32 65 1a 34 56' => 'KO' - , '++ 32 2 1a3 45 67' => 'KO' - , '++ 32 485 1a 34 56' => 'KO' - , '02 12 45 67' => 'KO' - , '0485 112 34 56' => 'KO' - , '00 32 5 12 34 56' => 'KO' - , '00 32 12 123 45 67' => 'KO' - , '00 32 45 12 34 56' => 'OK' - , '+ 32 651 12 34 56' => 'KO' - , '+ 32 2 13 45 67' => 'KO' - , '+ 32 4851 12 34 56' => 'KO' - , '++ 32 65 112 34 56' => 'KO' - , '++ 32 2 1213 45 67' => 'KO' - , '++ 32 485 112 34 56' => 'KO' - - ); - -$nationalId = array( '73011136173' => 'OK'// OK it's mine +$nationalIdList = array( '73011136173' => 'OK'// OK it's mine , '73.01.11.361-73' => 'OK'// OK it's mine , '730111-361-73' => 'OK'// OK it's mine , '730111-361-73' => 'OK'// OK it's mine @@ -55,54 +14,32 @@ ); -$errorFound = false; - - - $errorFound = $errorFound || test_func('phoneNumber', $phonesnumbers ); +$functionToTest = 'nationalId'; +$title = 'Test Validate_BE::' . $functionToTest . '()'; +echo $title . "\n"; +echo str_pad('',strlen($title),'*') . "\n"; +echo (test_func($functionToTest, $nationalIdList )) ? '... FAILED' : '... SUCCESS'; - echo ($errorFound) ? '... FAILED' : '... SUCCESS'; + echo (test_func('nationalId', $nationalIdList )) ? '... FAILED' : '... SUCCESS'; ?> --EXPECT-- -Test Validate_BE -**************** +Test Validate_BE::nationalId() +****************************** --------- -Test phoneNumber +Test nationalId _ Value State Return V = validation result is right X = validation result is wrong - V 065 12 34 56 : OK OK - V 02 123 45 67 : OK OK - V 0485 12 34 56 : OK OK - V 00 32 65 12 34 56 : OK OK - V 00 32 2 123 45 67 : OK OK - V 00 32 485 12 34 56 : OK OK - V +32 65 12 34 56 : OK OK - V +32 2 123 45 67 : OK OK - V +32 485 12 34 56 : OK OK - V ++ 32 65 12 34 56 : OK OK - V ++ 32 2 123 45 67 : OK OK - V ++ 32 485 12 34 56 : OK OK - V 02 1a3 45 67 : KO KO - V 0485 a2 34 56 : KO KO - V 00 32 a5 12 34 56 : KO KO - V 00 32 a 123 45 67 : KO KO - V 00 32 4a5 12 34 56 : KO KO - V 017 12 34 56 : KO KO - V + 32 6a 12 34 56 : KO KO - V + 32 2 1a3 45 67 : KO KO - V + 32 485 1a 34 56 : KO KO - V ++ 32 65 1a 34 56 : KO KO - V ++ 32 2 1a3 45 67 : KO KO - V ++ 32 485 1a 34 56 : KO KO - V 02 12 45 67 : KO KO - V 0485 112 34 56 : KO KO - V 00 32 5 12 34 56 : KO KO - V 00 32 12 123 45 67 : KO KO - V 00 32 45 12 34 56 : OK OK - V + 32 651 12 34 56 : KO KO - V + 32 2 13 45 67 : KO KO - V + 32 4851 12 34 56 : KO KO - V ++ 32 65 112 34 56 : KO KO - V ++ 32 2 1213 45 67 : KO KO - V ++ 32 485 112 34 56 : KO KO + V 72011136173 : KO KO + V 73011136173 : OK OK + V 03092213638 : OK OK + V 03132213638 : KO KO + V 72011a36173 : KO KO + V 73011a36173 : KO KO + V 03092a13638 : KO KO + V 03132a13638 : KO KO + V 2011136173 : KO KO + V 3011136173 : KO KO + V 3092213638 : KO KO + V 3132213638 : KO KO ... SUCCESS \ No newline at end of file
« previous php.pear.cvs (#35177) next »