diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index f706bda19..fdd7e1960 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -240,7 +240,7 @@ function isDate($p_date) { if (strlen(trim($p_date)) == 0) return null; - if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/", $p_date) == 0) + if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}$/", $p_date) == 0) { return null; diff --git a/unit-test/include/lib/ac_commonTest.php b/unit-test/include/lib/ac_commonTest.php index 25ce794a1..2a2da0a0e 100644 --- a/unit-test/include/lib/ac_commonTest.php +++ b/unit-test/include/lib/ac_commonTest.php @@ -1,4 +1,4 @@ -assertEquals($text,$text); } + /** + * provides data to testIsDate + */ + function dataIsDate() + { + return array( + ['01.01.1992',1], + ['30.02.2001',0], + ['15.07.01',0], + ['21.08.2001',1] + ); + } + /** + * @covers IsDate + * @testdox isDate + * @dataProvider dataIsDate + */ + function testIsDate($p_date,$expected) + { + $return=($expected==1)?$p_date:null; + $this->assertEquals(isDate($p_date),$return,"Test $p_date"); + } + function dataCompareDate () + { + return array( + ['01.01.1992','05.02.2001',-1], + ['01.01.2012','05.02.2001',1], + ['05.02.2001','05.02.2001',0]); + } + /** + * @covers cmpDate + * @testDox test cmpDate + * @dataProvider dataCompareDate + */ + function testCompareDate($p_date,$p_date_2,$p_result) + { + $cmp=cmpDate($p_date,$p_date_2); + switch ( $p_result ) { + case 0: + $this->assertEquals($cmp,0); + break; + case 1: + $this->assertGreaterThan(0,$cmp); + break; + case -1: + $this->assertLessThan(0,$cmp); + break; + + } + } }