From a11c771993bd31d9a20ad92f4f79570bb7aeb282 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Apr 2013 13:34:37 +0200 Subject: [PATCH 1/5] Qual: More PHPUnit tests --- test/phpunit/Functions2Test.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/phpunit/Functions2Test.php b/test/phpunit/Functions2Test.php index 46f662576f5..3c44e004fc9 100755 --- a/test/phpunit/Functions2Test.php +++ b/test/phpunit/Functions2Test.php @@ -127,8 +127,32 @@ class Functions2Test extends PHPUnit_Framework_TestCase $result=jsUnEscape('%u03BD%u03B5%u03BF'); print __METHOD__." result=".$result."\n"; $this->assertEquals('νεο',$result); - - return; } + + /** + * isValidMailDomain + * + * @return void + */ + public function testIsValidMailDomain() + { + + } + + /** + * isValidURL + * + * @return void + */ + public function testIsValidUrl() + { + $result=isValidUrl('http://www.google.com',1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1,$result); + $result=isValidUrl('www.google.com',2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0,$result); + } + } ?> \ No newline at end of file From 248de051963a8ec43faf3bf39de370d794b6ed52 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Apr 2013 15:00:41 +0200 Subject: [PATCH 2/5] Fix: bug into is_erasable function. --- htdocs/compta/facture/class/facture.class.php | 11 ++--- htdocs/core/lib/functions2.lib.php | 46 +++++++++---------- test/phpunit/NumberingModulesTest.php | 29 ++++++++---- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 272e2d313b5..f36ddc88a1d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1611,7 +1611,7 @@ class Facture extends CommonInvoice $now=dol_now(); $error=0; - dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse, LOG_WARNING); + dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse); // Check parameters if (! $this->brouillon) @@ -2611,11 +2611,10 @@ class Facture extends CommonInvoice { $maxfacnumber = $this->getNextNumRef($this->client,'last'); $ventilExportCompta = $this->getVentilExportCompta(); - // Si derniere facture et si non ventilee, on peut supprimer - if ($maxfacnumber == $this->ref && $ventilExportCompta == 0) - { - return 1; - } + // If there is no invoice into the reset range and not already dispatched, we can delete + if ($maxfacnumber == '' && $ventilExportCompta == 0) return 1; + // If invoice to delete is last one and not already dispatched, we can delete + if ($maxfacnumber == $this->ref && $ventilExportCompta == 0) return 1; } else if ($this->statut == 0 && $facref == 'PROV') // Si facture brouillon et provisoire { diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index fb51b62809e..059400d7399 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -506,7 +506,7 @@ function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdopti } /** - * Return next value for a mask + * Return last or next value for a mask (according to area we should not reset) * * @param DoliDB $db Database handler * @param string $mask Mask to use @@ -688,7 +688,6 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...) if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence'; $sqlstring='SUBSTRING('.$field.', '.($posnumstart+1).', '.dol_strlen($maskcounter).')'; - //print "x".$sqlstring; // Define $maskLike $maskLike = dol_string_nospecial($mask); @@ -701,7 +700,6 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $maskLike = preg_replace('/\{dd\}/i','__',$maskLike); $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",dol_strlen($maskcounter),"_"),$maskLike); if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike); - //if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),str_pad("",dol_strlen($masktype),"_"),$maskLike); if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike); // Get counter in database @@ -715,7 +713,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if ($sqlwhere) $sql.=' AND '.$sqlwhere; //print $sql.'
'; - dol_syslog("functions2::get_next_value sql=".$sql, LOG_DEBUG); + dol_syslog("functions2::get_next_value mode=".$mode." sql=".$sql, LOG_DEBUG); $resql=$db->query($sql); if ($resql) { @@ -725,30 +723,32 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m else dol_print_error($db); if (empty($counter) || preg_match('/[^0-9]/i',$counter)) $counter=$maskoffset; - if ($mode == 'last') + if ($mode == 'last') // We found value for counter = last counter value. Now need to get corresponding ref of invoice. { $counterpadded=str_pad($counter,dol_strlen($maskcounter),"0",STR_PAD_LEFT); - // Define $maskLike - $maskLike = dol_string_nospecial($mask); - $maskLike = str_replace("%","_",$maskLike); - // Replace protected special codes with matching number of _ as wild card caracter - $maskLike = preg_replace('/\{yyyy\}/i','____',$maskLike); - $maskLike = preg_replace('/\{yy\}/i','__',$maskLike); - $maskLike = preg_replace('/\{y\}/i','_',$maskLike); - $maskLike = preg_replace('/\{mm\}/i','__',$maskLike); - $maskLike = preg_replace('/\{dd\}/i','__',$maskLike); - $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike); - if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike); - //if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),str_pad("",dol_strlen($masktype),"_"),$maskLike); - if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike); - + // Define $maskLike + $maskLike = dol_string_nospecial($mask); + $maskLike = str_replace("%","_",$maskLike); + // Replace protected special codes with matching number of _ as wild card caracter + $maskLike = preg_replace('/\{yyyy\}/i','____',$maskLike); + $maskLike = preg_replace('/\{yy\}/i','__',$maskLike); + $maskLike = preg_replace('/\{y\}/i','_',$maskLike); + $maskLike = preg_replace('/\{mm\}/i','__',$maskLike); + $maskLike = preg_replace('/\{dd\}/i','__',$maskLike); + $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike); + if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike); + if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike); + $ref=''; - $sql = "SELECT facnumber as ref"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; - $sql.= " WHERE facnumber LIKE '".$maskLike."'"; + $sql = "SELECT ".$field." as ref"; + $sql.= " FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE ".$field." LIKE '".$maskLike."'"; + $sql.= " AND ".$field." NOT LIKE '%PROV%'"; $sql.= " AND entity IN (".getEntity($table, 1).")"; - + if ($where) $sql.=$where; + if ($sqlwhere) $sql.=' AND '.$sqlwhere; + dol_syslog("functions2::get_next_value sql=".$sql); $resql=$db->query($sql); if ($resql) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index 946826449ed..7bd96c2d4bf 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -140,17 +140,19 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); $result2=$localobject->create($user,1); - $result3=$localobject->validate($user, $result); + $result3=$localobject->validate($user, $result); // create invoice by forcing ref print __METHOD__." result=".$result."\n"; - $this->assertEquals('1915-0001', $result); // counter must start to 1 + $this->assertEquals('1915-0001', $result); // counter must start to 1 $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + $this->assertEquals('1915-0001', $result); $result=$numbering->getNextValue($mysoc, $localobject); print __METHOD__." result=".$result."\n"; - $this->assertEquals('1916-0002', $result); // counter must not be reset + $this->assertEquals('1916-0002', $result); // counter must not be reseted so be 2 // Now we try with a reset $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000@1}'; @@ -162,7 +164,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); print __METHOD__." result=".$result."\n"; - $this->assertEquals('1910-0001', $result); // counter must start to 1 + $this->assertEquals('1910-0001', $result); // counter must start to 1 // Same mask but we add month $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@1}'; @@ -175,15 +177,15 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result2=$localobject->create($user,1); $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; - $this->assertEquals('192001-0001', $result); // counter must start to 1 + $this->assertEquals('192001-0001', $result); // counter must start to 1 $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); print __METHOD__." result=".$result."\n"; - $this->assertEquals('192101-0001', $result); // counter must be resete to 1 + $this->assertEquals('192101-0001', $result); // counter must be reseted to 1 // Now we try with a different fiscal month (forced by mask) @@ -194,16 +196,25 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + print __METHOD__." result for last=".$result."\n"; + $this->assertEquals('', $result); // no existing ref into reset range $result=$numbering->getNextValue($mysoc, $localobject); $result2=$localobject->create($user,1); $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; - $this->assertEquals('193001-0001', $result); // counter must start to 1 + $this->assertEquals('193001-0001', $result); // counter must start to 1 + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + print __METHOD__." result for last=".$result."\n"; + $this->assertEquals('193001-0001', $result); // last ref into reset range should be same than last created $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + print __METHOD__." result for last=".$result."\n"; + $this->assertEquals('', $result); // last ref into reset range should be '' $result=$numbering->getNextValue($mysoc, $localobject); $result2=$localobject->create($user,1); $result3=$localobject->validate($user, $result); From 5b110ebae927ea2b4cd4aa4ce7158560444be808 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Apr 2013 15:49:00 +0200 Subject: [PATCH 3/5] Qual: Include is_erasable() into test --- test/phpunit/NumberingModulesTest.php | 54 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index 7bd96c2d4bf..008ffe6ce94 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -131,6 +131,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase // First we try with a simple mask, with no reset // and we test counter is still increase second year. + $conf->global->FACTURE_ADDON='mercure'; $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000}'; $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000}'; @@ -143,17 +144,29 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result3=$localobject->validate($user, $result); // create invoice by forcing ref print __METHOD__." result=".$result."\n"; $this->assertEquals('1915-0001', $result); // counter must start to 1 - - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) + $result=$localobject->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertEquals(1, $result); // Can be deleted + + $localobject2=new Facture($this->savdb); + $localobject2->initAsSpecimen(); + $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + $result=$numbering->getNextValue($mysoc, $localobject2, 'last'); + print __METHOD__." result=".$result."\n"; $this->assertEquals('1915-0001', $result); - $result=$numbering->getNextValue($mysoc, $localobject); + $result=$numbering->getNextValue($mysoc, $localobject2); + $result2=$localobject2->create($user,1); + $result3=$localobject2->validate($user, $result); // create invoice by forcing ref print __METHOD__." result=".$result."\n"; $this->assertEquals('1916-0002', $result); // counter must not be reseted so be 2 - + $result=$localobject2->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertEquals(1, $result); // Can be deleted + $result=$localobject->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertEquals(0, $result); // Case 1 can not be deleted (case 2 is more recent) + // Now we try with a reset $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000@1}'; $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000@1}'; @@ -178,15 +191,26 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; $this->assertEquals('192001-0001', $result); // counter must start to 1 - - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required) + $result=$localobject->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertEquals(1, $result); // Can be deleted + + $localobject2=new Facture($this->savdb); + $localobject2->initAsSpecimen(); + $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required) $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - print __METHOD__." result=".$result."\n"; + $result=$numbering->getNextValue($mysoc, $localobject2); + $result2=$localobject2->create($user,1); + $result3=$localobject2->validate($user, $result); + print __METHOD__." result=".$result."\n"; $this->assertEquals('192101-0001', $result); // counter must be reseted to 1 - + $result=$localobject2->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertEquals(1, $result); // Can be deleted + $result=$localobject->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertEquals(1, $result); // Case 1 can be deleted (because there was a reset for case 2) + // Now we try with a different fiscal month (forced by mask) $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@6}'; @@ -233,7 +257,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different discal year but same year + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); print __METHOD__." result=".$result."\n"; From b30c492494fec07c2fb1f4cf17361a2d0e1ad330 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Apr 2013 16:29:21 +0200 Subject: [PATCH 4/5] Fix: pgsql upgrade --- htdocs/install/mysql/migration/3.3.0-3.4.0.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql index 479874a441f..e8c1da2aa4f 100755 --- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql +++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql @@ -110,6 +110,14 @@ ALTER TABLE llx_c_shipment_mode ADD COLUMN tracking VARCHAR(256) NOT NULL DEFAUL -- VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; -- VPGSQL8.2 DROP table llx_c_shipment_mode; -- VPGSQL8.2 CREATE TABLE llx_c_shipment_mode (rowid SERIAL PRIMARY KEY, tms timestamp, code varchar(30) NOT NULL, libelle varchar(50) NOT NULL, description text, tracking varchar(256) NOT NULL, active integer DEFAULT 0, module varchar(32) NULL); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (1,'CATCH','Catch','Catch by client','',1); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (2,'TRANS','Transporter','Generic transporter','',1); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (3,'COLSUI','Colissimo Suivi','Colissimo Suivi','',0); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (4,'LETTREMAX','Lettre Max','Courrier Suivi et Lettre Max','',0); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (5,'UPS','UPS','United Parcel Service','http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber2=&InquiryNumber3=&tracknums_displayed=3&loc=fr_FR&TypeOfInquiryNumber=T&HTMLVersion=4.0&InquiryNumber22=&InquiryNumber32=&track=Track&Suivi.x=64&Suivi.y=7&Suivi=Valider&InquiryNumber1={TRACKID}',0); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (6,'KIALA','KIALA','Relais Kiala','http://www.kiala.fr/tnt/delivery/{TRACKID}',0); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (7,'GLS','GLS','General Logistics Systems','http://www.gls-group.eu/276-I-PORTAL-WEB/content/GLS/FR01/FR/5004.htm?txtAction=71000&txtRefNo={TRACKID}',0); +-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (8,'CHRONO','Chronopost','Chronopost','http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?listeNumeros={TRACKID}',0); -- and create the new index and constraint ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_shipping_method (fk_shipping_method); From d28316f4a8039654fc027edfcd54a32026a95a4d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Apr 2013 16:33:05 +0200 Subject: [PATCH 5/5] Look: Optimize size --- htdocs/admin/carrier.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/carrier.php b/htdocs/admin/carrier.php index ebc31c8b4cb..edb995d3fe7 100644 --- a/htdocs/admin/carrier.php +++ b/htdocs/admin/carrier.php @@ -153,7 +153,7 @@ if ($action=='edit_carrier' || $action=='setvalue') $var=!$var; print ''; print $langs->trans("Tracking").''; - print ''; + print ''; print '   '.$langs->trans("Example").': http://www.website.com/dir/{TRACKID}'; print ''; @@ -194,7 +194,7 @@ else print ''.$object->listmeths[$i]['code'].''; print ''.$object->listmeths[$i]['libelle'].''; print ''.$object->listmeths[$i]['description'].''; - print ''.$object->listmeths[$i]['tracking'].''; + print ''.dol_trunc($object->listmeths[$i]['tracking'],92,'middle').''; print ''; if($object->listmeths[$i]['active'] == 0) {