From fa526a95090064c75e579ea9821aa4ccaea258a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@users.sourceforge.net> Date: Sun, 3 Oct 2010 18:53:40 +0000 Subject: [PATCH] Qual: Add more PHPUnit tests --- test/phpunit/AdherentTest.php | 2 +- test/phpunit/BuildDocTest.php | 2 +- test/phpunit/CommandeFournisseurTest.php | 250 +++++++++++++++++++++++ test/phpunit/CommandeTest.php | 2 +- test/phpunit/CommonObjectTest.php | 2 +- test/phpunit/CompanyBankAccountTest.php | 2 +- test/phpunit/ContratTest.php | 2 +- test/phpunit/DateLibTest.php | 2 +- test/phpunit/FactureFournisseurTest.php | 235 +++++++++++++++++++++ test/phpunit/FactureTest.php | 2 +- test/phpunit/MyTestSuite.php | 8 +- test/phpunit/PropalTest.php | 2 +- test/phpunit/UserGroupTest.php | 2 +- test/phpunit/UserTest.php | 2 +- 14 files changed, 502 insertions(+), 13 deletions(-) create mode 100644 test/phpunit/CommandeFournisseurTest.php create mode 100644 test/phpunit/FactureFournisseurTest.php diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index e48096c0db2..ac0939a54be 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/AdherentTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php index 619b904b6fd..ace431f7d36 100644 --- a/test/phpunit/BuildDocTest.php +++ b/test/phpunit/BuildDocTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/BuildDocTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/CommandeFournisseurTest.php b/test/phpunit/CommandeFournisseurTest.php new file mode 100644 index 00000000000..1e81cb2f3c8 --- /dev/null +++ b/test/phpunit/CommandeFournisseurTest.php @@ -0,0 +1,250 @@ +<?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/CommandeFournisseurTest.php + * \ingroup test + * \brief PHPUnit test + * \version $Id$ + * \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/fourn/class/fournisseur.commande.class.php'; + +if (empty($user->id)) +{ + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); +} +$conf->global->MAIN_DISABLE_ALL_MAILS=1; + + +/** + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @covers CommandeFournisseur + * @covers OrderLineFournisseur + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class CommandeFournisseurTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return CommandeFournisseurTest + */ + function CommandeFournisseurTest() + { + //$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"; + //print $db->getVersion()."\n"; + } + /** + */ + protected function tearDown() + { + print __METHOD__."\n"; + } + + /** + */ + public function testCommandeFournisseurCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new CommandeFournisseur($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); + + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } + + /** + * @depends testCommandeFournisseurCreate + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new CommandeFournisseur($this->savdb); + $result=$localobject->fetch($id); + + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } + + /** + * @depends testCommandeFournisseurFetch + * The depends says test is run only if previous is ok + */ +/* public function testCommandeFournisseurUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject->note='New note after update'; + $result=$localobject->update($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject->id; + } +*/ + /** + * @depends testCommandeFournisseurFetch + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $result=$localobject->valid($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } + + /** + * @depends testCommandeFournisseurValid + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurCancel($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $result=$localobject->cancel($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject->id; + } + + /** + * @depends testCommandeFournisseurCancel + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new CommandeFournisseur($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); + + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } + + /** + * + */ + public function testVerifyNumRef() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new CommandeFournisseur($this->savdb); + $result=$localobject->ref='refthatdoesnotexists'; + $result=$localobject->VerifyNumRef(); + + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 0); + return $result; + } +} +?> \ No newline at end of file diff --git a/test/phpunit/CommandeTest.php b/test/phpunit/CommandeTest.php index c07b119881e..9867fd450c4 100644 --- a/test/phpunit/CommandeTest.php +++ b/test/phpunit/CommandeTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/CommandeTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/CommonObjectTest.php b/test/phpunit/CommonObjectTest.php index 22af5847a63..17048356a0a 100644 --- a/test/phpunit/CommonObjectTest.php +++ b/test/phpunit/CommonObjectTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/CommonObjectTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/CompanyBankAccountTest.php b/test/phpunit/CompanyBankAccountTest.php index 2fd8f567095..16bd3e9dee4 100644 --- a/test/phpunit/CompanyBankAccountTest.php +++ b/test/phpunit/CompanyBankAccountTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/CompanyBankAccount.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/ContratTest.php b/test/phpunit/ContratTest.php index bcad727db5e..1e2d77eb591 100644 --- a/test/phpunit/ContratTest.php +++ b/test/phpunit/ContratTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/ContratTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/DateLibTest.php b/test/phpunit/DateLibTest.php index 4a2182b6247..5b0154b0093 100644 --- a/test/phpunit/DateLibTest.php +++ b/test/phpunit/DateLibTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/DateLibTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/FactureFournisseurTest.php b/test/phpunit/FactureFournisseurTest.php new file mode 100644 index 00000000000..f6e3190b3b2 --- /dev/null +++ b/test/phpunit/FactureFournisseurTest.php @@ -0,0 +1,235 @@ +<?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/FactureFournisseurTest.php + * \ingroup test + * \brief PHPUnit test + * \version $Id$ + * \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/fourn/class/fournisseur.facture.class.php'; + +if (empty($user->id)) +{ + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); +} +$conf->global->MAIN_DISABLE_ALL_MAILS=1; + + +/** + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @covers DoliDb + * @covers User + * @covers Translate + * @covers Conf + * @covers Interfaces + * @covers CommonObject + * @covers FactureFournisseur + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class FactureFournisseurTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return FactureFournisseurTest + */ + function FactureFournisseurTest() + { + //$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 testFactureFournisseurCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new FactureFournisseur($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); + + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } + + /** + * @depends testFactureFournisseurCreate + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new FactureFournisseur($this->savdb); + $result=$localobject->fetch($id); + + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } + + /** + * @depends testFactureFournisseurFetch + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject->note='New note after update'; + $result=$localobject->update($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } + + /** + * @depends testFactureFournisseurUpdate + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $result=$localobject->validate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + + $this->assertLessThan($result, 0); + return $localobject->id; + } + + /** + * @depends testFactureFournisseurValid + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new FactureFournisseur($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($id); + + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } + + /** + * + */ + /*public function testVerifyNumRef() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Facture($this->savdb); + $result=$localobject->ref='refthatdoesnotexists'; + $result=$localobject->VerifyNumRef(); + + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 0); + return $result; + }*/ +} +?> \ No newline at end of file diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index c8a40fb5175..d6cf4527c61 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/FactureTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/MyTestSuite.php b/test/phpunit/MyTestSuite.php index 6bf7d1b9609..c1415d12ca8 100644 --- a/test/phpunit/MyTestSuite.php +++ b/test/phpunit/MyTestSuite.php @@ -62,11 +62,15 @@ class MyTestSuite $suite->addTestSuite('AdherentTest'); require_once dirname(__FILE__).'/CommandeTest.php'; $suite->addTestSuite('CommandeTest'); - require_once dirname(__FILE__).'/ContratTest.php'; + require_once dirname(__FILE__).'/CommandeFournisseurTest.php'; + $suite->addTestSuite('CommandeFournisseurTest'); + require_once dirname(__FILE__).'/ContratTest.php'; $suite->addTestSuite('ContratTest'); require_once dirname(__FILE__).'/FactureTest.php'; $suite->addTestSuite('FactureTest'); - require_once dirname(__FILE__).'/PropalTest.php'; + require_once dirname(__FILE__).'/FactureFournisseurTest.php'; + $suite->addTestSuite('FactureFournisseurTest'); + require_once dirname(__FILE__).'/PropalTest.php'; $suite->addTestSuite('PropalTest'); require_once dirname(__FILE__).'/UserTest.php'; $suite->addTestSuite('UserTest'); diff --git a/test/phpunit/PropalTest.php b/test/phpunit/PropalTest.php index 3b47b430f3f..d0285186280 100644 --- a/test/phpunit/PropalTest.php +++ b/test/phpunit/PropalTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/PropalTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/UserGroupTest.php b/test/phpunit/UserGroupTest.php index fddbad3fcb3..68ef0014862 100644 --- a/test/phpunit/UserGroupTest.php +++ b/test/phpunit/UserGroupTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/UserGroupTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ diff --git a/test/phpunit/UserTest.php b/test/phpunit/UserTest.php index a31d5dd7887..61340970065 100644 --- a/test/phpunit/UserTest.php +++ b/test/phpunit/UserTest.php @@ -19,7 +19,7 @@ /** * \file test/phpunit/UserTest.php * \ingroup test - * \brief This file is an example for a PHPUnit test + * \brief PHPUnit test * \version $Id$ * \remarks To run this script as CLI: phpunit filename.php */ -- GitLab