From 68d41b82ca0538a1060f8a315fbd690cd2eb7491 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 14 Sep 2022 19:38:08 +0200 Subject: [PATCH] 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('%s',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('%s ',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('%s',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",""); ?> - + request("ac","string",""); ?> - - - + - + 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('%s',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('%s',h("test@noalyss.be"),h("test@noalyss.be")); + $expect.=sprintf('%s',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('%s',h(123),h(123)); + $expect=preg_replace('/\s+/','',$expect); + $this->assertEquals(strtoupper($expect),strtoupper(preg_replace("/\s+/",'',faxTo('123'))),); } }