noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 23/33: Fix : date before 2000 throws an excep


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 23/33: Fix : date before 2000 throws an exception
Date: Thu, 11 Nov 2021 06:02:49 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit b0f58ab59279a8ce9696b5568ecc4d7a1e21c4fd
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Thu Oct 21 23:46:52 2021 +0200

    Fix : date before 2000 throws an exception
---
 include/lib/ac_common.php               |  2 +-
 unit-test/include/lib/ac_commonTest.php | 52 ++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index f706bda..fdd7e19 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 25ce794..2a2da0a 100644
--- a/unit-test/include/lib/ac_commonTest.php
+++ b/unit-test/include/lib/ac_commonTest.php
@@ -1,4 +1,4 @@
-<?php
+2<?php
 
 use PHPUnit\Framework\TestCase;
 
@@ -204,4 +204,54 @@ class Ac_CommonTest extends TestCase
         $this->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;
+                
+        }
+    }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]