add test for invoices API
This commit is contained in:
parent
05a7ab158b
commit
3003b41a88
@ -751,8 +751,8 @@ function updateInvoice($authentication,$invoice)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id.
|
||||
", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext);
|
||||
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id'].
|
||||
", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
@ -782,10 +782,13 @@ function updateInvoice($authentication,$invoice)
|
||||
|
||||
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)
|
||||
{
|
||||
$result=$object->validate($fuser);
|
||||
$result = $object->validate($fuser);
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
@ -798,7 +801,8 @@ function updateInvoice($authentication,$invoice)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,10 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
protected $soapclient;
|
||||
protected $socid;
|
||||
|
||||
protected $ns = 'http://www.dolibarr.org/ns/';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -68,17 +72,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
$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.
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||
|
||||
|
||||
// Set the WebService URL
|
||||
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
||||
$this->soapclient = new nusoap_client($WS_DOL_URL);
|
||||
if ($this->soapclient)
|
||||
{
|
||||
$this->soapclient->soap_defencoding='UTF-8';
|
||||
$this->soapclient->decodeUTF8(false);
|
||||
}
|
||||
|
||||
// create a third_party, needed to create an invoice
|
||||
$societe=new Societe($db);
|
||||
@ -94,8 +98,20 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$societe->create($user);
|
||||
|
||||
print __METHOD__." societe created id=".$societe->id."\n";
|
||||
$this->socid = $societe->id;
|
||||
|
||||
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";
|
||||
}
|
||||
@ -148,23 +164,12 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||
$WS_METHOD = 'createInvoice';
|
||||
$ns='http://www.dolibarr.org/ns/';
|
||||
|
||||
// load societe first
|
||||
$societe=new Societe($db);
|
||||
$societe->fetch('', '', '209');
|
||||
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 (
|
||||
@ -191,11 +196,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
"close_note" => NULL,
|
||||
"project_id" => NULL,
|
||||
"lines" => array(
|
||||
"id" => NULL,
|
||||
array("id" => NULL,
|
||||
"type" => 0,
|
||||
"desc" => "Horloge Vinyle Serge",
|
||||
"vat_rate" => 20,
|
||||
"qty" => "1",
|
||||
"qty" => 1,
|
||||
"unitprice" => "30.000000",
|
||||
"total_net" => "30.000000",
|
||||
"total_vat" => "6.00",
|
||||
@ -206,7 +211,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
"product_id" => "",
|
||||
"product_ref" => "",
|
||||
"product_label" => "",
|
||||
"product_desc" => "" )
|
||||
"product_desc" => "" ))
|
||||
);
|
||||
|
||||
// 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);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||
}
|
||||
catch(SoapFault $exception)
|
||||
{
|
||||
@ -232,15 +237,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
if (! $result || ! empty($result['faultstring']))
|
||||
{
|
||||
//var_dump($soapclient);
|
||||
print $soapclient->error_str;
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->request;
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->response;
|
||||
print $this->soapclient->response;
|
||||
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('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
|
||||
*/
|
||||
public function testWSInvoicesGetInvoice()
|
||||
public function testWSInvoicesGetInvoiceByRefExt($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
@ -261,18 +268,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||
$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.
|
||||
$authentication=array(
|
||||
@ -287,7 +283,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
$parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||
}
|
||||
catch(SoapFault $exception)
|
||||
{
|
||||
@ -296,29 +292,30 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring']))
|
||||
{
|
||||
//var_dump($soapclient);
|
||||
print $soapclient->error_str;
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->request;
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->response;
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
$this->assertEquals('165', $result['result']['invoice']->ref_ext);
|
||||
$this->assertEquals('165', $result['invoice']['ref_ext']);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSInvoicesUpdateInvoice
|
||||
* testWSInvoicesUpdateInvoiceByRefExt
|
||||
*
|
||||
* Update an invoice using ref_ext
|
||||
* @depends testWSInvoicesCreateInvoice
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function testWSInvoicesUpdateInvoice()
|
||||
public function testWSInvoicesUpdateInvoiceByRefExt($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
@ -326,61 +323,51 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||
$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
|
||||
$body = array (
|
||||
"id" => NULL,
|
||||
"ref" => NULL,
|
||||
"ref_ext" => "165",
|
||||
"thirdparty_id" => "209",
|
||||
"fk_user_author" => NULL,
|
||||
"fk_user_valid" => NULL,
|
||||
"date" => "2015-04-19 20:16:53",
|
||||
"date_due" => "",
|
||||
"date_creation" => "",
|
||||
"date_validation" => "",
|
||||
"date_modification" => "",
|
||||
"type" => "",
|
||||
"total_net" => "36.30",
|
||||
$body = array (
|
||||
"id" => NULL,
|
||||
"ref" => NULL,
|
||||
"ref_ext" => "165",
|
||||
"thirdparty_id" => "209",
|
||||
"fk_user_author" => NULL,
|
||||
"fk_user_valid" => NULL,
|
||||
"date" => "2015-04-19 20:16:53",
|
||||
"date_due" => "",
|
||||
"date_creation" => "",
|
||||
"date_validation" => "",
|
||||
"date_modification" => "",
|
||||
"type" => "",
|
||||
"total_net" => "36.30",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "42.30",
|
||||
"payment_mode_id" => 50,
|
||||
"note_private" => "Synchronised from Prestashop",
|
||||
"note_public" => "",
|
||||
"status" => "2",
|
||||
"close_code" => NULL ,
|
||||
"close_note" => NULL,
|
||||
"project_id" => NULL,
|
||||
"lines" => array(
|
||||
array(
|
||||
"id" => NULL,
|
||||
"type" => 0,
|
||||
"desc" => "Horloge Vinyle Serge",
|
||||
"vat_rate" => 20,
|
||||
"qty" => "1",
|
||||
"unitprice" => "30.000000",
|
||||
"total_net" => "30.000000",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "42.30",
|
||||
"payment_mode_id" => 50,
|
||||
"note_private" => "Synchronised from Prestashop",
|
||||
"note_public" => "",
|
||||
"status" => "2",
|
||||
"close_code" => NULL ,
|
||||
"close_note" => NULL,
|
||||
"project_id" => NULL,
|
||||
"lines" => array(
|
||||
"id" => NULL,
|
||||
"type" => 0,
|
||||
"desc" => "Horloge Vinyle Serge",
|
||||
"vat_rate" => 20,
|
||||
"qty" => "1",
|
||||
"unitprice" => "30.000000",
|
||||
"total_net" => "30.000000",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "36.000000",
|
||||
"date_start" => "",
|
||||
"date_end" => "",
|
||||
"payment_mode_id" => "",
|
||||
"product_id" => "",
|
||||
"product_ref" => "",
|
||||
"product_label" => "",
|
||||
"product_desc" => "" )
|
||||
);
|
||||
"total" => "36.000000",
|
||||
"date_start" => "",
|
||||
"date_end" => "",
|
||||
"payment_mode_id" => "",
|
||||
"product_id" => "",
|
||||
"product_ref" => "",
|
||||
"product_label" => "",
|
||||
"product_desc" => "" ))
|
||||
);
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
@ -395,7 +382,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
$parameters = array('authentication'=>$authentication,'invoice'=>$body);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||
}
|
||||
catch(SoapFault $exception)
|
||||
{
|
||||
@ -404,18 +391,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring']))
|
||||
{
|
||||
//var_dump($soapclient);
|
||||
print $soapclient->error_str;
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->request;
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->response;
|
||||
print $this->soapclient->response;
|
||||
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('2', $result['result']['invoice']->status);
|
||||
$this->assertEquals('165', $result['ref_ext']);
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user