diff --git a/test/CommandeTest.php b/test/CommandeTest.php index 5e22e62e4ad638737c9e4594db918114b0c8d2fe..daf2156d6213b0e9e9df6277deea4aae04282dbd 100644 --- a/test/CommandeTest.php +++ b/test/CommandeTest.php @@ -29,14 +29,18 @@ require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__).'/../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../htdocs/commande/commande.class.php'; -print "Load permissions for admin user with login 'admin'\n"; -$user->fetch('admin'); -$user->getrights(); +if (empty($user->id)) +{ + print "Load permissions for admin user with login 'admin'\n"; + $user->fetch('admin'); + $user->getrights(); +} /** - * @backupGlobals enabled + * @backupGlobals disabled * @backupStaticAttributes enabled + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. */ class CommandeTest extends PHPUnit_Framework_TestCase { @@ -69,20 +73,19 @@ class CommandeTest extends PHPUnit_Framework_TestCase 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"; - if (! $db->transaction_opened) $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. } public static function tearDownAfterClass() { global $conf,$user,$langs,$db; + $db->rollback(); print __METHOD__."\n"; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled */ protected function setUp() { @@ -96,8 +99,6 @@ class CommandeTest extends PHPUnit_Framework_TestCase //print $db->getVersion()."\n"; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled */ protected function tearDown() { @@ -105,8 +106,6 @@ class CommandeTest extends PHPUnit_Framework_TestCase } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @covers Commande::create */ public function testCommandeCreate() @@ -127,8 +126,6 @@ class CommandeTest extends PHPUnit_Framework_TestCase } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testCommandeCreate * @covers Commande::fetch * The depends says test is run only if previous is ok @@ -143,14 +140,13 @@ class CommandeTest extends PHPUnit_Framework_TestCase $localobject=new Commande($this->savdb); $result=$localobject->fetch($id); + $this->assertLessThan($result, 0); print __METHOD__." id=".$id." result=".$result."\n"; return $localobject; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testCommandeFetch * @covers Commande::update * The depends says test is run only if previous is ok @@ -165,14 +161,13 @@ class CommandeTest extends PHPUnit_Framework_TestCase $localobject->note='New note after update'; $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $localobject->id; } */ /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testCommandeFetch * @covers Commande::valid * The depends says test is run only if previous is ok @@ -186,14 +181,13 @@ class CommandeTest extends PHPUnit_Framework_TestCase $db=$this->savdb; $result=$localobject->valid($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $localobject->id; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testCommandeValid * @covers Commande::delete * The depends says test is run only if previous is ok @@ -209,7 +203,8 @@ class CommandeTest extends PHPUnit_Framework_TestCase $localobject=new Commande($this->savdb); $result=$localobject->fetch($id); $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; + + print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; } diff --git a/test/FactureTest.php b/test/FactureTest.php index 47046225219512fced268b6bf6f6643dcf2a7afb..be7ee079a1cf84c03e53c60c6828c1807894f6f4 100644 --- a/test/FactureTest.php +++ b/test/FactureTest.php @@ -29,17 +29,21 @@ require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__).'/../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../htdocs/compta/facture/class/facture.class.php'; -print "Load permissions for admin user with login 'admin'\n"; -$user->fetch('admin'); -$user->getrights(); +if (empty($user->id)) +{ + print "Load permissions for admin user with login 'admin'\n"; + $user->fetch('admin'); + $user->getrights(); +} /** - * @backupGlobals enabled + * @backupGlobals disabled * @backupStaticAttributes enabled * @covers DoliDb * @covers User * @covers Translate + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. */ class FactureTest extends PHPUnit_Framework_TestCase { @@ -72,20 +76,19 @@ class FactureTest extends PHPUnit_Framework_TestCase 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"; - if (! $db->transaction_opened) $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. } public static function tearDownAfterClass() { global $conf,$user,$langs,$db; + $db->rollback(); print __METHOD__."\n"; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled */ protected function setUp() { @@ -98,8 +101,6 @@ class FactureTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled */ protected function tearDown() { @@ -107,8 +108,6 @@ class FactureTest extends PHPUnit_Framework_TestCase } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @covers Facture::create */ public function testFactureCreate() @@ -129,8 +128,6 @@ class FactureTest extends PHPUnit_Framework_TestCase } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testFactureCreate * @covers Facture::fetch * The depends says test is run only if previous is ok @@ -145,14 +142,13 @@ class FactureTest extends PHPUnit_Framework_TestCase $localobject=new Facture($this->savdb); $result=$localobject->fetch($id); + $this->assertLessThan($result, 0); print __METHOD__." id=".$id." result=".$result."\n"; return $localobject; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testFactureFetch * @covers Facture::update * The depends says test is run only if previous is ok @@ -167,14 +163,13 @@ class FactureTest extends PHPUnit_Framework_TestCase $localobject->note='New note after update'; $result=$localobject->update($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $localobject; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testFactureUpdate * @covers Facture::set_valid * The depends says test is run only if previous is ok @@ -189,13 +184,12 @@ class FactureTest extends PHPUnit_Framework_TestCase $result=$localobject->set_valid($user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); return $localobject->id; } -/** - * @backupGlobals enabled - * @backupStaticAttributes enabled + /** * @depends testFactureValid * @covers Facture::delete * The depends says test is run only if previous is ok @@ -211,7 +205,8 @@ class FactureTest extends PHPUnit_Framework_TestCase $localobject=new Facture($this->savdb); $result=$localobject->fetch($id); $result=$localobject->delete($id); - print __METHOD__." id=".$id." result=".$result."\n"; + + print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; } diff --git a/test/MyTestSuite.php b/test/MyTestSuite.php index 45719a2daaef29bd84d251ad7d2864abdebb8485..aad027b820e011a34500f5fdca6c8548410e2f84 100644 --- a/test/MyTestSuite.php +++ b/test/MyTestSuite.php @@ -1,15 +1,42 @@ <?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/MyTestSuite.php + * \ingroup test + * \brief This file is a test suite to run all unit tests + * \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__).'/FactureTest.php'; require_once dirname(__FILE__).'/PropalTest.php'; require_once dirname(__FILE__).'/CommandeTest.php'; -print "Load permissions for admin user with login 'admin'\n"; -$user->fetch('admin'); -$user->getrights(); +if (empty($user->id)) +{ + print "Load permissions for admin user with login 'admin'\n"; + $user->fetch('admin'); + $user->getrights(); +} /** diff --git a/test/PropalTest.php b/test/PropalTest.php index 1aef2d88bff902150344d7230b6b7ccfefa07d13..39f3f9946f7abd93aa82ab3e07d61075a6082ae4 100644 --- a/test/PropalTest.php +++ b/test/PropalTest.php @@ -29,14 +29,18 @@ require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__).'/../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../htdocs/comm/propal/propal.class.php'; -print "Load permissions for admin user with login 'admin'\n"; -$user->fetch('admin'); -$user->getrights(); +if (empty($user->id)) +{ + print "Load permissions for admin user with login 'admin'\n"; + $user->fetch('admin'); + $user->getrights(); +} /** - * @backupGlobals enabled + * @backupGlobals disabled * @backupStaticAttributes enabled + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. */ class PropalTest extends PHPUnit_Framework_TestCase { @@ -69,20 +73,19 @@ class PropalTest extends PHPUnit_Framework_TestCase 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"; - if (! $db->transaction_opened) $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. } public static function tearDownAfterClass() { global $conf,$user,$langs,$db; + $db->rollback(); print __METHOD__."\n"; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled */ protected function setUp() { @@ -96,8 +99,6 @@ class PropalTest extends PHPUnit_Framework_TestCase //print $db->getVersion()."\n"; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled */ protected function tearDown() { @@ -105,8 +106,6 @@ class PropalTest extends PHPUnit_Framework_TestCase } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @covers Propal::create */ public function testPropalCreate() @@ -127,8 +126,6 @@ class PropalTest extends PHPUnit_Framework_TestCase } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testPropalCreate * @covers Propal::fetch * The depends says test is run only if previous is ok @@ -143,14 +140,13 @@ class PropalTest extends PHPUnit_Framework_TestCase $localobject=new Propal($this->savdb); $result=$localobject->fetch($id); + $this->assertLessThan($result, 0); print __METHOD__." id=".$id." result=".$result."\n"; return $localobject; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testPropalFetch * @covers Propal::update * The depends says test is run only if previous is ok @@ -165,14 +161,13 @@ class PropalTest extends PHPUnit_Framework_TestCase $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; } */ /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testPropalFetch * @covers Propal::valid * The depends says test is run only if previous is ok @@ -186,14 +181,13 @@ class PropalTest extends PHPUnit_Framework_TestCase $db=$this->savdb; $result=$localobject->valid($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $localobject->id; } /** - * @backupGlobals enabled - * @backupStaticAttributes enabled * @depends testPropalValid * @covers Propal::delete * The depends says test is run only if previous is ok @@ -209,11 +203,11 @@ class PropalTest extends PHPUnit_Framework_TestCase $localobject=new Propal($this->savdb); $result=$localobject->fetch($id); $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; + + print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; } - } ?> \ No newline at end of file diff --git a/test/phpunit.xml b/test/phpunit.xml new file mode 100644 index 0000000000000000000000000000000000000000..7a34674fe44eb47559e3e55acfac6a14c75c7ece --- /dev/null +++ b/test/phpunit.xml @@ -0,0 +1,30 @@ +<phpunit backupGlobals="false" + backupStaticAttributes="true" + bootstrap="/path/to/bootstrap.php" + colors="false" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="true" + stopOnFailure="true" + syntaxCheck="false" + testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"> +<filter> + <blacklist> + <directory suffix=".php">/path/to/files</directory> + <file>/path/to/file</file> + <exclude> + <directory suffix=".php">/path/to/files</directory> + <file>/path/to/file</file> + </exclude> + </blacklist> + <whitelist> + <directory suffix=".php">/path/to/files</directory> + <file>/path/to/file</file> + <exclude> + <directory suffix=".php">/path/to/files</directory> + <file>/path/to/file</file> + </exclude> + </whitelist> +</filter> +</phpunit> \ No newline at end of file