cvs: pear /Validate/tests credit_card.php date.php number.php validate_NL.php
| From: | Pierre-Alain Joye | Date: | Wed, 10 Dec 2003 14:35:05 +0000 |
| Subject: | cvs: pear /Validate/tests credit_card.php date.php number.php validate_NL.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14756@lists.php.net to get a copy of this message | ||
pajoye Wed Dec 10 09:35:05 2003 EDT
Modified files:
/pear/Validate/tests credit_card.php date.php number.php
validate_NL.php
Log:
- Update tests, using PHPUnit
Index: pear/Validate/tests/credit_card.php diff -u pear/Validate/tests/credit_card.php:1.1 pear/Validate/tests/credit_card.php:1.2 --- pear/Validate/tests/credit_card.php:1.1 Thu Nov 21 08:23:30 2002 +++ pear/Validate/tests/credit_card.php Wed Dec 10 09:35:05 2003 @@ -1,23 +1,44 @@ <?php +require_once 'PHPUnit.php'; require_once 'Validate.php'; -function test($res, $expected) { - static $no = 1; - if ($res !== $expected) { - echo "test $no failed\n"; +class Validate_CreditCard extends PHPUnit_TestCase +{ + var $cards = array( + 0 => false, + -1 => false, + '6762195515061813' => true, + '6762195515061814' => false, + '4405771709596026' => true, + 'Big brother is watching you' => false + ); + function Validate_date( $name ) + { + $this->PHPUnit_TestCase($name); + } + + /* will be used later */ + function setup () + { + } + + function tearDown() + { + } + + function testCreditCard() + { + foreach ($this->cards as $card=>$expected_result){ + $r = Validate::creditCard($card); + $this->assertEquals($r, $expected_result); + } } - $no++; } -// 1 -test(Validate::creditCard(0), false); -// 2 -test(Validate::creditCard(-1), false); -// 3 -test(Validate::creditCard('6762195515061813'), true); -// 4 -test(Validate::creditCard('6762195515061814'), false); -// 5 -test(Validate::creditCard(array('number' => '4405771709596026')), true); -// 6 -test(Validate::creditCard('Big brother is watching you'), false); -?> + +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_CreditCard"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); + +?> \ No newline at end of file Index: pear/Validate/tests/date.php diff -u pear/Validate/tests/date.php:1.3 pear/Validate/tests/date.php:1.4 --- pear/Validate/tests/date.php:1.3 Thu Nov 21 08:26:09 2002 +++ pear/Validate/tests/date.php Wed Dec 10 09:35:05 2003 @@ -1,55 +1,73 @@ <?php require_once 'Validate.php'; -function test($res, $expected) { - static $no = 1; - if ($res !== $expected) { - echo "test $no failed\n"; +require_once 'PHPUnit.php'; +require_once( "Validate/NL.php" ); + +class Validate_date extends PHPUnit_TestCase +{ + var $dates = array( + '121202' => array(array('format'=>'%d%m%y'), true), + '21202' => array(array('format'=>'%d%m%y'), false), + '121402' => array(array('format'=>'%d%m%y'), false), + '12120001' => array(array('format'=>'%d%m%Y'), true), + + /* Ambiguous date >> false + * They should be still valid. Maybe by changing the loop + * 1st check for the Y (4digits), and then m (2digits) + * if you got the idea ;) + */ + '220001' => array(array('format'=>'%j%n%Y'), false), + '2299' => array(array('format'=>'%j%n%y'), false), + '2120001' => array(array('format'=>'%j%m%Y'), false), + /* End */ + + '12121999' => array(array('format'=>'%d%m%Y', + 'min'=>array('01','01','1995')), true), + '12121996' => array(array('format'=>'%d%m%Y', + 'min'=>array('01','01','1995'), + 'max'=>array('01','01','1997')), true), + '29022002' => array(array('format'=>'%d%m%Y'), false), + '12.12.1902' => array(array('format'=>'%d.%m.%Y'), true), + '12/12/1902' => array(array('format'=>'%d/%m/%Y'), true), + '12/12/1902' => array(array('format'=>'%d/%m/%Y'), true), + '12:12:1902' => array(array('format'=>'%d:%m:%Y'), true), + '12' => array(array('format'=>'%g'), true), + '12' => array(array('format'=>'%G'), true), + '13:00' => array(array('format'=>'%g:%i'), false), + '24:59' => array(array('format'=>'%G:%i'), true), + '25:00' => array(array('format'=>'%G:%i'), false), + '25:00' => array(array('format'=>'%G:%i:%s'), false), + '121902' => array(array('format'=>'%m%Y'), true), + '13120001' => array(array('format'=>'%d%m%Y'), true) + ); + function Validate_date( $name ) + { + $this->PHPUnit_TestCase($name); + } + + /* will be used later */ + function setup () + { + } + + function tearDown() + { + } + + function testDate() + { + foreach ($this->dates as $date=>$data){ + $r = Validate::date($date,$data[0]); + $this->assertEquals($r, $data[1]); + } } - $no++; } -// 1 -test(Validate::date('121202','%d%m%y'), true); -// 2 -test(Validate::date('21202','%d%m%y'), false); -// 3 -test(Validate::date('121402','%d%m%y'), false); -// 4 -test(Validate::date('12120001','%d%m%Y'), true); -// 5 -test(Validate::date('2120001','%j%m%Y'), true); -// 6 -test(Validate::date('220001','%j%n%Y'), true); -// 7 -test(Validate::date('2299','%j%n%y'), true); -// 8 -test(Validate::date('12121999','%d%m%Y', array('01','01','1995')), true); -// 9 -test(Validate::date('12121996','%d%m%Y', array('01','01','1995'), array('01','01','1997')), true); -// 10 -test(Validate::date('29022002','%d%m%Y'), false); -// 11 -test(Validate::date('12.12.1902','%d.%m.%Y'), true); -// 12 -test(Validate::date('12/12/1902','%d/%m/%Y'), true); -// 13 -test(Validate::date('12/12/1902','%d/%m/%Y'), true); -// 14 -test(Validate::date('12:12:1902','%d:%m:%Y'), true); -// 15 -test(Validate::date('12','%g'), true); -// 16 -test(Validate::date('12','%G'), true); -// 17 -test(Validate::date('13:00','%g:%i'), false); -// 18 -test(Validate::date('24:59','%G:%i'), true); -// 19 -test(Validate::date('25:00','%G:%i'), false); -// 20 -test(Validate::date('25:00','%G:%i:%s'), false); -// 21 -test(Validate::date('121902','%m%Y'), true); -// 22 -test(Validate::date('13120001','%d%m%Y'), true); -?> + +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_date"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); + +?> \ No newline at end of file Index: pear/Validate/tests/number.php diff -u pear/Validate/tests/number.php:1.3 pear/Validate/tests/number.php:1.4 --- pear/Validate/tests/number.php:1.3 Thu Nov 21 08:26:09 2002 +++ pear/Validate/tests/number.php Wed Dec 10 09:35:05 2003 @@ -1,39 +1,62 @@ <?php require_once 'Validate.php'; +require_once 'PHPUnit.php'; -function test($res, $expected) { - static $no = 1; - if ($res !== $expected) { - echo "test $no failed\n"; +class Validate_Number extends PHPUnit_TestCase +{ + var $numbers = array( + 8 => array(null,true), + '-8' => array(null,true), + -8 => array(null,true), + '-8,' => array(array('decimal'=>','), false), + '-8.0' => array(array('decimal'=>','), false), + '-8,0' => array(array('decimal'=>',','dec_prec'=>2), + true), + 8.0004 => array(array('decimal'=>'.','dec_prec'=>3), + false), + 8.0004 => array(array('decimal'=>'.','dec_prec'=>4), + true), + '-8' => array(array('min'=>1,'max'=>9), false), + '-8' => array(array('min'=>-8,'max'=>-7), true), + '-8.02' => array(array('decimal'=>'.', + 'min'=>-8,'max'=>-7), false), + '-8.02' => array(array('decimal'=>'.', + 'min'=>-9,'max'=>-7), true), + '-8.02' => array(array('decimal'=>'.,', + 'min'=>-9,'max'=>-7), true) + ); + + function Validate_Number( $name ) + { + $this->PHPUnit_TestCase($name); + } + + /* will be used later */ + function setup () + { + } + + function tearDown() + { + } + + /* Is there a way to get which loop iteration failed? + * No time to investigate, feel free to modify + */ + function testNumber() + { + foreach($this->numbers as $number=>$data) { + $r = Validate::number($number,$data[0]); + $this->assertEquals($r, $data[1]); + } } - $no++; } -// 1 -test(Validate::number(8), true); -// 2 -test(Validate::number('8'), true); -// 3 -test(Validate::number('-8'), true); -// 4 -test(Validate::number(-8), true); -// 5 -test(Validate::number('-8,', ','), false); -// 6 -test(Validate::number('-8.0', ','), false); -// 7 -test(Validate::number('-8,0', ',', 2), true); -// 8 -test(Validate::number(8.0004, '.', 3), false); -// 9 -test(Validate::number(8.0004, '.', 4), true); -// 10 -test(Validate::number('-8', null, null, 1, 9), false); -// 11 -test(Validate::number('-8', null, null, -8, -7), true); -// 12 -test(Validate::number('-8.02', '.', null, -8, -7), false); -// 13 -test(Validate::number('-8.02', '.', null, -9, -7), true); -// 14 -test(Validate::number('-8.02', '.,', null, -9, -8), true); + + +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_Number"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); + ?> Index: pear/Validate/tests/validate_NL.php diff -u pear/Validate/tests/validate_NL.php:1.3 pear/Validate/tests/validate_NL.php:1.4 --- pear/Validate/tests/validate_NL.php:1.3 Wed Oct 15 12:11:52 2003 +++ pear/Validate/tests/validate_NL.php Wed Dec 10 09:35:05 2003 @@ -1,61 +1,95 @@ <?php - +require_once 'PHPUnit.php'; require_once( "Validate/NL.php" ); -//Phase 1: Testing zipcode (Validate_NL::postcode) -echo "Testing postcode check\n"; -echo validateResult("Correct postcode '1234 AB'", Validate_NL::postcode("1234 AB"), true); -echo ValidateResult("Correct postcode '1234 ab'", Validate_NL::postcode("1234 ab"), true); -echo ValidateResult("Correct postcode '1234AB'", Validate_NL::postcode("1234AB"), true); -echo ValidateResult("Correct postcode '1234ab'", Validate_NL::postcode("1234ab"), true); -echo ValidateResult("Correct postcode '1234aB'", Validate_NL::postcode("1234aB"), true); -echo ValidateResult("Incorrect postcode '123456'", Validate_NL::postcode("123456"), false); -echo ValidateResult("Incorrect postcode '1234'", Validate_NL::postcode("1234"), false); -echo ValidateResult("Incorrect postcode 'AB1234'", Validate_NL::postcode("AB1234"), false); -echo ValidateResult("Incorrect postcode 'Ab12 34'", Validate_NL::postcode("aB12 34"), false); - - - -//Phase 2: Testing phonenumbers -echo "\nTesting phonenumber check (Validate_NL::phonenumber\n"; -echo ValidateResult("Correct mobile phonenumber (0612345678)", Validate_NL::phonenumber("0612345678", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), true); -echo ValidateResult("Correct mobile phonenumber (0031612345678)", Validate_NL::phonenumber("0031612345678", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), true); -echo ValidateResult("Correct mobile phonenumber (+31612345678)", Validate_NL::phonenumber("+31612345678", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), true); -echo ValidateResult("Correct normal phonenumber (0101234567)", Validate_NL::phonenumber("0101234567", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), true); -echo ValidateResult("Correct normal phonenumber (+31101234567)", Validate_NL::phonenumber("+31101234567", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), true); -echo ValidateResult("Correct normal phonenumber (0031101234567)", Validate_NL::phonenumber("0031101234567", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), true); -echo ValidateResult("Correct (any) phonenumber (0612345678)", Validate_NL::phonenumber("0612345678", VALIDATE_NL_PHONENUMBER_TYPE_ANY), true); -echo ValidateResult("Correct (any) phonenumber (+31101234567)", Validate_NL::phonenumber("+31101234567", VALIDATE_NL_PHONENUMBER_TYPE_ANY), true); - -echo ValidateResult("Incorrect mobile phonenumber (+31101234567)", Validate_NL::phonenumber("+31101234567", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), false); -echo ValidateResult("Incorrect normal phonenumber (0031612345678)", Validate_NL::phonenumber("0031612345678", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), false); -echo ValidateResult("Incorrect phonenumber (0101234A67)", Validate_NL::phonenumber("0101234A67", VALIDATE_NL_PHONENUMBER_TYPE_ANY), false); - -//Phase 3: testing ssn (SoFi nummer) -echo "\nTesting SSN number check (Validate_NL::SSN)\n"; -echo ValidateResult("Incorrect SSN (12345678)", Validate_NL::SSN("12345678"), false); -echo ValidateResult("Incorrect SSN (1234567890)", Validate_NL::SSN("1234567890"), false); -echo ValidateResult("Correct SSN (123456789)", Validate_NL::SSN("123456789"), true); - -//Phase 4: test bankaccount number -echo "\nTesting BankAccount number check (Validate_NL::bankAccountNumber)\n"; -echo validateResult("Correct bank number (640000231)", Validate_NL::bankAccountNumber("640000231"), true); -echo validateResult("Incorrect bank number (640400231)", Validate_NL::bankAccountNumber("640400231"), false); +class Validate_NL_Test extends PHPUnit_TestCase +{ + var $postcodes = array( + "1234 AB" => true, + "1234 ab" => true, + "1234AB" => true, + "1234ab" => true, + "1234aB" => true, + "123456" => false, + "1234" => false, + "AB1234" => false, + "aB12 34" => false + ); + + var $phonenumbers = array( + "0612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, true), + "0031612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, true), + "+31612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, true), + "0101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, true), + "+31101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, true), + "0031101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, true), + "0612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_ANY, true), + "+31101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_ANY, true), + "+31101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, false), + "+0031612345678"=> array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, false) + ); + + var $ssns = array( + "12345678"=> false, + "1234567890"=> false, + "123456789"=> true + ); + + var $bank_accounts = array( + "640000231" => true, + "640400231" => false + ); + + function Validate_NL_Test( $name ) + { + $this->PHPUnit_TestCase($name); + } + /* will be used later */ + function setup () + { + } + function tearDown() + { + } + function testPostcode() + { + foreach ($this->postcodes as $postcode=>$expected_result){ + $r = Validate_NL::postcode($postcode); + $this->assertEquals($r, $expected_result); + } + } + function testPhone() + { + foreach ($this->phonenumbers as $phonenumber=>$data){ + $r = Validate_NL::phonenumber($phonenumber, $data[0]); + $this->assertEquals($r, $data[1]); + } + } -function validateResult($description, $result, $compareString) -{ - if ((string)$result == (string)$compareString) { - $ret = "$description - PASSED\n"; - } else { - $ret = "$description - FAILED\n\tResult was " . ($result == false ? "false" : $result) . ", " - ."expecting " . ($compareString == false ? "false" : $compareString) . "\n"; + function testSSN() + { + foreach ($this->ssns as $ssn=>$expected_result){ + $r = Validate_NL::SSN($ssn); + $this->assertEquals($r, $expected_result); + } } - return $ret; + function testBankAccount() + { + foreach ($this->bank_accounts as $account=>$expected_result){ + $r = Validate_NL::bankAccountNumber($account); + $this->assertEquals($r, $expected_result); + } + } } +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_NL_Test"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); ?> \ No newline at end of file
Index: pear/Validate/tests/credit_card.php diff -u pear/Validate/tests/credit_card.php:1.1 pear/Validate/tests/credit_card.php:1.2 --- pear/Validate/tests/credit_card.php:1.1 Thu Nov 21 08:23:30 2002 +++ pear/Validate/tests/credit_card.php Wed Dec 10 09:35:05 2003 @@ -1,23 +1,44 @@ <?php +require_once 'PHPUnit.php'; require_once 'Validate.php'; -function test($res, $expected) { - static $no = 1; - if ($res !== $expected) { - echo "test $no failed\n"; +class Validate_CreditCard extends PHPUnit_TestCase +{ + var $cards = array( + 0 => false, + -1 => false, + '6762195515061813' => true, + '6762195515061814' => false, + '4405771709596026' => true, + 'Big brother is watching you' => false + ); + function Validate_date( $name ) + { + $this->PHPUnit_TestCase($name); + } + + /* will be used later */ + function setup () + { + } + + function tearDown() + { + } + + function testCreditCard() + { + foreach ($this->cards as $card=>$expected_result){ + $r = Validate::creditCard($card); + $this->assertEquals($r, $expected_result); + } } - $no++; } -// 1 -test(Validate::creditCard(0), false); -// 2 -test(Validate::creditCard(-1), false); -// 3 -test(Validate::creditCard('6762195515061813'), true); -// 4 -test(Validate::creditCard('6762195515061814'), false); -// 5 -test(Validate::creditCard(array('number' => '4405771709596026')), true); -// 6 -test(Validate::creditCard('Big brother is watching you'), false); -?> + +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_CreditCard"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); + +?> \ No newline at end of file Index: pear/Validate/tests/date.php diff -u pear/Validate/tests/date.php:1.3 pear/Validate/tests/date.php:1.4 --- pear/Validate/tests/date.php:1.3 Thu Nov 21 08:26:09 2002 +++ pear/Validate/tests/date.php Wed Dec 10 09:35:05 2003 @@ -1,55 +1,73 @@ <?php require_once 'Validate.php'; -function test($res, $expected) { - static $no = 1; - if ($res !== $expected) { - echo "test $no failed\n"; +require_once 'PHPUnit.php'; +require_once( "Validate/NL.php" ); + +class Validate_date extends PHPUnit_TestCase +{ + var $dates = array( + '121202' => array(array('format'=>'%d%m%y'), true), + '21202' => array(array('format'=>'%d%m%y'), false), + '121402' => array(array('format'=>'%d%m%y'), false), + '12120001' => array(array('format'=>'%d%m%Y'), true), + + /* Ambiguous date >> false + * They should be still valid. Maybe by changing the loop + * 1st check for the Y (4digits), and then m (2digits) + * if you got the idea ;) + */ + '220001' => array(array('format'=>'%j%n%Y'), false), + '2299' => array(array('format'=>'%j%n%y'), false), + '2120001' => array(array('format'=>'%j%m%Y'), false), + /* End */ + + '12121999' => array(array('format'=>'%d%m%Y', + 'min'=>array('01','01','1995')), true), + '12121996' => array(array('format'=>'%d%m%Y', + 'min'=>array('01','01','1995'), + 'max'=>array('01','01','1997')), true), + '29022002' => array(array('format'=>'%d%m%Y'), false), + '12.12.1902' => array(array('format'=>'%d.%m.%Y'), true), + '12/12/1902' => array(array('format'=>'%d/%m/%Y'), true), + '12/12/1902' => array(array('format'=>'%d/%m/%Y'), true), + '12:12:1902' => array(array('format'=>'%d:%m:%Y'), true), + '12' => array(array('format'=>'%g'), true), + '12' => array(array('format'=>'%G'), true), + '13:00' => array(array('format'=>'%g:%i'), false), + '24:59' => array(array('format'=>'%G:%i'), true), + '25:00' => array(array('format'=>'%G:%i'), false), + '25:00' => array(array('format'=>'%G:%i:%s'), false), + '121902' => array(array('format'=>'%m%Y'), true), + '13120001' => array(array('format'=>'%d%m%Y'), true) + ); + function Validate_date( $name ) + { + $this->PHPUnit_TestCase($name); + } + + /* will be used later */ + function setup () + { + } + + function tearDown() + { + } + + function testDate() + { + foreach ($this->dates as $date=>$data){ + $r = Validate::date($date,$data[0]); + $this->assertEquals($r, $data[1]); + } } - $no++; } -// 1 -test(Validate::date('121202','%d%m%y'), true); -// 2 -test(Validate::date('21202','%d%m%y'), false); -// 3 -test(Validate::date('121402','%d%m%y'), false); -// 4 -test(Validate::date('12120001','%d%m%Y'), true); -// 5 -test(Validate::date('2120001','%j%m%Y'), true); -// 6 -test(Validate::date('220001','%j%n%Y'), true); -// 7 -test(Validate::date('2299','%j%n%y'), true); -// 8 -test(Validate::date('12121999','%d%m%Y', array('01','01','1995')), true); -// 9 -test(Validate::date('12121996','%d%m%Y', array('01','01','1995'), array('01','01','1997')), true); -// 10 -test(Validate::date('29022002','%d%m%Y'), false); -// 11 -test(Validate::date('12.12.1902','%d.%m.%Y'), true); -// 12 -test(Validate::date('12/12/1902','%d/%m/%Y'), true); -// 13 -test(Validate::date('12/12/1902','%d/%m/%Y'), true); -// 14 -test(Validate::date('12:12:1902','%d:%m:%Y'), true); -// 15 -test(Validate::date('12','%g'), true); -// 16 -test(Validate::date('12','%G'), true); -// 17 -test(Validate::date('13:00','%g:%i'), false); -// 18 -test(Validate::date('24:59','%G:%i'), true); -// 19 -test(Validate::date('25:00','%G:%i'), false); -// 20 -test(Validate::date('25:00','%G:%i:%s'), false); -// 21 -test(Validate::date('121902','%m%Y'), true); -// 22 -test(Validate::date('13120001','%d%m%Y'), true); -?> + +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_date"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); + +?> \ No newline at end of file Index: pear/Validate/tests/number.php diff -u pear/Validate/tests/number.php:1.3 pear/Validate/tests/number.php:1.4 --- pear/Validate/tests/number.php:1.3 Thu Nov 21 08:26:09 2002 +++ pear/Validate/tests/number.php Wed Dec 10 09:35:05 2003 @@ -1,39 +1,62 @@ <?php require_once 'Validate.php'; +require_once 'PHPUnit.php'; -function test($res, $expected) { - static $no = 1; - if ($res !== $expected) { - echo "test $no failed\n"; +class Validate_Number extends PHPUnit_TestCase +{ + var $numbers = array( + 8 => array(null,true), + '-8' => array(null,true), + -8 => array(null,true), + '-8,' => array(array('decimal'=>','), false), + '-8.0' => array(array('decimal'=>','), false), + '-8,0' => array(array('decimal'=>',','dec_prec'=>2), + true), + 8.0004 => array(array('decimal'=>'.','dec_prec'=>3), + false), + 8.0004 => array(array('decimal'=>'.','dec_prec'=>4), + true), + '-8' => array(array('min'=>1,'max'=>9), false), + '-8' => array(array('min'=>-8,'max'=>-7), true), + '-8.02' => array(array('decimal'=>'.', + 'min'=>-8,'max'=>-7), false), + '-8.02' => array(array('decimal'=>'.', + 'min'=>-9,'max'=>-7), true), + '-8.02' => array(array('decimal'=>'.,', + 'min'=>-9,'max'=>-7), true) + ); + + function Validate_Number( $name ) + { + $this->PHPUnit_TestCase($name); + } + + /* will be used later */ + function setup () + { + } + + function tearDown() + { + } + + /* Is there a way to get which loop iteration failed? + * No time to investigate, feel free to modify + */ + function testNumber() + { + foreach($this->numbers as $number=>$data) { + $r = Validate::number($number,$data[0]); + $this->assertEquals($r, $data[1]); + } } - $no++; } -// 1 -test(Validate::number(8), true); -// 2 -test(Validate::number('8'), true); -// 3 -test(Validate::number('-8'), true); -// 4 -test(Validate::number(-8), true); -// 5 -test(Validate::number('-8,', ','), false); -// 6 -test(Validate::number('-8.0', ','), false); -// 7 -test(Validate::number('-8,0', ',', 2), true); -// 8 -test(Validate::number(8.0004, '.', 3), false); -// 9 -test(Validate::number(8.0004, '.', 4), true); -// 10 -test(Validate::number('-8', null, null, 1, 9), false); -// 11 -test(Validate::number('-8', null, null, -8, -7), true); -// 12 -test(Validate::number('-8.02', '.', null, -8, -7), false); -// 13 -test(Validate::number('-8.02', '.', null, -9, -7), true); -// 14 -test(Validate::number('-8.02', '.,', null, -9, -8), true); + + +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_Number"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); + ?> Index: pear/Validate/tests/validate_NL.php diff -u pear/Validate/tests/validate_NL.php:1.3 pear/Validate/tests/validate_NL.php:1.4 --- pear/Validate/tests/validate_NL.php:1.3 Wed Oct 15 12:11:52 2003 +++ pear/Validate/tests/validate_NL.php Wed Dec 10 09:35:05 2003 @@ -1,61 +1,95 @@ <?php - +require_once 'PHPUnit.php'; require_once( "Validate/NL.php" ); -//Phase 1: Testing zipcode (Validate_NL::postcode) -echo "Testing postcode check\n"; -echo validateResult("Correct postcode '1234 AB'", Validate_NL::postcode("1234 AB"), true); -echo ValidateResult("Correct postcode '1234 ab'", Validate_NL::postcode("1234 ab"), true); -echo ValidateResult("Correct postcode '1234AB'", Validate_NL::postcode("1234AB"), true); -echo ValidateResult("Correct postcode '1234ab'", Validate_NL::postcode("1234ab"), true); -echo ValidateResult("Correct postcode '1234aB'", Validate_NL::postcode("1234aB"), true); -echo ValidateResult("Incorrect postcode '123456'", Validate_NL::postcode("123456"), false); -echo ValidateResult("Incorrect postcode '1234'", Validate_NL::postcode("1234"), false); -echo ValidateResult("Incorrect postcode 'AB1234'", Validate_NL::postcode("AB1234"), false); -echo ValidateResult("Incorrect postcode 'Ab12 34'", Validate_NL::postcode("aB12 34"), false); - - - -//Phase 2: Testing phonenumbers -echo "\nTesting phonenumber check (Validate_NL::phonenumber\n"; -echo ValidateResult("Correct mobile phonenumber (0612345678)", Validate_NL::phonenumber("0612345678", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), true); -echo ValidateResult("Correct mobile phonenumber (0031612345678)", Validate_NL::phonenumber("0031612345678", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), true); -echo ValidateResult("Correct mobile phonenumber (+31612345678)", Validate_NL::phonenumber("+31612345678", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), true); -echo ValidateResult("Correct normal phonenumber (0101234567)", Validate_NL::phonenumber("0101234567", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), true); -echo ValidateResult("Correct normal phonenumber (+31101234567)", Validate_NL::phonenumber("+31101234567", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), true); -echo ValidateResult("Correct normal phonenumber (0031101234567)", Validate_NL::phonenumber("0031101234567", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), true); -echo ValidateResult("Correct (any) phonenumber (0612345678)", Validate_NL::phonenumber("0612345678", VALIDATE_NL_PHONENUMBER_TYPE_ANY), true); -echo ValidateResult("Correct (any) phonenumber (+31101234567)", Validate_NL::phonenumber("+31101234567", VALIDATE_NL_PHONENUMBER_TYPE_ANY), true); - -echo ValidateResult("Incorrect mobile phonenumber (+31101234567)", Validate_NL::phonenumber("+31101234567", VALIDATE_NL_PHONENUMBER_TYPE_MOBILE), false); -echo ValidateResult("Incorrect normal phonenumber (0031612345678)", Validate_NL::phonenumber("0031612345678", VALIDATE_NL_PHONENUMBER_TYPE_NORMAL), false); -echo ValidateResult("Incorrect phonenumber (0101234A67)", Validate_NL::phonenumber("0101234A67", VALIDATE_NL_PHONENUMBER_TYPE_ANY), false); - -//Phase 3: testing ssn (SoFi nummer) -echo "\nTesting SSN number check (Validate_NL::SSN)\n"; -echo ValidateResult("Incorrect SSN (12345678)", Validate_NL::SSN("12345678"), false); -echo ValidateResult("Incorrect SSN (1234567890)", Validate_NL::SSN("1234567890"), false); -echo ValidateResult("Correct SSN (123456789)", Validate_NL::SSN("123456789"), true); - -//Phase 4: test bankaccount number -echo "\nTesting BankAccount number check (Validate_NL::bankAccountNumber)\n"; -echo validateResult("Correct bank number (640000231)", Validate_NL::bankAccountNumber("640000231"), true); -echo validateResult("Incorrect bank number (640400231)", Validate_NL::bankAccountNumber("640400231"), false); +class Validate_NL_Test extends PHPUnit_TestCase +{ + var $postcodes = array( + "1234 AB" => true, + "1234 ab" => true, + "1234AB" => true, + "1234ab" => true, + "1234aB" => true, + "123456" => false, + "1234" => false, + "AB1234" => false, + "aB12 34" => false + ); + + var $phonenumbers = array( + "0612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, true), + "0031612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, true), + "+31612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, true), + "0101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, true), + "+31101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, true), + "0031101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, true), + "0612345678" => array(VALIDATE_NL_PHONENUMBER_TYPE_ANY, true), + "+31101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_ANY, true), + "+31101234567" => array(VALIDATE_NL_PHONENUMBER_TYPE_MOBILE, false), + "+0031612345678"=> array(VALIDATE_NL_PHONENUMBER_TYPE_NORMAL, false) + ); + + var $ssns = array( + "12345678"=> false, + "1234567890"=> false, + "123456789"=> true + ); + + var $bank_accounts = array( + "640000231" => true, + "640400231" => false + ); + + function Validate_NL_Test( $name ) + { + $this->PHPUnit_TestCase($name); + } + /* will be used later */ + function setup () + { + } + function tearDown() + { + } + function testPostcode() + { + foreach ($this->postcodes as $postcode=>$expected_result){ + $r = Validate_NL::postcode($postcode); + $this->assertEquals($r, $expected_result); + } + } + function testPhone() + { + foreach ($this->phonenumbers as $phonenumber=>$data){ + $r = Validate_NL::phonenumber($phonenumber, $data[0]); + $this->assertEquals($r, $data[1]); + } + } -function validateResult($description, $result, $compareString) -{ - if ((string)$result == (string)$compareString) { - $ret = "$description - PASSED\n"; - } else { - $ret = "$description - FAILED\n\tResult was " . ($result == false ? "false" : $result) . ", " - ."expecting " . ($compareString == false ? "false" : $compareString) . "\n"; + function testSSN() + { + foreach ($this->ssns as $ssn=>$expected_result){ + $r = Validate_NL::SSN($ssn); + $this->assertEquals($r, $expected_result); + } } - return $ret; + function testBankAccount() + { + foreach ($this->bank_accounts as $account=>$expected_result){ + $r = Validate_NL::bankAccountNumber($account); + $this->assertEquals($r, $expected_result); + } + } } +// runs the tests +$suite = new PHPUnit_TestSuite("Validate_NL_Test"); +$result = PHPUnit::run($suite); +// prints the tests +echo $result->toString(); ?> \ No newline at end of file