cvs: pear /Validate package_AT.xml /Validate/Validate AT.php /Validate/tests validate_AT.phpt

From: Date: Tue, 21 Aug 2007 23:01:09 +0000
Subject: cvs: pear /Validate package_AT.xml /Validate/Validate AT.php /Validate/tests validate_AT.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48484@lists.php.net to get a copy of this message
kguest Tue Aug 21 23:01:09 2007 UTC Modified files: /pear/Validate package_AT.xml /pear/Validate/Validate AT.php /pear/Validate/tests validate_AT.phpt Log: Bug #11885 coding standard errors plus DATADIR reference won't work when testing from CVS

http://cvs.php.net/viewvc.cgi/pear/Validate/package_AT.xml?r1=1.13&r2=1.14&diff_format=u Index: pear/Validate/package_AT.xml diff -u pear/Validate/package_AT.xml:1.13 pear/Validate/package_AT.xml:1.14 --- pear/Validate/package_AT.xml:1.13 Fri Nov 4 16:23:28 2005 +++ pear/Validate/package_AT.xml Tue Aug 21 23:01:08 2007 @@ -33,6 +33,7 @@ </file> </dir> <dir name="tests" role="test"> + <file>validate_functions.inc</file> <file>validate_AT.phpt</file> </dir> <file role="data" name="data/AT_postcodes.txt" install-as="AT_postcodes.txt" /> http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/AT.php?r1=1.22&r2=1.23&diff_format=u Index: pear/Validate/Validate/AT.php diff -u pear/Validate/Validate/AT.php:1.22 pear/Validate/Validate/AT.php:1.23 --- pear/Validate/Validate/AT.php:1.22 Wed Aug 30 12:11:25 2006 +++ pear/Validate/Validate/AT.php Tue Aug 21 23:01:09 2007 @@ -1,32 +1,27 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Michael Wallner | -// +----------------------------------------------------------------------+ -// | 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: Michael Wallner <mike@iworks.at> | -// | Byron Adams <byron.adams54@gmail.com> | -// +----------------------------------------------------------------------+ -// /** * Specific validation methods for data used in Austria * - * @category Validate - * @package Validate_AT - * @author Michael Wallner <mike@php.net> - * @author Byron Adams <byron.adams54@gmail.com> - * @copyright 1997-2005 Michael Wallner - * @copyright (c) 2006 Byron Adams - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: AT.php,v 1.22 2006/08/30 12:11:25 badams Exp $ - * @link http://pear.php.net/package/Validate_AT + * PHP Versions 4 and 5 + * + * 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. + * + * @category Validate + * @package Validate_AT + * @author Michael Wallner <mike@php.net> + * @author Byron Adams <byron.adams54@gmail.com> + * @copyright 1997-2005 Michael Wallner + * @copyright 2006 Byron Adams + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: AT.php,v 1.23 2007/08/21 23:01:09 kguest Exp $ + * @link http://pear.php.net/package/Validate_AT */ @@ -39,35 +34,43 @@ * - Postal code (Postleitzahl) * - Regional code (Regionaler Code) * - * @category Validate - * @package Validate_AT - * @author Michael Wallner <mike@php.net> - * @author Byron Adams <byron.adams54@gmail.com> - * @copyright 1997-2005 Michael Wallner - * @copyright (c) 2006 Byron Adams - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_AT + * @category Validate + * @package Validate_AT + * @author Michael Wallner <mike@php.net> + * @author Byron Adams <byron.adams54@gmail.com> + * @copyright 1997-2005 Michael Wallner + * @copyright 2006 Byron Adams + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_AT */ class Validate_AT { - /** - * Validate postcode ("Postleitzahl") - * - * @static $postcodes - * @access public - * @param string postcode to validate - * @param bool optional; strong checks against a list of postcodes - * @return bool true if postcode is ok, false otherwise - */ - function postalCode($postcode, $strong = false) + /** + * Validate postcode ("Postleitzahl") + * + * @param string $postcode postcode to validate + * @param bool $strong optional; strong checks against a list of postcodes + * @param string $dataDir optional; name of directory datafile can be + * found in. set during install process but may be + * overridden. + * + * @static $postcodes + * @access public + * @return bool true if postcode is ok, false otherwise + */ + function postalCode($postcode, $strong = false, $dataDir = null) { if ($strong) { static $postcodes; if (!isset($postcodes)) { - $file = '@DATADIR@/Validate_AT/AT_postcodes.txt'; + if ($dataDir != null && (is_file($dataDir . '/AT_postcodes.txt'))) { + $file = $dataDir . '/AT_postcodes.txt'; + } else { + $file = '@DATADIR@/Validate_AT/AT_postcodes.txt'; + } $postcodes = array_map('trim', file($file)); } @@ -76,19 +79,20 @@ return preg_match("(^[0-9]{4}$)", $postcode); } - /** - * Validate SSN ("Sozialversicherungsnummer") - * - * @access public - * @param string $svn, the SVN number to validate - * @return bool true if SVN is ok, false otherwise - */ + /** + * Validate SSN ("Sozialversicherungsnummer") + * + * @param string $ssn the SSN/SVN number to validate + * + * @return bool true if SVN is ok, false otherwise + * @access public + */ function ssn($ssn) { $weights = array("3", "7", "9", "0", "5", "8", "4", "2", "1", "6"); - $ssn = preg_replace("/[^\d]/", "", trim($ssn)); - $digits = str_split($ssn); + $lssn = preg_replace("/[^\d]/", "", trim($ssn)); + $digits = str_split($lssn); $sum = 0; @@ -96,21 +100,21 @@ $sum += $digit * $weights[$key]; } - return ($sum % 11 == $ssn{3}); + return ($sum % 11 == $lssn{3}); } - /** - * Validates Austrian Regional Code ("Regionaler Code") - * - * The validation is based on FIPS 10-4 region codes. - * http://en.wikipedia.org/wiki/FIPS_10-4 - * - * @access public - * @author Byron Adams <byron.adams54@gmail.com> - * @param string $region, regional code to validate - * @return bool true if regional code is ok, false otherwise - * @link http://en.wikipedia.org/wiki/List_of_FIPS_region_codes_(A-C)#AU:_Austria - */ + /** + * Validates Austrian Regional Code ("Regionaler Code") + * + * The validation is based on FIPS 10-4 region codes. + * http://en.wikipedia.org/wiki/FIPS_10-4 + * + * @param string $region regional code to validate + * + * @access public + * @return bool true if regional code is ok, false otherwise + * @link en.wikipedia.org/wiki/List_of_FIPS_region_codes_(A-C)#AU:_Austria + */ function region($region) { $region = str_ireplace(array("AU", "-", " "), "", $region); http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_AT.phpt?r1=1.4&r2=1.5&diff_format=u Index: pear/Validate/tests/validate_AT.phpt diff -u pear/Validate/tests/validate_AT.phpt:1.4 pear/Validate/tests/validate_AT.phpt:1.5 --- pear/Validate/tests/validate_AT.phpt:1.4 Mon Jul 23 04:47:53 2007 +++ pear/Validate/tests/validate_AT.phpt Tue Aug 21 23:01:09 2007 @@ -2,11 +2,17 @@ validate_AT.phpt: Unit tests for 'Validate/AT.php' --FILE-- <?php -// $Id: validate_AT.phpt,v 1.4 2007/07/23 04:47:53 moosh Exp $ +// $Id: validate_AT.phpt,v 1.5 2007/08/21 23:01:09 kguest Exp $ // Validate test script $noYes = array('NO', 'YES'); include (dirname(__FILE__).'/validate_functions.inc'); -require_once 'Validate/AT.php'; +if (is_file(dirname(__FILE__) . '/../Validate/AT.php')) { + require_once dirname(__FILE__) . '/../Validate/AT.php'; + $dataDir = '../data'; +} else { + require_once 'Validate/AT.php'; + $dataDir = null; +} echo "Test Validate_AT\n"; echo "****************\n"; @@ -35,9 +41,9 @@ '4298001282' => 'KO', '1508-10-13-50' => 'KO', '1508101050' => 'OK', - 1508101051 => 'KO', // - 4290021282 => 'KO', // - '21 34 23 12 74' => 'KO', + '1508101051' => 'KO', + '4290021282' => 'KO', + '21 34 23 12 74' => 'KO', ); @@ -49,8 +55,8 @@ $errorFound = false; $errorFound = $errorFound || test_func(array('Validate_AT','ssn' ), $ssns ); -$errorFound = $errorFound || test_func(array('Validate_AT','postalCode' ), $postalCodesStrong ); -$errorFound = $errorFound || test_func(array('Validate_AT','postalCode' ), $postalCodesStrong, true ); +$errorFound = $errorFound || test_func(array('Validate_AT','postalCode' ), $postalCodesStrong, array(false, $dataDir)); +$errorFound = $errorFound || test_func(array('Validate_AT','postalCode' ), $postalCodesStrong, array(true, $dataDir)); $errorFound = $errorFound || test_func(array('Validate_AT','postalCode' ), $postalCodes,false ); echo ($errorFound) ? '... FAILED' : '... SUCCESS'; @@ -70,10 +76,11 @@ V 1508-10-13-50 : KO KO V 1508101050 : OK OK V 1508101051 : KO KO - V -4946014 : KO KO + V 4290021282 : KO KO V 21 34 23 12 74 : KO KO --------- Test Validate_AT::postalCode +extra params:|../data _ Value State Return V = validation result is right X = validation result is wrong @@ -87,7 +94,7 @@ V a7000 : KO KO --------- Test Validate_AT::postalCode -extra params:1 +extra params:1|../data _ Value State Return V = validation result is right X = validation result is wrong @@ -113,4 +120,4 @@ V 9999 : OK OK V abc : KO KO V a7000 : KO KO -... SUCCESS \ No newline at end of file +... SUCCESS
« previous php.pear.cvs (#48484) next »