From bbfcc372873b7ef448bed4d6e40d9b022adc374d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 8 May 2010 18:38:17 +0000 Subject: [PATCH] Add more PHPUnit tests --- test/BuildDocTest.php | 150 ++++++++++++++++++++++++++++++++++++++++++ test/FactureTest.php | 1 + test/MyTestSuite.php | 4 +- test/phpunittest.xml | 21 ++++-- 4 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 test/BuildDocTest.php diff --git a/test/BuildDocTest.php b/test/BuildDocTest.php new file mode 100644 index 00000000000..8d209d29e13 --- /dev/null +++ b/test/BuildDocTest.php @@ -0,0 +1,150 @@ + + * + * 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/BuildDocTest.php + * \ingroup test + * \brief This file is an example for a 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/compta/facture/class/facture.class.php'; + +if (empty($user->id)) +{ + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); +} + + +/** + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @covers DoliDb + * @covers User + * @covers Translate + * @covers Conf + * @covers CommonObject + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class BuildDocTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return BuildDocTest + */ + function BuildDocTest() + { + //$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"; + } + + /** + * @covers ModelePDFFactures + * @covers pdf_crabe + * @covers pdf_oursin + */ + public function testFactureBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + require_once(DOL_DOCUMENT_ROOT.'/includes/modules/facture/modules_facture.php'); + $conf->facture->dir_output.='/temp'; + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->socid=1; + + // Crabe + $localobject->modelpdf='crabe'; + $result=facture_pdf_create($db, $localobject, '', $localobject->modelpdf, $langs); + + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + + // Oursin + $localobject->modelpdf='oursin'; + $result=facture_pdf_create($db, $localobject, '', $localobject->modelpdf, $langs); + + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + + return 0; + } + +} +?> \ No newline at end of file diff --git a/test/FactureTest.php b/test/FactureTest.php index 032e614f8a8..87858e8e3f1 100644 --- a/test/FactureTest.php +++ b/test/FactureTest.php @@ -49,6 +49,7 @@ if (empty($user->id)) * @covers CommonObject * @covers Facture * @covers FactureLigne + * @covers ModeleNumRefFactures * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. */ class FactureTest extends PHPUnit_Framework_TestCase diff --git a/test/MyTestSuite.php b/test/MyTestSuite.php index 4980634a992..e5ecd972863 100644 --- a/test/MyTestSuite.php +++ b/test/MyTestSuite.php @@ -53,7 +53,7 @@ class MyTestSuite require_once dirname(__FILE__).'/BuildDocTest.php'; $suite->addTestSuite('BuildDocTest'); - /* + require_once dirname(__FILE__).'/CommonObjectTest.php'; $suite->addTestSuite('CommonObjectTest'); @@ -71,7 +71,7 @@ class MyTestSuite $suite->addTestSuite('UserTest'); require_once dirname(__FILE__).'/UserGroupTest.php'; $suite->addTestSuite('UserGroupTest'); -*/ + return $suite; } } diff --git a/test/phpunittest.xml b/test/phpunittest.xml index 0d7e558be8b..fbe6eaf6bd1 100644 --- a/test/phpunittest.xml +++ b/test/phpunittest.xml @@ -1,10 +1,21 @@ - ../test/ - ../htdocs/includes/adodbtime/ - ../htdocs/includes/artichow/ - ../htdocs/includes/fpdf/ + ../test/ + ../htdocs/includes/adodbtime/ + ../htdocs/includes/artichow/ + ../htdocs/includes/barcode/php-barcode/ + ../htdocs/includes/fpdf/ + ../htdocs/includes/efc_xfss/ + ../htdocs/includes/fckeditor/ + ../htdocs/includes/iphone/ + ../htdocs/includes/jcrop/ + ../htdocs/includes/jquery/ + ../htdocs/includes/odtphp/ + ../htdocs/includes/nusoap/ + ../htdocs/includes/pwc/ + ../htdocs/includes/smarty/ + ../htdocs/includes/vcard/ ../htdocs/lib/databases/mssql.lib.php ../htdocs/lib/databases/pgsql.lib.php ../htdocs/lib/databases/mysql.lib.php @@ -13,6 +24,8 @@ ../htdocs/ ../htdocs/ + ../htdocs/ + ../htdocs/includes/modules/facture/modules_facture.php \ No newline at end of file