Merge pull request #5377 from EuskalMoneta/fix-failure-in-WebservicesInvoicesTest
Improve the code in WebservicesInvoicesTest.
This commit is contained in:
commit
abb808231f
@ -54,7 +54,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
protected $savlangs;
|
protected $savlangs;
|
||||||
protected $savdb;
|
protected $savdb;
|
||||||
protected $soapclient;
|
protected $soapclient;
|
||||||
protected $socid;
|
|
||||||
|
private static $socid;
|
||||||
|
|
||||||
protected $ns = 'http://www.dolibarr.org/ns/';
|
protected $ns = 'http://www.dolibarr.org/ns/';
|
||||||
|
|
||||||
@ -72,10 +73,9 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->savuser=$user;
|
$this->savuser=$user;
|
||||||
$this->savlangs=$langs;
|
$this->savlangs=$langs;
|
||||||
$this->savdb=$db;
|
$this->savdb=$db;
|
||||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
|
||||||
|
|
||||||
|
|
||||||
// Set the WebService URL
|
// Set the WebService URL
|
||||||
|
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||||
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
||||||
$this->soapclient = new nusoap_client($WS_DOL_URL);
|
$this->soapclient = new nusoap_client($WS_DOL_URL);
|
||||||
if ($this->soapclient)
|
if ($this->soapclient)
|
||||||
@ -84,7 +84,28 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->soapclient->decodeUTF8(false);
|
$this->soapclient->decodeUTF8(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create third_parties, needed to test an invoice
|
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||||
|
//print " - db ".$db->db;
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
|
||||||
|
// create a third_party, needed to create an invoice
|
||||||
|
//
|
||||||
|
// The third party is created in setUpBeforeClass() and not in the
|
||||||
|
// constructor to avoid creating several objects (the constructor is
|
||||||
|
// called for each test).
|
||||||
|
//
|
||||||
|
// The third party must be created before beginning the DB transaction
|
||||||
|
// because there is a foreign key constraint between invoices and third
|
||||||
|
// parties (tables: lx_facture and llx_societe) and with MySQL,
|
||||||
|
// constraints are checked immediately, they are not deferred to
|
||||||
|
// transaction commit. So if the invoice is created in the same
|
||||||
|
// transaction than the third party, the FK constraint fails.
|
||||||
|
// See this post for more detail: http://stackoverflow.com/a/5014744/5187108
|
||||||
$societe=new Societe($db);
|
$societe=new Societe($db);
|
||||||
$societe->ref='';
|
$societe->ref='';
|
||||||
$societe->name='name';
|
$societe->name='name';
|
||||||
@ -98,23 +119,14 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$societe->create($user);
|
$societe->create($user);
|
||||||
|
|
||||||
$this->socid = $societe->id;
|
self::$socid = $societe->id;
|
||||||
|
|
||||||
print __METHOD__." societe created id=".$societe->id."\n";
|
print __METHOD__." societe created id=".$societe->id."\n";
|
||||||
|
|
||||||
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.
|
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||||
|
|
||||||
print __METHOD__."\n";
|
print __METHOD__."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass()
|
public static function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
global $conf,$user,$langs,$db;
|
global $conf,$user,$langs,$db;
|
||||||
@ -137,7 +149,6 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
$db=$this->savdb;
|
$db=$this->savdb;
|
||||||
|
|
||||||
print __METHOD__."\n";
|
print __METHOD__."\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,17 +177,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$WS_METHOD = 'createInvoice';
|
$WS_METHOD = 'createInvoice';
|
||||||
|
|
||||||
// load societe first
|
|
||||||
/*$societe=new Societe($db);
|
|
||||||
$societe->fetch('', '', 'ref-phpunit');
|
|
||||||
print __METHOD__." societe loaded id=".$societe->id."\n";
|
|
||||||
*/
|
|
||||||
|
|
||||||
$body = array (
|
$body = array (
|
||||||
"id" => NULL,
|
"id" => NULL,
|
||||||
"ref" => NULL,
|
"ref" => NULL,
|
||||||
"ref_ext" => "ref-phpunit-2",
|
"ref_ext" => "ref-phpunit-2",
|
||||||
"thirdparty_id" => $this->socid,
|
"thirdparty_id" => self::$socid,
|
||||||
"fk_user_author" => NULL,
|
"fk_user_author" => NULL,
|
||||||
"fk_user_valid" => NULL,
|
"fk_user_valid" => NULL,
|
||||||
"date" => "2015-04-19 20:16:53",
|
"date" => "2015-04-19 20:16:53",
|
||||||
@ -333,7 +338,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
|||||||
"id" => NULL,
|
"id" => NULL,
|
||||||
"ref" => NULL,
|
"ref" => NULL,
|
||||||
"ref_ext" => "ref-phpunit-2",
|
"ref_ext" => "ref-phpunit-2",
|
||||||
"thirdparty_id" => $this->socid,
|
"thirdparty_id" => self::$socid,
|
||||||
"fk_user_author" => NULL,
|
"fk_user_author" => NULL,
|
||||||
"fk_user_valid" => NULL,
|
"fk_user_valid" => NULL,
|
||||||
"date" => "2015-04-19 20:16:53",
|
"date" => "2015-04-19 20:16:53",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user