diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index d5e25d89661..c9296124a1f 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -217,6 +217,7 @@ class Product extends CommonObject
// Clean parameters
$this->ref = dol_string_nospecial(trim($this->ref));
$this->libelle = trim($this->libelle);
+ if (empty($this->type)) $this->type=0;
$this->price_ttc=price2num($this->price_ttc);
$this->price=price2num($this->price);
$this->price_min_ttc=price2num($this->price_min_ttc);
@@ -267,7 +268,7 @@ class Product extends CommonObject
// Check parameters
if (empty($this->libelle))
{
- $this->error='ErrorWrongParameters';
+ $this->error='ErrorMandatoryParametersNotProvided';
return -1;
}
if (empty($this->ref))
@@ -1260,7 +1261,7 @@ class Product extends CommonObject
* @param int $id Id of product/service to load
* @param string $ref Ref of product/service to load
* @param string $ref_ext Ref ext of product/service to load
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, 0 if not found, >0 if OK
*/
function fetch($id='',$ref='',$ref_ext='')
{
diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php
index dbbde72cb34..f2c418c8664 100644
--- a/htdocs/webservices/server_productorservice.php
+++ b/htdocs/webservices/server_productorservice.php
@@ -14,6 +14,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
+ *
+ * Path to WSDL is: http://localhost/dolibarr/webservices/server_productorservice.php?wsdl
*/
/**
@@ -187,18 +189,6 @@ $server->wsdl->addComplexType(
)
);
-/*$server->wsdl->addComplexType(
- 'ProductsArray',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(
- array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:product[]')
- ),
- 'tns:product'
-);*/
$server->wsdl->addComplexType(
'ProductsArray2',
'complexType',
@@ -267,6 +257,20 @@ $server->register(
'WS to update a product or service'
);
+// Register WSDL
+$server->register(
+ 'deleteProductOrService',
+ // Entry values
+ array('authentication'=>'tns:authentication','listofid'=>'xsd:string'),
+ // Exit values
+ array('result'=>'tns:result','nbdeleted'=>'xsd:int'),
+ $ns,
+ $ns.'#deleteProductOrService',
+ $styledoc,
+ $styleuse,
+ 'WS to delete a product or service'
+);
+
// Register WSDL
$server->register(
'getListOfProductsOrServices',
@@ -412,7 +416,7 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang=''
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
-
+ //var_dump($objectresp);exit;
return $objectresp;
}
@@ -527,7 +531,7 @@ function createProductOrService($authentication,$product)
/**
- * Update an invoice
+ * Update a product or service
*
* @param array $authentication Array of authentication information
* @param Product $product Product
@@ -637,6 +641,103 @@ function updateProductOrService($authentication,$product)
}
+/**
+ * Delete a product or service
+ *
+ * @param array $authentication Array of authentication information
+ * @param string $listofidstring List of id with comma
+ * @return array Array result
+ */
+function deleteProductOrService($authentication,$listofidstring)
+{
+ global $db,$conf,$langs;
+
+ $now=dol_now();
+
+ dol_syslog("Function: deleteProductOrService login=".$authentication['login']);
+
+ if ($authentication['entity']) $conf->entity=$authentication['entity'];
+
+ // Init and check authentication
+ $objectresp=array();
+ $errorcode='';$errorlabel='';
+ $error=0;
+ $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
+
+ // User must be defined to user authenticated
+ global $user;
+ $user=$fuser;
+
+ $listofid=explode(',',trim($listofidstring));
+ $listofiddeleted=array();
+
+ // Check parameters
+ if (count($listofid) == 0 || empty($listofid[0]))
+ {
+ $error++; $errorcode='KO'; $errorlabel="List of Id of products or services to delete are required.";
+ }
+
+ if (! $error)
+ {
+ $firsterror='';
+
+ $db->begin();
+
+ foreach($listofid as $key => $id)
+ {
+ $newobject=new Product($db);
+ $result=$newobject->fetch($id);
+
+ if ($result == 0)
+ {
+ $error++;
+ $firsterror='Product or service with id '.$id.' not found';
+ break;
+ }
+ else
+ {
+ $result=$newobject->delete();
+ if ($result <= 0)
+ {
+ $error++;
+ $firsterror=$newobject->error;
+ break;
+ }
+
+ $listofiddeleted[]=$id;
+ }
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ //$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'listofid'=>$listofiddeleted);
+ $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'nbdeleted'=>count($listofiddeleted));
+ }
+ else
+ {
+ $db->rollback();
+ $error++;
+ $errorcode='KO';
+ $errorlabel=$firsterror;
+ }
+ }
+
+ if ($error)
+ {
+ //$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'listofid'=>$listofiddeleted);
+ $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'nbdeleted'=>0);
+ }
+ else if (count($listofiddeleted) == 0)
+ {
+ //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted);
+ $objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'nbdeleted'=>0);
+ }
+
+ return $objectresp;
+}
+
+
/**
* getListOfProductsOrServices
*
diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php
index 35c89a5dc3a..66b434ce6b7 100644
--- a/test/phpunit/AllTests.php
+++ b/test/phpunit/AllTests.php
@@ -156,6 +156,8 @@ class AllTests
require_once dirname(__FILE__).'/CategorieTest.php';
$suite->addTestSuite('CategorieTest');
+ require_once dirname(__FILE__).'/WebservicesProductsTest.php';
+ $suite->addTestSuite('WebservicesProductsTest');
require_once dirname(__FILE__).'/WebservicesInvoicesTest.php';
$suite->addTestSuite('WebservicesInvoicesTest');
require_once dirname(__FILE__).'/WebservicesOrdersTest.php';
diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php
index 1f619beae6b..a8c6a36842a 100755
--- a/test/phpunit/WebservicesInvoicesTest.php
+++ b/test/phpunit/WebservicesInvoicesTest.php
@@ -131,7 +131,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
- $WS_METHOD = '';
+ $WS_METHOD = 'getInvoice';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
@@ -153,24 +153,29 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
// Test URL
$result='';
- if ($WS_METHOD)
- {
- $parameters = array('authentication'=>$authentication);
- print __METHOD__." call method ".$WS_METHOD."\n";
+ $parameters = array('authentication'=>$authentication,'id'=>1);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
- if (! $result)
- {
- //var_dump($soapclient);
- print $soapclient->error_str;
- print "
\n\n";
- print $soapclient->request;
- print "
\n\n";
- print $soapclient->response;
- }
-
- print __METHOD__." result=".$result."\n";
- $this->assertEquals('OK',$result['result']['result_code']);
}
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']))
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
return $result;
}
diff --git a/test/phpunit/WebservicesOrdersTest.php b/test/phpunit/WebservicesOrdersTest.php
index e1ecca1371e..be83927431a 100755
--- a/test/phpunit/WebservicesOrdersTest.php
+++ b/test/phpunit/WebservicesOrdersTest.php
@@ -118,11 +118,11 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
/**
- * testWSOrderXxx
+ * testWSOrderGetOrder
*
* @return int
*/
- public function testWSOrderXxx()
+ public function testWSOrderGetOrder()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
@@ -131,7 +131,7 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
$db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_order.php';
- $WS_METHOD = '';
+ $WS_METHOD = 'getOrder';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
@@ -152,24 +152,29 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
'entity'=>'');
// Test URL
- if ($WS_METHOD)
- {
- $parameters = array('authentication'=>$authentication);
- print __METHOD__." call method ".$WS_METHOD."\n";
+ $parameters = array('authentication'=>$authentication,'id'=>1);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
- if (! $result)
- {
- //var_dump($soapclient);
- print $soapclient->error_str;
- print "
\n\n";
- print $soapclient->request;
- print "
\n\n";
- print $soapclient->response;
- }
-
- print __METHOD__." result=".$result."\n";
- $this->assertEquals('OK',$result['result']['result_code']);
}
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']))
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
return $result;
}
diff --git a/test/phpunit/WebservicesOtherTest.php b/test/phpunit/WebservicesOtherTest.php
index 005e3e9114e..6ba1f8891da 100755
--- a/test/phpunit/WebservicesOtherTest.php
+++ b/test/phpunit/WebservicesOtherTest.php
@@ -153,24 +153,61 @@ class WebservicesOtherTest extends PHPUnit_Framework_TestCase
// Test URL
$result='';
- if ($WS_METHOD)
- {
- $parameters = array('authentication'=>$authentication);
- print __METHOD__." call method ".$WS_METHOD."\n";
+ $parameters = array('authentication'=>$authentication);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
- if (! $result)
- {
- //var_dump($soapclient);
- print $soapclient->error_str;
- print "
\n\n";
- print $soapclient->request;
- print "
\n\n";
- print $soapclient->response;
- }
-
- print __METHOD__." result=".$result."\n";
- $this->assertEquals('OK',$result['result']['result_code']);
}
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! empty($result['faultstring']))
+ {
+ print $result['faultstring']."\n";
+ $result=0;
+ }
+ if (! $result)
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+
+ // Test method that does not exists
+ $WS_METHOD='methodthatdoesnotexists';
+ $result='';
+ $parameters = array('authentication'=>$authentication);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
+ }
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']))
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals("SOAP-ENV:Client: Operation 'methodthatdoesnotexists' is not defined in the WSDL for this service", $soapclient->error_str);
return $result;
}
diff --git a/test/phpunit/WebservicesProducts.php b/test/phpunit/WebservicesProducts.php
new file mode 100755
index 00000000000..ca7ad463743
--- /dev/null
+++ b/test/phpunit/WebservicesProducts.php
@@ -0,0 +1,322 @@
+
+ *
+ * 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 3 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, see .
+ * or see http://www.gnu.org/
+ *
+ * Path to WSDL is: http://localhost/dolibarr/webservices/server_productorservice.php?wsdl
+ */
+
+/**
+ * \file test/phpunit/WebservicesProductsTest.php
+ * \ingroup test
+ * \brief PHPUnit test
+ * \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/Autoload.php';
+require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
+require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
+require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP
+
+
+if (empty($user->id))
+{
+ print "Load permissions for admin user nb 1\n";
+ $user->fetch(1);
+ $user->getrights();
+}
+$conf->global->MAIN_DISABLE_ALL_MAILS=1;
+
+
+/**
+ * Class for PHPUnit tests
+ *
+ * @backupGlobals disabled
+ * @backupStaticAttributes enabled
+ * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
+ */
+class WebservicesProductsTest extends PHPUnit_Framework_TestCase
+{
+ protected $savconf;
+ protected $savuser;
+ protected $savlangs;
+ protected $savdb;
+
+ /**
+ * Constructor
+ * We save global variables into local variables
+ *
+ * @return DateLibTest
+ */
+ function __construct()
+ {
+ //$this->sharedFixture
+ global $conf,$user,$langs,$db;
+ $this->savconf=$conf;
+ $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.
+
+ print __METHOD__."\n";
+ }
+ public static function tearDownAfterClass()
+ {
+ global $conf,$user,$langs,$db;
+ $db->rollback();
+
+ print __METHOD__."\n";
+ }
+
+ /**
+ * Init phpunit tests
+ *
+ * @return void
+ */
+ protected function setUp()
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+
+ print __METHOD__."\n";
+ }
+
+ /**
+ * End phpunit tests
+ *
+ * @return void
+ */
+ protected function tearDown()
+ {
+ print __METHOD__."\n";
+ }
+
+
+ /**
+ * testWSProductsCreateProductOrService
+ *
+ * @return int
+ */
+ public function testWSProductsCreateProductOrService()
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+
+ $datestring=dol_print_date(dol_now(),'dayhourlog');
+
+ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
+ $WS_METHOD = 'createProductOrService';
+ $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(
+ 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+ 'sourceapplication'=>'DEMO',
+ 'login'=>'admin',
+ 'password'=>'admin',
+ 'entity'=>'');
+
+ // Test URL
+ $result='';
+ $parameters = array('authentication'=>$authentication,'product'=>array(
+ 'ref'=>'NewProductFromWS'.$datestring,
+ 'label'=>'New Product From WS '.$datestring,
+ 'type'=>1,
+ 'description'=>'This is a new product created from WS PHPUnit test case'));
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
+ }
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']) || $result['result']['result_code'] != 'OK')
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+
+ return $result['id'];
+ }
+
+ /**
+ * testWSProductsGetProductOrService
+ *
+ * @return int
+ *
+ * @depends testWSProductsCreateProductOrService
+ */
+ public function testWSProductsGetProductOrService($id)
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+
+ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
+ $WS_METHOD = 'getProductOrService';
+ $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(
+ 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+ 'sourceapplication'=>'DEMO',
+ 'login'=>'admin',
+ 'password'=>'admin',
+ 'entity'=>'');
+
+ // Test URL
+ $result='';
+ $parameters = array('authentication'=>$authentication,'id'=>$id,'ref'=>'');
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
+ }
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']))
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+
+ return $id;
+ }
+
+ /**
+ * testWSProductsDeleteProductOrService
+ *
+ * @return int
+ *
+ * @depends testWSProductsGetProductOrService
+ */
+ public function testWSProductsDeleteProductOrService($id)
+ {
+ global $conf,$user,$langs,$db;
+ $conf=$this->savconf;
+ $user=$this->savuser;
+ $langs=$this->savlangs;
+ $db=$this->savdb;
+
+ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
+ $WS_METHOD = 'deleteProductOrService';
+ $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(
+ 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+ 'sourceapplication'=>'DEMO',
+ 'login'=>'admin',
+ 'password'=>'admin',
+ 'entity'=>'');
+
+ // Test URL
+ $result='';
+ $parameters = array('authentication'=>$authentication,'listofid'=>$id);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
+ $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
+ }
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']) || $result['result']['result_code'] != 'OK')
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
+
+ return 0;
+ }
+
+}
+?>
\ No newline at end of file
diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php
index 84c433f9716..100752e9f72 100755
--- a/test/phpunit/WebservicesThirdpartyTest.php
+++ b/test/phpunit/WebservicesThirdpartyTest.php
@@ -118,11 +118,11 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
/**
- * testWSThirdpartyXxx
+ * testWSThirdpartygetThirdParty
*
* @return int
*/
- public function testWSThirdpartyXxx()
+ public function testWSThirdpartygetThirdParty()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
@@ -131,7 +131,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
$db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
- $WS_METHOD = '';
+ $WS_METHOD = 'getThirdParty';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
@@ -153,24 +153,29 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
// Test URL
$result='';
- if ($WS_METHOD)
- {
- $parameters = array('authentication'=>$authentication);
- print __METHOD__." call method ".$WS_METHOD."\n";
+ $parameters = array('authentication'=>$authentication);
+ print __METHOD__." call method ".$WS_METHOD."\n";
+ try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
- if (! $result)
- {
- //var_dump($soapclient);
- print $soapclient->error_str;
- print "
\n\n";
- print $soapclient->request;
- print "
\n\n";
- print $soapclient->response;
- }
-
- print __METHOD__." result=".$result."\n";
- //$this->assertEquals('OK',$result['result']['result_code']);
}
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']))
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('OK',$result['result']['result_code']);
return $result;
}
diff --git a/test/phpunit/WebservicesUserTest.php b/test/phpunit/WebservicesUserTest.php
index ee8cb68aee6..b90e9a377e5 100755
--- a/test/phpunit/WebservicesUserTest.php
+++ b/test/phpunit/WebservicesUserTest.php
@@ -118,11 +118,11 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase
/**
- * testWSUserXxx
+ * testWSUserGetUser
*
* @return int
*/
- public function testWSUserXxx()
+ public function testWSUserGetUser()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
@@ -130,8 +130,8 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs;
$db=$this->savdb;
- $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_other.php';
- $WS_METHOD = 'xxx';
+ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_user.php';
+ $WS_METHOD = 'getUser';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
@@ -152,25 +152,61 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase
'entity'=>'');
// Test URL
- if ($WS_METHOD)
- {
- $parameters = array('authentication'=>$authentication);
- print __METHOD__."Call method ".$WS_METHOD."\n";
+ $result='';
+ $parameters = array('authentication'=>$authentication,'ref'=>'admin');
+ print __METHOD__."Call method ".$WS_METHOD."\n";
+ try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
- if (! $result)
- {
- //var_dump($soapclient);
- print $soapclient->error_str;
- print "
\n\n";
- print $soapclient->request;
- print "
\n\n";
- print $soapclient->response;
- exit;
- }
+ }
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! empty($result['faultstring']))
+ {
+ print $result['faultstring']."\n";
+ $result=0;
+ }
+ if (! $result)
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
}
print __METHOD__." result=".$result."\n";
- //$this->assertEquals('OK',$result['result']['result_code']);
+ $this->assertEquals('OK',$result['result']['result_code']);
+
+ // Test URL
+ $result='';
+ $parameters = array('authentication'=>$authentication,'ref'=>'refthatdoesnotexists');
+ print __METHOD__."Call method ".$WS_METHOD."\n";
+ try {
+ $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
+ }
+ catch(SoapFault $exception)
+ {
+ echo $exception;
+ $result=0;
+ }
+ if (! $result || ! empty($result['faultstring']))
+ {
+ //var_dump($soapclient);
+ print $soapclient->error_str;
+ print "\n
\n";
+ print $soapclient->request;
+ print "\n
\n";
+ print $soapclient->response;
+ print "\n";
+ }
+
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('NOT_FOUND',$result['result']['result_code']);
return $result;
}