diff --git a/dev/codesniffer/ruleset.xml b/dev/codesniffer/ruleset.xml index b5b3d90d4b2d6441540f59931cac42b6481d8467..b31cd2b3befa7834ab32f7d24802ad7432983549 100755 --- a/dev/codesniffer/ruleset.xml +++ b/dev/codesniffer/ruleset.xml @@ -135,6 +135,13 @@ <severity>0</severity> </rule> --> + <rule ref="PEAR.Commenting.FunctionComment.WrongStyle"> + <severity>0</severity> + </rule> + + <rule ref="PEAR.Commenting.FunctionComment.Empty"> + <severity>5</severity> + </rule> <rule ref="PEAR.Commenting.FunctionComment" /> <rule ref="PEAR.Commenting.FunctionComment.SpacingBeforeParamType"> diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 8aaf19054348eaccdfc87ef272defd0dd7b91dcd..8e3d33b74509c37d71898ba093fea838bc79070f 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index 2358c4f83cea49c8bd4a0699f32c879497a0a837..a550f6811aa9593f114c536a84a07772237b0721 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -95,8 +95,12 @@ class AllTests require_once dirname(__FILE__).'/CategorieTest.php'; $suite->addTestSuite('CategorieTest'); - require_once dirname(__FILE__).'/WebservicesTest.php'; // At end because it's the longer + require_once dirname(__FILE__).'/WebservicesTest.php'; $suite->addTestSuite('WebservicesTest'); + require_once dirname(__FILE__).'/ExportTest.php'; + $suite->addTestSuite('ExportTest'); + require_once dirname(__FILE__).'/ImportTest.php'; + $suite->addTestSuite('ImportTest'); require_once dirname(__FILE__).'/ModulesTest.php'; // At end because it's the longer $suite->addTestSuite('ModulesTest'); diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php index 930d7bbce1c3c1e6d8629bc200aeb4b872290cef..fea6e603450b4f83e251006ff13e8789e4aeb790 100644 --- a/test/phpunit/BuildDocTest.php +++ b/test/phpunit/BuildDocTest.php @@ -63,6 +63,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers User * @xcovers Translate diff --git a/test/phpunit/CMailFileTest.php b/test/phpunit/CMailFileTest.php index eef53b19bc58cff522d428daceb163aff140f532..6a2dea77fc3329186c97e6e791db69011988975d 100755 --- a/test/phpunit/CMailFileTest.php +++ b/test/phpunit/CMailFileTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 92ba8c26158a32243d922c262e2d17fb5038faac..511b8adcd4644263f26fda18ef7129666206b48b 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/ChargeSocialesTest.php b/test/phpunit/ChargeSocialesTest.php index e4c4ecf9fd89499ed60f23ab7ccb8abeb82aa24c..d725984f797ee261ec4640fb02a9fe80b0412a96 100755 --- a/test/phpunit/ChargeSocialesTest.php +++ b/test/phpunit/ChargeSocialesTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/CommandeFournisseurTest.php b/test/phpunit/CommandeFournisseurTest.php index 6bc7e47ef5723b6ffcd64ce3f9b8b6038bddf26b..b1bcfe0982f5622f5800d4439307a3b27ff2c6b8 100644 --- a/test/phpunit/CommandeFournisseurTest.php +++ b/test/phpunit/CommandeFournisseurTest.php @@ -40,6 +40,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers CommandeFournisseur * @xcovers CommandeFournisseurLigne * diff --git a/test/phpunit/CommandeTest.php b/test/phpunit/CommandeTest.php index aff3471550c04b79c9fad2df1f692a95bbee6654..03bbb024f8013263a2347721fe83ee88758f0abe 100644 --- a/test/phpunit/CommandeTest.php +++ b/test/phpunit/CommandeTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers Commande * @xcovers OrderLine * diff --git a/test/phpunit/CommonObjectTest.php b/test/phpunit/CommonObjectTest.php index b802cd8cd6d6e730d82315e04ea341b30d5bbdc9..ba0d3e25d886daecb8c7db853f81c4ffd5fe1f22 100644 --- a/test/phpunit/CommonObjectTest.php +++ b/test/phpunit/CommonObjectTest.php @@ -40,6 +40,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers User * @xcovers Translate diff --git a/test/phpunit/CompanyBankAccountTest.php b/test/phpunit/CompanyBankAccountTest.php index 380706fce9ae7f15bc5a7ffc1bf2a38f7e16e246..bd726353f4ee4a3cc06e96a9d2a18f19a5d53d75 100644 --- a/test/phpunit/CompanyBankAccountTest.php +++ b/test/phpunit/CompanyBankAccountTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers CompanyBankAccount * * @backupGlobals disabled diff --git a/test/phpunit/ContratTest.php b/test/phpunit/ContratTest.php index fadaf67fa0f1d9464cb3c760bee7a03d579815eb..552d31bc2196cbc2c018dd0bcf99704e7594b9a9 100644 --- a/test/phpunit/ContratTest.php +++ b/test/phpunit/ContratTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/CoreTest.php b/test/phpunit/CoreTest.php index 1e9cc93c68d534cb899de36cb472cc84c9bb2879..435082a35f633bad3318d6d6a483716dae22bf0e 100755 --- a/test/phpunit/CoreTest.php +++ b/test/phpunit/CoreTest.php @@ -17,7 +17,7 @@ */ /** - * \file test/phpunit/SecurityTest.php + * \file test/phpunit/CoreTest.php * \ingroup test * \brief PHPUnit test * \remarks To run this script as CLI: phpunit filename.php diff --git a/test/phpunit/Example_import_company_1.csv b/test/phpunit/Example_import_company_1.csv new file mode 100755 index 0000000000000000000000000000000000000000..a5bbe397f16033957e6bb50ffa599789be8b4b11 --- /dev/null +++ b/test/phpunit/Example_import_company_1.csv @@ -0,0 +1,2 @@ +"Name* (s.nom)";"Status (s.status)";"Customer* (s.client)";"Supplier* (s.fournisseur)";"DateCreation (s.datec)";"CustomerCode (s.code_client)";"SupplierCode (s.code_fournisseur)";"Address (s.address)";"Zip (s.cp)";"Town (s.ville)";"Phone (s.tel)";"Fax (s.fax)";"Url (s.url)";"Email (s.email)";"IdProf1 (s.siret)";"IdProf2 (s.siren)";"IdProf3 (s.ape)";"IdProf4 (s.idprof4)";"VATIntraShort (s.tva_intra)";"Capital (s.capital)";"Note (s.note)";"ThirdPartyType (s.fk_typent)";"Effectif (s.fk_effectif)";"JuridicalStatus (s.fk_forme_juridique)";"ProspectLevel (s.fk_prospectlevel)";"ProspectStatus (s.fk_stcomm)";"DefaultLanguage (s.default_lang)";"BarCode (s.gencod)" +"MyBigCompanyImport1";1;3;1;01/01/00;"CU01-0001";"SU01-0001";"61 jump street";123456;"Big town";101010101;101010102;"http://mycompany.com";"test@mycompany.com";;;;;"FR0123456789";10000;"This is an example of note for record";2;3;1;"PL_MEDIUM";1;"en_US";123456789 diff --git a/test/phpunit/ExportTest.php b/test/phpunit/ExportTest.php new file mode 100755 index 0000000000000000000000000000000000000000..a29a397aaeaa4cfcb16f93ce9552c791ac4ad22f --- /dev/null +++ b/test/phpunit/ExportTest.php @@ -0,0 +1,167 @@ +<?php +/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file test/phpunit/ImportTest.php + * \ingroup test + * \brief PHPUnit test + * \remarks To run this script as CLI: phpunit filename.php + */ + +global $conf,$user,$langs,$db; +//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/exports/class/export.class.php'; + +if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); +if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); +if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) + + +/** + * When no cover is provided. We use everything. + * + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class ExportTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return ExportTest + */ + function ExportTest() + { + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; + + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + // Static methods + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + print __METHOD__."\n"; + } + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + //$db->rollback(); + + print __METHOD__."\n"; + } + + /** + * Ran on start + * + * @return void + */ + protected function setUp() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + print __METHOD__."\n"; + } + /** + * Ran on start + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } + + + /** + * Test export function + * + * @return void + */ + public function testExportPersonalizedExport() + { + global $conf,$user,$langs,$db; + + $sql = "SELECT f.facnumber as f_facnumber, f.amount as f_amount, f.total as f_total, f.tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; + + $objexport=new Export($db); + //$objexport->load_arrays($user,$datatoexport); + + // Define properties + $datatoexport='test'; + $array_selected = array("f.facnumber"=>1, "f.amount"=>2, "f.total"=>3, "f.tva"=>4); + $array_export_fields = array("f.facnumber"=>"FacNumber", "f.amount"=>"FacAmount", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); + $array_alias = array("f_facnumber"=>"facnumber", "f_amount"=>"amount", "f_total"=>"total", "f_tva"=>"tva"); + $objexport->array_export_fields[0]=$array_export_fields; + $objexport->array_export_alias[0]=$array_alias; + + $model='csv'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $expectedresult=1; + $this->assertEquals($result,$expectedresult); + + $model='tsv'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $expectedresult=1; + $this->assertEquals($result,$expectedresult); + + $model='excel'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $expectedresult=1; + $this->assertEquals($result,$expectedresult); + + return true; + } + +} +?> \ No newline at end of file diff --git a/test/phpunit/FactureFournisseurTest.php b/test/phpunit/FactureFournisseurTest.php index dfc5e49ef7f3135da67c202fc5c5b84dd6bac5b8..2b7a7b67aaab34f635e5896026466976059ad369 100644 --- a/test/phpunit/FactureFournisseurTest.php +++ b/test/phpunit/FactureFournisseurTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers User * @xcovers Translate diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index 674d851e6436793b29f1580910ff39fc5b54343a..48c88e4299fc608e285521380c3de39ad0479b37 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers User * @xcovers Translate diff --git a/test/phpunit/FunctionsTest.php b/test/phpunit/FunctionsTest.php index 2cef6cbcfa6f6d0551c1d826e04f066b808e21df..b2ec54f0d8984bdabdcb5835450e506032f41b50 100755 --- a/test/phpunit/FunctionsTest.php +++ b/test/phpunit/FunctionsTest.php @@ -41,6 +41,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is /** + * * @backupGlobals disabled * @backupStaticAttributes enabled * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. diff --git a/test/phpunit/ImportTest.php b/test/phpunit/ImportTest.php new file mode 100755 index 0000000000000000000000000000000000000000..301f56c8700de5a8cef09f2cbdaf5f55f6036703 --- /dev/null +++ b/test/phpunit/ImportTest.php @@ -0,0 +1,124 @@ +<?php +/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file test/phpunit/ImportTest.php + * \ingroup test + * \brief PHPUnit test + * \remarks To run this script as CLI: phpunit filename.php + */ + +global $conf,$user,$langs,$db; +//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; + +if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); +if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); +if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) + + +/** + * When no cover is provided. We use everything. + * + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class ImportTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return ImportTest + */ + function ImportTest() + { + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; + + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + // Static methods + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + print __METHOD__."\n"; + } + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + //$db->rollback(); + + print __METHOD__."\n"; + } + + /** + */ + protected function setUp() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + print __METHOD__."\n"; + } + /** + */ + protected function tearDown() + { + print __METHOD__."\n"; + } + + + /** + */ + public function testImportSample1() + { + + + + return true; + } + +} +?> \ No newline at end of file diff --git a/test/phpunit/ModulesTest.php b/test/phpunit/ModulesTest.php index f319f74d6e14a58e7251d4bd3a81c51b111a71ee..4e02d9b288542115c4a50107d0c4eee39f79f1b8 100755 --- a/test/phpunit/ModulesTest.php +++ b/test/phpunit/ModulesTest.php @@ -38,6 +38,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DolibarrModules * @xcovers modAccounting * @xcovers modAdherent diff --git a/test/phpunit/PropalTest.php b/test/phpunit/PropalTest.php index 2cb10af4d6e484aea785f7d4a92854f98349c94f..045fbd2d7e2d7dbcc00398830a6952cdd727f99b 100644 --- a/test/phpunit/PropalTest.php +++ b/test/phpunit/PropalTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers Propal * @xcovers PropaleLigne * diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 347d94cbc04c6cff833971c89fabaa9c89105787..c83eb81fa0b41f8d768d5a3e9b373bd86d6cea7a 100755 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -42,6 +42,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 7d6aa47a6db53850396ea6172585471f69bcdb42..a5f761677f99a76f0cebe7f96089908c8ff37e27 100755 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Conf * @xcovers Societe diff --git a/test/phpunit/UserGroupTest.php b/test/phpunit/UserGroupTest.php index 26b706090c853dc025ff44d24cdae0d0765bd5f3..c98fd59501dba6f72e625cafb19da4e307d13e0b 100644 --- a/test/phpunit/UserGroupTest.php +++ b/test/phpunit/UserGroupTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/UserTest.php b/test/phpunit/UserTest.php index 7347905c3fec5eaa83cde9faf9be4fa3c35f0c0f..a166834b977a63bd7a682791b44b70280d3aa3e1 100644 --- a/test/phpunit/UserTest.php +++ b/test/phpunit/UserTest.php @@ -39,6 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** + * * @xcovers DoliDb * @xcovers Translate * @xcovers Conf diff --git a/test/phpunit/WebservicesTest.php b/test/phpunit/WebservicesTest.php index 250bf687578803c5011b885c84f35a349eeedb06..a5d8acb74b2ed825ccdced2cdd9d50c40c6f26bb 100755 --- a/test/phpunit/WebservicesTest.php +++ b/test/phpunit/WebservicesTest.php @@ -41,7 +41,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; /** - * When not cover is provided. We use everything. + * When no cover is provided. We use everything. * * @backupGlobals disabled * @backupStaticAttributes enabled