diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php
index 0c99d7d362a..71c90b3f636 100755
--- a/test/phpunit/WebservicesThirdpartyTest.php
+++ b/test/phpunit/WebservicesThirdpartyTest.php
@@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
protected $savuser;
protected $savlangs;
protected $savdb;
+ protected $soapclient;
+
+ private $WS_DOL_URL;
+ private $ns='http://www.dolibarr.org/ns/';
+
+
+
/**
* Constructor
@@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
+
+ $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
+
+ // Set the WebService URL
+ print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n";
+ $this->soapclient = new nusoap_client($this->WS_DOL_URL);
+ if ($this->soapclient) {
+ $this->soapclient->soap_defencoding='UTF-8';
+ $this->soapclient->decodeUTF8(false);
+ }
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
@@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
print __METHOD__."\n";
}
-
/**
- * testWSThirdpartygetThirdParty
+ * testWSThirdpartycreateThirdParty
*
* @return int
*/
- public function testWSThirdpartygetThirdParty()
+ public function testWSThirdpartycreateThirdParty()
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+
+ $WS_METHOD = 'createThirdParty';
+
+
+ // Call the WebService method and store its result in $result.
+ $authentication=array(
+ 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+ 'sourceapplication'=>'DEMO',
+ 'login'=>'admin',
+ 'password'=>'admin',
+ 'entity'=>'');
+
+ $body = array (
+ "id" => NULL,
+ "ref" => "name",
+ "ref_ext" => "12",
+ "fk_user_author" => NULL,
+ "status" => NULL,
+ "client" => 1,
+ "supplier" => 0,
+ "customer_code" => "",
+ "supplier_code" => "",
+ "customer_code_accountancy" => "",
+ "supplier_code_accountancy" => "",
+ "date_creation" => "", // dateTime
+ "date_modification" => "", // dateTime
+ "note_private" => "",
+ "note_public" => "",
+ "address" => "",
+ "zip" => "",
+ "town" => "",
+ "province_id" => "",
+ "country_id" => "",
+ "country_code" => "",
+ "country" => "",
+ "phone" => "",
+ "fax" => "",
+ "email" => "",
+ "url" => "",
+ "profid1" => "",
+ "profid2" => "",
+ "profid3" => "",
+ "profid4" => "",
+ "profid5" => "",
+ "profid6" => "",
+ "capital" => "",
+ "vat_used" => "",
+ "vat_number" => ""
+ );
+
+ // Test URL
+ $result='';
+ $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,'');
+ } catch(SoapFault $exception) {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring'])) {
+ //var_dump($soapclient);
+ print $this->soapclient->error_str;
+ print "\n
\n";
+ print $this->soapclient->request;
+ print "\n
\n";
+ print $this->soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result['result']['result_code']."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+ $this->assertEquals('name',$result['ref']);
+
+ return $result;
+ }
+
+ /**
+ * testWSThirdpartygetThirdPartyById
+ *
+ * Use id to retrieve thirdparty
+ * @depends testWSThirdpartycreateThirdParty
+ *
+ * @return int
+ */
+ public function testWSThirdpartygetThirdPartyById($result)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
+ $id = $result['id'];
- $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
$WS_METHOD = 'getThirdParty';
- $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(
@@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
'password'=>'admin',
'entity'=>'');
- // Test URL
$result='';
- $parameters = array('authentication'=>$authentication, 'id'=>1);
+ $parameters = array('authentication'=>$authentication, 'id'=>$id);
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) {
echo $exception;
$result=0;
}
if (! $result || ! empty($result['faultstring'])) {
//var_dump($soapclient);
- print $soapclient->error_str;
+ print $this->soapclient->error_str;
print "\n
\n";
- print $soapclient->request;
+ print $this->soapclient->request;
print "\n
\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($id, $result['thirdparty']['id']);
+ $this->assertEquals('name', $result['thirdparty']['ref']);
+ $this->assertEquals('12', $result['thirdparty']['ref_ext']);
+ $this->assertEquals('0', $result['thirdparty']['status']);
+ $this->assertEquals('1', $result['thirdparty']['client']);
+ $this->assertEquals('0', $result['thirdparty']['supplier']);
+
+
return $result;
}
+
+ /**
+ * testWSThirdpartygetThirdPartyByRefExt
+ *
+ * Use ref_ext to retrieve thirdparty
+ *
+ * @depends testWSThirdpartycreateThirdParty
+ * @return int
+ */
+ public function testWSThirdpartygetThirdPartyByRefExt($result)
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+ $id = $result['id'];
+
+ $WS_METHOD = 'getThirdParty';
+
+ // Call the WebService method and store its result in $result.
+ $authentication=array(
+ 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+ 'sourceapplication'=>'DEMO',
+ 'login'=>'admin',
+ 'password'=>'admin',
+ 'entity'=>'');
+
+ // Test URL
+ $result='';
+ $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12');
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
+ } catch(SoapFault $exception) {
+ echo $exception;
+ $result=0;
+ }
+ print $this->soapclient->response;
+ if (! $result || ! empty($result['faultstring'])) {
+ //var_dump($soapclient);
+ print $this->soapclient->error_str;
+ print "\n
\n";
+ print $this->soapclient->request;
+ print "\n
\n";
+ print $this->soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result['result']['result_code']."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+ $this->assertEquals($id, $result['thirdparty']['id']);
+ $this->assertEquals('name', $result['thirdparty']['ref']);
+ $this->assertEquals('12', $result['thirdparty']['ref_ext']);
+ $this->assertEquals('0', $result['thirdparty']['status']);
+ $this->assertEquals('1', $result['thirdparty']['client']);
+ $this->assertEquals('0', $result['thirdparty']['supplier']);
+
+
+ return $result;
+ }
+
+ /**
+ * testWSThirdpartydeleteThirdParty
+ *
+ * @depends testWSThirdpartycreateThirdParty
+ *
+ * @return int
+ */
+ public function testWSThirdpartydeleteThirdPartyById($result)
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+ $id = $result['id'];
+
+ $WS_METHOD = 'deleteThirdParty';
+
+ // Call the WebService method and store its result in $result.
+ $authentication=array(
+ 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+ 'sourceapplication'=>'DEMO',
+ 'login'=>'admin',
+ 'password'=>'admin',
+ 'entity'=>'');
+
+ $result='';
+ $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>'');
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
+ } catch(SoapFault $exception) {
+ echo $exception;
+ $result=0;
+ }
+ //if (! $result || ! empty($result['faultstring'])) {
+ print $this->soapclient->error_str;
+ print "\n
\n";
+ print $this->soapclient->request;
+ print "\n
\n";
+ print $this->soapclient->response;
+ print "\n";
+ //}
+
+ print __METHOD__." result=".$result['result']['result_code']."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+
+ return $result;
+ }
}