noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 08/12: Task #0002125: type , missed phoneTo f


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 08/12: Task #0002125: type , missed phoneTo for mobile , phone and faxTo, several emails separated by a comma
Date: Sat, 17 Sep 2022 08:40:57 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 68d41b82ca0538a1060f8a315fbd690cd2eb7491
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Sep 14 19:38:08 2022 +0200

    Task #0002125: type , missed phoneTo for mobile , phone and faxTo, several
    emails separated by a comma
---
 include/lib/ac_common.php               | 32 +++++++++++++++++++++++++++++---
 include/template/contact-summary.php    |  8 +++-----
 unit-test/include/lib/ac_commonTest.php | 20 +++++++++++++++++++-
 3 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 5bd7d8f28..2398f8fcd 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -1637,12 +1637,38 @@ function phoneTo($p_tel) {
 
 /**
  * @brief compose a HTML string with email
- * @param $p_email
+ * @param string $p_email email or emails separated by a comma
  * @return false|string returns false if email not valide
  */
 function mailTo($p_email) {
-    if ( filter_var($p_email,FILTER_VALIDATE_EMAIL) ) {
-        $r=sprintf('<a href="mailto:%s";>%s</a>',h($p_email),h($p_email));
+    if (empty($p_email )) return "";
+    $nComma=preg_match("/,/",$p_email);
+    if ( $nComma > 0) {
+        $aEmail=explode(",",$p_email);
+    } else {
+        $aEmail[0]=$p_email;
+    }
+    $r="";
+    foreach ($aEmail as $email) {
+        if ( filter_var(trim($email),FILTER_VALIDATE_EMAIL) ) {
+            $r.=sprintf('<a href="mailto:%s";>%s</a> ',h($email),h($email));
+        } else {
+            $r.=sprintf("%s",h($email));
+
+        }
+
+    }
+    return $r;
+}
+
+/**
+ * @brief compose a HTML string with fax
+ * @param string $p_fax fax number
+ * @return false|string returns false if $p_fax is empty
+ */
+function FaxTo($p_tel) {
+    if (!empty($p_tel)) {
+        $r=sprintf('<a href="fax:%s">%s</a>',h($p_tel),h($p_tel));
         return $r;
     }
     return false;
diff --git a/include/template/contact-summary.php 
b/include/template/contact-summary.php
index d13a34695..b4ebb3fa6 100644
--- a/include/template/contact-summary.php
+++ b/include/template/contact-summary.php
@@ -68,7 +68,7 @@ $from=$http->request("ac","string","");
             ?>
         </td>
         <td>
-            <?=$contact['contact_mobile']?>
+             <?=phoneTo($contact['contact_mobile'])?>
         </td>
         <td>
             <?php
@@ -82,12 +82,10 @@ $from=$http->request("ac","string","");
             ?>
         </td>
         <td>
-            <?php if (!empty($contact['contact_phone'])):?>
-                <a 
href="tel:<?=$contact['contact_phone']?>"><?=$contact['contact_phone']?></a>
-            <?php endif;?>
+            <?=phoneTo($contact['contact_phone'])?>
         </td>
         <td>
-            <?=$contact['contact_phone']?>
+            <?=FaxTo($contact['contact_fax'])?>
         </td>
     </tr>
     <?php endforeach;?>
diff --git a/unit-test/include/lib/ac_commonTest.php 
b/unit-test/include/lib/ac_commonTest.php
index 4cbcee8b4..510395b17 100644
--- a/unit-test/include/lib/ac_commonTest.php
+++ b/unit-test/include/lib/ac_commonTest.php
@@ -393,7 +393,25 @@ class Ac_CommonTest extends TestCase
         $expect=sprintf('<a 
href="mailto:%s";>%s</a>',h("test@noalyss.be"),h("test@noalyss.be"));
         $expect=preg_replace('/\s+/','',$expect);
         
$this->assertEquals(strtoupper($expect),strtoupper(preg_replace("/\s+/",'',mailTo('test@noalyss.be'))),);
-        $this->assertFalse(mailTo('test@noalyss.@be'),"Send email to 
invalidate email");
+        
$this->assertEquals('test@noalyss.@be',mailTo('test@noalyss.@be'),"Send email 
to invalidate email");
+        $expect=sprintf('<a 
href="mailto:%s";>%s</a>',h("test@noalyss.be"),h("test@noalyss.be"));
+        $expect.=sprintf('<a 
href="mailto:%s";>%s</a>',h("test2@noalyss.be"),h("test2@noalyss.be"));
+        $expect=preg_replace('/\s+/','',$expect);
+        $this->assertEquals($expect,
+            preg_replace('/\s+/','',mailTo('test@noalyss.be,test2@noalyss.be'))
+            ,"Send email to invalidate email");
+
+    }
+    /**
+     * @testdox Test the FAX tag
+     * @return void
+     */
+    function testFaxTo()
+    {
+        $this->assertFalse(faxTo(""),"Invalide phone");
+        $expect=sprintf('<a href="fax:%s">%s</a>',h(123),h(123));
+        $expect=preg_replace('/\s+/','',$expect);
+        
$this->assertEquals(strtoupper($expect),strtoupper(preg_replace("/\s+/",'',faxTo('123'))),);
 
     }
 }



reply via email to

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