From a353093ae7939a1d14e4d2fe98fbf519f9750e92 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Mon, 1 Aug 2016 20:18:31 +0200 Subject: [PATCH] NEW Phone formatting for Canada. Add dol_print_phone into phpunit tests --- htdocs/core/lib/functions.lib.php | 7 ++++++ test/phpunit/FunctionsLibTest.php | 36 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3133be47d65..87c87804ee6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1625,6 +1625,13 @@ function dol_print_phone($phone,$countrycode='',$cid=0,$socid=0,$addlink='',$sep } } + if (strtoupper($countrycode) == "CA") + { + if (dol_strlen($phone) == 10) { + $newphone=($separ!=''?'(':'').substr($newphone,0,3).($separ!=''?')':'').$separ.substr($newphone,3,3).($separ!=''?'-':'').substr($newphone,6,4); + } + } + if (! empty($addlink)) // Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set) { if (! empty($conf->browser->phone) || (! empty($conf->clicktodial->enabled) && ! empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) // If phone or option for, we use link of phone diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 4c76ba47770..ee7288e2928 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -624,6 +624,42 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $this->assertEquals("21 jump street\nMyTown, MyState, 99999",$address); } + + /** + * testDolFormatAddress + * + * @return void + */ + public function testDolPrintPhone() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $object=new Societe($db); + $object->initAsSpecimen(); + + $object->country_code='FR'; + $phone=dol_print_phone('1234567890', $object->country_code); + $this->assertEquals('<span style="margin-right: 10px;">12 34 56 78 90</span>', $phone, 'Phone for FR 1'); + + $object->country_code='FR'; + $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ''); + $this->assertEquals('<span style="margin-right: 10px;">1234567890</span>', $phone, 'Phone for FR 2'); + + $object->country_code='FR'; + $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); + $this->assertEquals('<span style="margin-right: 10px;">12 34 56 78 90</span>', $phone, 'Phone for FR 3'); + + $object->country_code='CA'; + $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); + $this->assertEquals('<span style="margin-right: 10px;">(123) 456-7890</span>', $phone, 'Phone for CA 1'); + + } + + /** * testImgPicto * -- GitLab