From ba91015ae1a7bc152d1cb599cfb67e30746fdc56 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 10 Dec 2011 10:57:10 +1030 Subject: [PATCH] Remove Validate_ES to own repo --- Validate/ES.php | 291 ------------------------------ package_ES.xml | 124 ------------- tests/validate_ES_ccc.phpt | 45 ----- tests/validate_ES_cif.phpt | 105 ----------- tests/validate_ES_dni.phpt | 53 ------ tests/validate_ES_postalCode.phpt | 45 ----- tests/validate_ES_ssn.phpt | 59 ------ 7 files changed, 722 deletions(-) delete mode 100644 Validate/ES.php delete mode 100644 package_ES.xml delete mode 100644 tests/validate_ES_ccc.phpt delete mode 100644 tests/validate_ES_cif.phpt delete mode 100644 tests/validate_ES_dni.phpt delete mode 100644 tests/validate_ES_postalCode.phpt delete mode 100644 tests/validate_ES_ssn.phpt diff --git a/Validate/ES.php b/Validate/ES.php deleted file mode 100644 index 991442f..0000000 --- a/Validate/ES.php +++ /dev/null @@ -1,291 +0,0 @@ - - * @author Byron Adams - * @author Jesús Espino - * @copyright 1997-2005 Pierre-Alain Joye,Tomas V.V.Cox - * @copyright 2006 Byron Adams - * @copyright 2010 Jesús Espino - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id$ - * @link http://pear.php.net/package/Validate_ES - */ - -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Pierre-Alain Joye,Tomas V.V.Cox | -// +----------------------------------------------------------------------+ -// | This source file is subject to the New BSD license, That is bundled | -// | with this package in the file LICENSE, and is available through | -// | the world-wide-web at | -// | http://www.opensource.org/licenses/bsd-license.php | -// | If you did not receive a copy of the new BSDlicense and are unable | -// | to obtain it through the world-wide-web, please send a note to | -// | pajoye@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Tomas V.V.Cox | -// | Pierre-Alain Joye | -// | Byron Adams | -// | Jesús Espino | -// +----------------------------------------------------------------------+ -// - -/** -* Requires base class Validate -*/ -require_once 'Validate.php'; - -/** - * Data validation class for Spain - * - * This class provides methods to validate: - * - Spanish DNI number ("El documento de la identificación nacional") - * - * @category Validate - * @package Validate_ES - * @author Tomas V.V.Cox - * @author Byron Adams - * @author Jesús Espino - * @copyright 1997-2005 Pierre-Alain Joye, Tomas V.V.Cox - * @copyright 2006 Byron Adams - * @copyright 2010 Jesús Espino - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_ES - */ -class Validate_ES -{ - /** - * Validate Spanish DNI number ("El documento de la identificación nacional") - * - * In Spain, all Spanish citizens are issued with a DNI - * the numbers are used as identification for almost all purposes. - * - * @param string $dni El Documento Nacional de Indentidad a chequear - * - * @return bool returns true on success false otherwise - * @author Tomas V.V.Cox - * @author Byron Adams - * @author Jesús Espino - * @link http://es.wikipedia.org/wiki/Algoritmo_para_obtener_la_letra_del_NIF - * @link http://nationalidentificationnumber.quickseek.com/#Spain - */ - function dni($dni) - { - $dni = str_replace("-", "", trim($dni)); - $letters = 'TRWAGMYFPDXBNJZSQVHLCKET'; - - $start = 0; - if (!empty($dni)) { - $start = (strtoupper($dni{0}) == "X"); - } - - $number = substr($dni, $start, -1); - $letter = strtoupper(substr($dni, -1)); - - if (!ctype_digit($number) || !ctype_alpha($letter)) { - return false; - } - - return ($letter == $letters{$number % 23}); - } - - /** - * Validate Spanish CIF number - * - * In Spain, all Spanish companies are issued with a CIF code. - * - * @param string $cif CIF to check - * - * @return bool returns true on success false otherwise - */ - function cif($cif) - { - $cif = strtoupper(str_replace("-", "", trim($cif))); - - $letters = 'ABCDEFGHJKLMNPRQSUVW'; - $letters2 = 'ABCDEFGHIJ'; - - if (preg_match("/^[$letters]\d{7}[\d[$letters2]$/", $cif) == 0) { - return false; - } - - $letter = substr($cif, 0, 1); - - $provinceCode = substr($cif, 1, 2); - - $number = substr($cif, 3, 5); - $controlCode = substr($cif, 8, 1); - - if (strpos("CKLMNPQRSW", $letter)!==false && ctype_digit($controlCode)) { - return false; - } - - if (strpos("ABDEFGHJUV", $letter)!==false && ctype_alpha($controlCode)) { - return false; - } - - $a = $provinceCode[1]+$number[1]+$number[3]; - - $b = 0; - $oddNumbers = array($provinceCode[0], $number[0], $number[2], $number[4]); - foreach ($oddNumbers as $number) { - $x = $number*2; - if ($x >= 10) { - $x = ($x % 10)+1; - } - $b += $x; - } - - $c = $a + $b; - - $e = $c % 10; - - if ($e != 0) { - $d = 10-$e; - } else { - $d = 0; - } - - if ((int)$controlCode != $d && $letters2[$d] != $controlCode) { - return false; - } - - return true; - } - - /** - * Validate Spanish Account Client Code number - * - * In Spain, all Spanish banking accounts are issued with a CCC code. - * - * @param string $ccc CCC to check - * - * @return bool returns true on success false otherwise - */ - function ccc($ccc) - { - $ccc = str_replace(array("-", " "), "", trim($ccc)); - - if (preg_match("/\d{20}$/", $ccc) == 0) { - return false; - } - - $weight = array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6); - - $entity = substr($ccc, 0, 4); - $office = substr($ccc, 4, 4); - - $controlCode = substr($ccc, 8, 2); - $account = substr($ccc, 10, 10); - - $firstCode = "00".$entity.$office; - $secondCode = $account; - - $firstCodeResult = 0; - for ($x=0; $x < 10; $x++) { - $firstCodeResult += (int)$firstCode[$x] * $weight[$x]; - } - - $firstCodeMod = $firstCodeResult % 11; - $firstCodeResult = 11 - $firstCodeMod; - - if ($firstCodeResult == 10) { - $firstCodeResult = 1; - } - - if ($firstCodeResult == 11) { - $firstCodeResult = 0; - } - - $secondCodeResult = 0; - for ($x=0; $x < 10; $x++) { - $secondCodeResult += (int)$secondCode[$x] * $weight[$x]; - } - - $secondCodeMod = $secondCodeResult % 11; - $secondCodeResult = 11 - $secondCodeMod; - - if ($secondCodeResult == 10) { - $secondCodeResult = 1; - } - - if ($secondCodeResult == 11) { - $secondCodeResult = 0; - } - - if ($firstCodeResult == $controlCode[0] - && $secondCodeResult == $controlCode[1] - ) { - return true; - } - - return false; - } - - - /** - * Validate Spanish Social Security number - * - * In Spain, all Spanish have a social security number. - * - * @param string $ssn Social security number to check - * - * @return bool returns true on success false otherwise - */ - function ssn($ssn) - { - $ssn = str_replace(array("-", " ", "/"), "", trim($ssn)); - - $a = substr($ssn, 0, 2); - $b = substr($ssn, 2, 8); - - $code = substr($ssn, 10, 2); - - $snn = sprintf("%012d", (int)$ssn); - - if (preg_match("/^\d{12}$/", $ssn) == 0) { - return false; - } - - if ((int)$b < 10000000) { - $d = (int)$b + ((int)$a * 10000000); - } else { - $d = $a . preg_replace("/0*$/", "", $b); - } - - $c = (int)$d % 97; - - return ($c == $code); - } - - - /** - * Validate Spanish Postal Code number - * - * @param string $postcode postcode to validate - * - * @return bool true if postcode is ok, false otherwise - */ - function postalCode($postcode) - { - $postcode = trim($postcode); - if (preg_match("/^\d{5}$/", $postcode) == 0) { - return false; - } - - $provinceCode = substr($postcode, 0, 2); - if (((int) $provinceCode > 52) || ((int) $provinceCode < 1)) { - return false; - } - - return true; - } - -} diff --git a/package_ES.xml b/package_ES.xml deleted file mode 100644 index 71f9b65..0000000 --- a/package_ES.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - Validate_ES - pear.php.net - Validation class for ES - Package containes locale validation for ES such as: - * DNI - * VAT Number (CIF) - * Back Account Number - * postalCode - * Social Security Number - - - - Jesús Espino - jespino - jespinog@gmail.com - yes - - - Tomas V.V.Cox - cox - cox@idecnet.com - no - - 2010-08-02 - - - 0.6.0 - 0.5.1 - - - alpha - alpha - - New BSD - -Bug #17452 Add check for Bank Account Number -Bug #17453 Add check for Postal Code -Bug #17454 Add check for CIF -Bug #17455 Add check for Social Security Number - -Added test for all checks (ccc, cif, dni, ssn and postalCode) - - - - - - - - - - - - - - 4.2.0 - - - 1.4.0b1 - - - Validate - pear.php.net - 0.5.0 - - - - - - - - 0.5.2 - 0.5.1 - - - alpha - alpha - - New BSD - -QA release -Updated to package 2.0 -Bug #9084 Validate_ES::dni wrong use of function arguments -Bug #4660 La validación es incorrecta. - - - - - - 0.5.0 - 0.5.0 - - - alpha - alpha - - 2005-05-20 - New BSD - - Split from Validate into independent package -- CS fixes - - - - - - 0.5.1 - 0.5.0 - - - alpha - alpha - - 2005-11-04 - New BSD - Swapped to BSD licence - - - - - diff --git a/tests/validate_ES_ccc.phpt b/tests/validate_ES_ccc.phpt deleted file mode 100644 index 3e1f4c5..0000000 --- a/tests/validate_ES_ccc.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -validate_ES_ccc.phpt: Unit tests ccc method for 'Validate/ES.php' ---FILE-- - 'OK' - , '2034 4505 73 1000034682' => 'KO' - , '0000 0000 00 0000000000' => 'OK' - , '0' => 'KO' - , '1111 1111 11 1111111111' => 'KO' - , '0001 0001 65 0000000001' => 'OK' - , '' => 'KO' - ); - -$errorFound = false; -$errorFound = $errorFound || test_func(array('validate_ES','ccc'), $cccs ); -echo ($errorFound) ? '... FAILED' : '... SUCCESS'; -?> ---EXPECT-- -Test Validate_ES -**************** ---------- -Test validate_ES::ccc - _ Value State Return - V = validation result is right - X = validation result is wrong - V 2077 0024 00 3102575766 : OK OK - V 2034 4505 73 1000034682 : KO KO - V 0000 0000 00 0000000000 : OK OK - V 0 : KO KO - V 1111 1111 11 1111111111 : KO KO - V 0001 0001 65 0000000001 : OK OK - V : KO KO -... SUCCESS diff --git a/tests/validate_ES_cif.phpt b/tests/validate_ES_cif.phpt deleted file mode 100644 index b33cf92..0000000 --- a/tests/validate_ES_cif.phpt +++ /dev/null @@ -1,105 +0,0 @@ ---TEST-- -validate_ES_cif.phpt: Unit tests cif method for 'Validate/ES.php' ---FILE-- - 'OK' - , 'B00000000' => 'OK' - , 'C0000000J' => 'OK' - , 'D00000000' => 'OK' - , 'E00000000' => 'OK' - , 'F00000000' => 'OK' - , 'G00000000' => 'OK' - , 'H00000000' => 'OK' - , 'I00000000' => 'KO' - , 'I0000000J' => 'KO' - , 'J00000000' => 'OK' - , 'K0000000J' => 'OK' - , 'L0000000J' => 'OK' - , 'M0000000J' => 'OK' - , 'N0000000J' => 'OK' - , 'O00000000' => 'KO' - , 'O0000000J' => 'KO' - , 'P0000000J' => 'OK' - , 'Q0000000J' => 'OK' - , 'R0000000J' => 'OK' - , 'S0000000J' => 'OK' - , 'T00000000' => 'KO' - , 'T0000000J' => 'KO' - , 'U00000000' => 'OK' - , 'V00000000' => 'OK' - , 'W0000000J' => 'OK' - , 'X00000000' => 'KO' - , 'X0000000J' => 'KO' - , 'Y00000000' => 'KO' - , 'Y0000000J' => 'KO' - , 'Z00000000' => 'KO' - , 'Z0000000J' => 'KO' - , 'B0000000J' => 'KO' - , 'BC0000000' => 'KO' - , '123456678' => 'KO' - , 'B-00000000' => 'OK' - , 'K-0000000-J' => 'OK' - ); - -$errorFound = false; -$errorFound = $errorFound || test_func(array('validate_ES','cif'), $cifs ); -echo ($errorFound) ? '... FAILED' : '... SUCCESS'; -?> ---EXPECT-- -Test Validate_ES -**************** ---------- -Test validate_ES::cif - _ Value State Return - V = validation result is right - X = validation result is wrong - V A58818501 : OK OK - V B00000000 : OK OK - V C0000000J : OK OK - V D00000000 : OK OK - V E00000000 : OK OK - V F00000000 : OK OK - V G00000000 : OK OK - V H00000000 : OK OK - V I00000000 : KO KO - V I0000000J : KO KO - V J00000000 : OK OK - V K0000000J : OK OK - V L0000000J : OK OK - V M0000000J : OK OK - V N0000000J : OK OK - V O00000000 : KO KO - V O0000000J : KO KO - V P0000000J : OK OK - V Q0000000J : OK OK - V R0000000J : OK OK - V S0000000J : OK OK - V T00000000 : KO KO - V T0000000J : KO KO - V U00000000 : OK OK - V V00000000 : OK OK - V W0000000J : OK OK - V X00000000 : KO KO - V X0000000J : KO KO - V Y00000000 : KO KO - V Y0000000J : KO KO - V Z00000000 : KO KO - V Z0000000J : KO KO - V B0000000J : KO KO - V BC0000000 : KO KO - V 123456678 : KO KO - V B-00000000 : OK OK - V K-0000000-J : OK OK -... SUCCESS diff --git a/tests/validate_ES_dni.phpt b/tests/validate_ES_dni.phpt deleted file mode 100644 index 50395eb..0000000 --- a/tests/validate_ES_dni.phpt +++ /dev/null @@ -1,53 +0,0 @@ ---TEST-- -validate_ES_dni.phpt: Unit tests dni method for 'Validate/ES.php' ---FILE-- - 'OK' - , '00000000T' => 'OK' - , '0T' => 'OK' - , '00000000-T' => 'OK' - , '87654321X' => 'OK' - , '87654321J' => 'KO' - , '123456781' => 'KO' - , 'X12345678' => 'KO' - , '123K' => 'KO' - , '43215678X' => 'KO' - , '' => 'KO' - ); - -$errorFound = false; -$errorFound = $errorFound || test_func(array('validate_ES','dni'), $dnis ); -echo ($errorFound) ? '... FAILED' : '... SUCCESS'; -?> ---EXPECT-- -Test Validate_ES -**************** ---------- -Test validate_ES::dni - _ Value State Return - V = validation result is right - X = validation result is wrong - V 12345678Z : OK OK - V 00000000T : OK OK - V 0T : OK OK - V 00000000-T : OK OK - V 87654321X : OK OK - V 87654321J : KO KO - V 123456781 : KO KO - V X12345678 : KO KO - V 123K : KO KO - V 43215678X : KO KO - V : KO KO -... SUCCESS diff --git a/tests/validate_ES_postalCode.phpt b/tests/validate_ES_postalCode.phpt deleted file mode 100644 index fbfb5a1..0000000 --- a/tests/validate_ES_postalCode.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -validate_ES_postalCode.phpt: Unit tests postalCode method for 'Validate/ES.php' ---FILE-- - 'OK' - , '35500' => 'OK' - , '59000' => 'KO' - , '12012' => 'OK' - , '25120' => 'OK' - , '10' => 'KO' - , 'X123' => 'KO' - ); - -$errorFound = false; -$errorFound = $errorFound || test_func(array('validate_ES','postalCode'), $postalCodes ); -echo ($errorFound) ? '... FAILED' : '... SUCCESS'; -?> ---EXPECT-- -Test Validate_ES -**************** ---------- -Test validate_ES::postalCode - _ Value State Return - V = validation result is right - X = validation result is wrong - V 28080 : OK OK - V 35500 : OK OK - V 59000 : KO KO - V 12012 : OK OK - V 25120 : OK OK - V 10 : KO KO - V X123 : KO KO -... SUCCESS diff --git a/tests/validate_ES_ssn.phpt b/tests/validate_ES_ssn.phpt deleted file mode 100644 index 8b278c5..0000000 --- a/tests/validate_ES_ssn.phpt +++ /dev/null @@ -1,59 +0,0 @@ ---TEST-- -validate_ES_ssn.phpt: Unit tests ssn method for 'Validate/ES.php' ---FILE-- - 'KO' - , '281234567840' => 'OK' - , '351234567825' => 'OK' - , '35/12345678/25' => 'OK' - , '35X1234567825' => 'KO' - , '031322136383' => 'KO' - , '72011a361732' => 'KO' - , '73011a361731' => 'KO' - , '03092a136383' => 'KO' - , '03132a136385' => 'KO' - , '201113617312' => 'KO' - , '301113617334' => 'KO' - , '309221363823' => 'KO' - , '313221363822' => 'KO' - ); - -$errorFound = false; -$errorFound = $errorFound || test_func(array('validate_ES','ssn'), $ssns ); -echo ($errorFound) ? '... FAILED' : '... SUCCESS'; -?> ---EXPECT-- -Test Validate_ES -**************** ---------- -Test validate_ES::ssn - _ Value State Return - V = validation result is right - X = validation result is wrong - V 720111361735 : KO KO - V 281234567840 : OK OK - V 351234567825 : OK OK - V 35/12345678/25 : OK OK - V 35X1234567825 : KO KO - V 031322136383 : KO KO - V 72011a361732 : KO KO - V 73011a361731 : KO KO - V 03092a136383 : KO KO - V 03132a136385 : KO KO - V 201113617312 : KO KO - V 301113617334 : KO KO - V 309221363823 : KO KO - V 313221363822 : KO KO -... SUCCESS