mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
New: Add phpunit tests
This commit is contained in:
parent
584a4919ea
commit
0e5b5b9946
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,42 @@
|
|||
<?php
|
||||
global $conf,$user,$langs,$db;
|
||||
require_once 'PHPUnit/Framework.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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
30
test/phpunit.xml
Normal file
30
test/phpunit.xml
Normal file
|
|
@ -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>
|
||||
Loading…
Reference in New Issue
Block a user