add test for invoices API

This commit is contained in:
Arnaud Aujon 2015-05-28 16:57:28 +02:00
parent 05a7ab158b
commit 3003b41a88
2 changed files with 108 additions and 118 deletions

View File

@ -751,8 +751,8 @@ function updateInvoice($authentication,$invoice)
{ {
global $db,$conf,$langs; global $db,$conf,$langs;
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id. dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id'].
", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); ", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']);
if ($authentication['entity']) $conf->entity=$authentication['entity']; if ($authentication['entity']) $conf->entity=$authentication['entity'];
@ -782,7 +782,10 @@ function updateInvoice($authentication,$invoice)
if (isset($invoice['status'])) if (isset($invoice['status']))
{ {
if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); if ($invoice['status'] == Facture::STATUS_DRAFT)
{
$result = $object->set_draft($fuser);
}
if ($invoice['status'] == Facture::STATUS_VALIDATED) if ($invoice['status'] == Facture::STATUS_VALIDATED)
{ {
$result = $object->validate($fuser); $result = $object->validate($fuser);
@ -798,7 +801,8 @@ function updateInvoice($authentication,$invoice)
{ {
$result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note);
} }
if ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); if ($invoice['status'] == Facture::STATUS_ABANDONED)
$result = $object->set_canceled($fuser,$invoice->close_code,$invoice->close_note);
} }
} }

View File

@ -53,6 +53,10 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
protected $savuser; protected $savuser;
protected $savlangs; protected $savlangs;
protected $savdb; protected $savdb;
protected $soapclient;
protected $socid;
protected $ns = 'http://www.dolibarr.org/ns/';
/** /**
* Constructor * Constructor
@ -68,17 +72,17 @@ 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';
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
// Static methods // Set the WebService URL
public static function setUpBeforeClass() print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
$this->soapclient = new nusoap_client($WS_DOL_URL);
if ($this->soapclient)
{ {
global $conf,$user,$langs,$db; $this->soapclient->soap_defencoding='UTF-8';
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. $this->soapclient->decodeUTF8(false);
}
// create a third_party, needed to create an invoice // create a third_party, needed to create an invoice
$societe=new Societe($db); $societe=new Societe($db);
@ -94,8 +98,20 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$societe->create($user); $societe->create($user);
$this->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.
print __METHOD__."\n"; print __METHOD__."\n";
} }
@ -148,24 +164,13 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs; $langs=$this->savlangs;
$db=$this->savdb; $db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
$WS_METHOD = 'createInvoice'; $WS_METHOD = 'createInvoice';
$ns='http://www.dolibarr.org/ns/';
// load societe first // load societe first
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch('', '', '209'); $societe->fetch('', '', '209');
print __METHOD__." societe loaded id=".$societe->id."\n"; print __METHOD__." societe loaded id=".$societe->id."\n";
// Set the WebService URL
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
$soapclient = new nusoap_client($WS_DOL_URL);
if ($soapclient)
{
$soapclient->soap_defencoding='UTF-8';
$soapclient->decodeUTF8(false);
}
$body = array ( $body = array (
"id" => NULL, "id" => NULL,
@ -191,11 +196,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
"close_note" => NULL, "close_note" => NULL,
"project_id" => NULL, "project_id" => NULL,
"lines" => array( "lines" => array(
"id" => NULL, array("id" => NULL,
"type" => 0, "type" => 0,
"desc" => "Horloge Vinyle Serge", "desc" => "Horloge Vinyle Serge",
"vat_rate" => 20, "vat_rate" => 20,
"qty" => "1", "qty" => 1,
"unitprice" => "30.000000", "unitprice" => "30.000000",
"total_net" => "30.000000", "total_net" => "30.000000",
"total_vat" => "6.00", "total_vat" => "6.00",
@ -206,7 +211,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
"product_id" => "", "product_id" => "",
"product_ref" => "", "product_ref" => "",
"product_label" => "", "product_label" => "",
"product_desc" => "" ) "product_desc" => "" ))
); );
// Call the WebService method and store its result in $result. // Call the WebService method and store its result in $result.
@ -222,7 +227,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$parameters = array('authentication'=>$authentication,'invoice'=>$body); $parameters = array('authentication'=>$authentication,'invoice'=>$body);
print __METHOD__." call method ".$WS_METHOD."\n"; print __METHOD__." call method ".$WS_METHOD."\n";
try { try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
} }
catch(SoapFault $exception) catch(SoapFault $exception)
{ {
@ -232,15 +237,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
if (! $result || ! empty($result['faultstring'])) if (! $result || ! empty($result['faultstring']))
{ {
//var_dump($soapclient); //var_dump($soapclient);
print $soapclient->error_str; print $this->soapclient->error_str;
print "\n<br>\n"; print "\n<br>\n";
print $soapclient->request; print $this->soapclient->request;
print "\n<br>\n"; print "\n<br>\n";
print $soapclient->response; print $this->soapclient->response;
print "\n"; print "\n";
} }
print __METHOD__." result=".$result['result']['result_label']."\n"; print __METHOD__." result=".$result['result']['result_code']."\n";
$this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('OK',$result['result']['result_code']);
$this->assertEquals('165', $result['ref_ext']); $this->assertEquals('165', $result['ref_ext']);
@ -249,11 +254,13 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
} }
/** /**
* testWSInvoicesGetInvoice * testWSInvoicesGetInvoiceByRefExt
* *
* Retrieve an invoice using ref_ext
* @depends testWSInvoicesCreateInvoice
* @return int * @return int
*/ */
public function testWSInvoicesGetInvoice() public function testWSInvoicesGetInvoiceByRefExt($result)
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -261,18 +268,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs; $langs=$this->savlangs;
$db=$this->savdb; $db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
$WS_METHOD = 'getInvoice'; $WS_METHOD = 'getInvoice';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
$soapclient = new nusoap_client($WS_DOL_URL);
if ($soapclient)
{
$soapclient->soap_defencoding='UTF-8';
$soapclient->decodeUTF8(false);
}
// Call the WebService method and store its result in $result. // Call the WebService method and store its result in $result.
$authentication=array( $authentication=array(
@ -287,7 +283,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165);
print __METHOD__." call method ".$WS_METHOD."\n"; print __METHOD__." call method ".$WS_METHOD."\n";
try { try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
} }
catch(SoapFault $exception) catch(SoapFault $exception)
{ {
@ -296,29 +292,30 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
} }
if (! $result || ! empty($result['faultstring'])) if (! $result || ! empty($result['faultstring']))
{ {
//var_dump($soapclient); print $this->soapclient->error_str;
print $soapclient->error_str;
print "\n<br>\n"; print "\n<br>\n";
print $soapclient->request; print $this->soapclient->request;
print "\n<br>\n"; print "\n<br>\n";
print $soapclient->response; print $this->soapclient->response;
print "\n"; print "\n";
} }
print __METHOD__." result=".$result['result']['result_code']."\n";
print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('OK',$result['result']['result_code']);
$this->assertEquals('165', $result['result']['invoice']->ref_ext); $this->assertEquals('165', $result['invoice']['ref_ext']);
return $result; return $result;
} }
/** /**
* testWSInvoicesUpdateInvoice * testWSInvoicesUpdateInvoiceByRefExt
*
* Update an invoice using ref_ext
* @depends testWSInvoicesCreateInvoice
* *
* @return int * @return int
*/ */
public function testWSInvoicesUpdateInvoice() public function testWSInvoicesUpdateInvoiceByRefExt($result)
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -326,18 +323,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs; $langs=$this->savlangs;
$db=$this->savdb; $db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
$WS_METHOD = 'updateInvoice'; $WS_METHOD = 'updateInvoice';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
$soapclient = new nusoap_client($WS_DOL_URL);
if ($soapclient)
{
$soapclient->soap_defencoding='UTF-8';
$soapclient->decodeUTF8(false);
}
// update status to 2 // update status to 2
$body = array ( $body = array (
@ -364,6 +350,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
"close_note" => NULL, "close_note" => NULL,
"project_id" => NULL, "project_id" => NULL,
"lines" => array( "lines" => array(
array(
"id" => NULL, "id" => NULL,
"type" => 0, "type" => 0,
"desc" => "Horloge Vinyle Serge", "desc" => "Horloge Vinyle Serge",
@ -379,7 +366,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
"product_id" => "", "product_id" => "",
"product_ref" => "", "product_ref" => "",
"product_label" => "", "product_label" => "",
"product_desc" => "" ) "product_desc" => "" ))
); );
// Call the WebService method and store its result in $result. // Call the WebService method and store its result in $result.
@ -395,7 +382,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$parameters = array('authentication'=>$authentication,'invoice'=>$body); $parameters = array('authentication'=>$authentication,'invoice'=>$body);
print __METHOD__." call method ".$WS_METHOD."\n"; print __METHOD__." call method ".$WS_METHOD."\n";
try { try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
} }
catch(SoapFault $exception) catch(SoapFault $exception)
{ {
@ -404,18 +391,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
} }
if (! $result || ! empty($result['faultstring'])) if (! $result || ! empty($result['faultstring']))
{ {
//var_dump($soapclient); print $this->soapclient->error_str;
print $soapclient->error_str;
print "\n<br>\n"; print "\n<br>\n";
print $soapclient->request; print $this->soapclient->request;
print "\n<br>\n"; print "\n<br>\n";
print $soapclient->response; print $this->soapclient->response;
print "\n"; print "\n";
} }
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n";
$this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('OK',$result['result']['result_code']);
$this->assertEquals('2', $result['result']['invoice']->status); $this->assertEquals('165', $result['ref_ext']);
return $result; return $result;