New: Add webservcie to delete a product.

Qual: More webservices in phpunit.
This commit is contained in:
Laurent Destailleur 2014-05-02 16:47:54 +02:00
parent 487c610f5a
commit f5b0651809
9 changed files with 620 additions and 106 deletions

View File

@ -217,6 +217,7 @@ class Product extends CommonObject
// Clean parameters // Clean parameters
$this->ref = dol_string_nospecial(trim($this->ref)); $this->ref = dol_string_nospecial(trim($this->ref));
$this->libelle = trim($this->libelle); $this->libelle = trim($this->libelle);
if (empty($this->type)) $this->type=0;
$this->price_ttc=price2num($this->price_ttc); $this->price_ttc=price2num($this->price_ttc);
$this->price=price2num($this->price); $this->price=price2num($this->price);
$this->price_min_ttc=price2num($this->price_min_ttc); $this->price_min_ttc=price2num($this->price_min_ttc);
@ -267,7 +268,7 @@ class Product extends CommonObject
// Check parameters // Check parameters
if (empty($this->libelle)) if (empty($this->libelle))
{ {
$this->error='ErrorWrongParameters'; $this->error='ErrorMandatoryParametersNotProvided';
return -1; return -1;
} }
if (empty($this->ref)) if (empty($this->ref))
@ -1260,7 +1261,7 @@ class Product extends CommonObject
* @param int $id Id of product/service to load * @param int $id Id of product/service to load
* @param string $ref Ref 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 * @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='') function fetch($id='',$ref='',$ref_ext='')
{ {

View File

@ -14,6 +14,8 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 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( $server->wsdl->addComplexType(
'ProductsArray2', 'ProductsArray2',
'complexType', 'complexType',
@ -267,6 +257,20 @@ $server->register(
'WS to update a product or service' '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 // Register WSDL
$server->register( $server->register(
'getListOfProductsOrServices', 'getListOfProductsOrServices',
@ -412,7 +416,7 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang=''
{ {
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
} }
//var_dump($objectresp);exit;
return $objectresp; 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 array $authentication Array of authentication information
* @param Product $product Product * @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 * getListOfProductsOrServices
* *

View File

@ -156,6 +156,8 @@ class AllTests
require_once dirname(__FILE__).'/CategorieTest.php'; require_once dirname(__FILE__).'/CategorieTest.php';
$suite->addTestSuite('CategorieTest'); $suite->addTestSuite('CategorieTest');
require_once dirname(__FILE__).'/WebservicesProductsTest.php';
$suite->addTestSuite('WebservicesProductsTest');
require_once dirname(__FILE__).'/WebservicesInvoicesTest.php'; require_once dirname(__FILE__).'/WebservicesInvoicesTest.php';
$suite->addTestSuite('WebservicesInvoicesTest'); $suite->addTestSuite('WebservicesInvoicesTest');
require_once dirname(__FILE__).'/WebservicesOrdersTest.php'; require_once dirname(__FILE__).'/WebservicesOrdersTest.php';

View File

@ -131,7 +131,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$db=$this->savdb; $db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
$WS_METHOD = ''; $WS_METHOD = 'getInvoice';
$ns='http://www.dolibarr.org/ns/'; $ns='http://www.dolibarr.org/ns/';
// Set the WebService URL // Set the WebService URL
@ -153,24 +153,29 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
// Test URL // Test URL
$result=''; $result='';
if ($WS_METHOD) $parameters = array('authentication'=>$authentication,'id'=>1);
{ print __METHOD__." call method ".$WS_METHOD."\n";
$parameters = array('authentication'=>$authentication); try {
print __METHOD__." call method ".$WS_METHOD."\n";
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
if (! $result)
{
//var_dump($soapclient);
print $soapclient->error_str;
print "<br>\n\n";
print $soapclient->request;
print "<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\n";
print $soapclient->response;
print "\n";
}
print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']);
return $result; return $result;
} }

View File

@ -118,11 +118,11 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
/** /**
* testWSOrderXxx * testWSOrderGetOrder
* *
* @return int * @return int
*/ */
public function testWSOrderXxx() public function testWSOrderGetOrder()
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -131,7 +131,7 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
$db=$this->savdb; $db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_order.php'; $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_order.php';
$WS_METHOD = ''; $WS_METHOD = 'getOrder';
$ns='http://www.dolibarr.org/ns/'; $ns='http://www.dolibarr.org/ns/';
// Set the WebService URL // Set the WebService URL
@ -152,24 +152,29 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
'entity'=>''); 'entity'=>'');
// Test URL // Test URL
if ($WS_METHOD) $parameters = array('authentication'=>$authentication,'id'=>1);
{ print __METHOD__." call method ".$WS_METHOD."\n";
$parameters = array('authentication'=>$authentication); try {
print __METHOD__." call method ".$WS_METHOD."\n";
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
if (! $result)
{
//var_dump($soapclient);
print $soapclient->error_str;
print "<br>\n\n";
print $soapclient->request;
print "<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\n";
print $soapclient->response;
print "\n";
}
print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']);
return $result; return $result;
} }

View File

@ -153,24 +153,61 @@ class WebservicesOtherTest extends PHPUnit_Framework_TestCase
// Test URL // Test URL
$result=''; $result='';
if ($WS_METHOD) $parameters = array('authentication'=>$authentication);
{ print __METHOD__." call method ".$WS_METHOD."\n";
$parameters = array('authentication'=>$authentication); try {
print __METHOD__." call method ".$WS_METHOD."\n";
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
if (! $result)
{
//var_dump($soapclient);
print $soapclient->error_str;
print "<br>\n\n";
print $soapclient->request;
print "<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\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; return $result;
} }

View File

@ -0,0 +1,322 @@
<?php
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <http://www.gnu.org/licenses/>.
* 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<br>\n";
print $soapclient->request;
print "\n<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\n";
print $soapclient->response;
print "\n";
}
print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']);
return 0;
}
}
?>

View File

@ -118,11 +118,11 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
/** /**
* testWSThirdpartyXxx * testWSThirdpartygetThirdParty
* *
* @return int * @return int
*/ */
public function testWSThirdpartyXxx() public function testWSThirdpartygetThirdParty()
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -131,7 +131,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
$db=$this->savdb; $db=$this->savdb;
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
$WS_METHOD = ''; $WS_METHOD = 'getThirdParty';
$ns='http://www.dolibarr.org/ns/'; $ns='http://www.dolibarr.org/ns/';
// Set the WebService URL // Set the WebService URL
@ -153,24 +153,29 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
// Test URL // Test URL
$result=''; $result='';
if ($WS_METHOD) $parameters = array('authentication'=>$authentication);
{ print __METHOD__." call method ".$WS_METHOD."\n";
$parameters = array('authentication'=>$authentication); try {
print __METHOD__." call method ".$WS_METHOD."\n";
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
if (! $result)
{
//var_dump($soapclient);
print $soapclient->error_str;
print "<br>\n\n";
print $soapclient->request;
print "<br>\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<br>\n";
print $soapclient->request;
print "\n<br>\n";
print $soapclient->response;
print "\n";
}
print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']);
return $result; return $result;
} }

View File

@ -118,11 +118,11 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase
/** /**
* testWSUserXxx * testWSUserGetUser
* *
* @return int * @return int
*/ */
public function testWSUserXxx() public function testWSUserGetUser()
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -130,8 +130,8 @@ class WebservicesUserTest 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_other.php'; $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_user.php';
$WS_METHOD = 'xxx'; $WS_METHOD = 'getUser';
$ns='http://www.dolibarr.org/ns/'; $ns='http://www.dolibarr.org/ns/';
// Set the WebService URL // Set the WebService URL
@ -152,25 +152,61 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase
'entity'=>''); 'entity'=>'');
// Test URL // Test URL
if ($WS_METHOD) $result='';
{ $parameters = array('authentication'=>$authentication,'ref'=>'admin');
$parameters = array('authentication'=>$authentication); print __METHOD__."Call method ".$WS_METHOD."\n";
print __METHOD__."Call method ".$WS_METHOD."\n"; try {
$result = $soapclient->call($WS_METHOD,$parameters,$ns,''); $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
if (! $result) }
{ catch(SoapFault $exception)
//var_dump($soapclient); {
print $soapclient->error_str; echo $exception;
print "<br>\n\n"; $result=0;
print $soapclient->request; }
print "<br>\n\n"; if (! empty($result['faultstring']))
print $soapclient->response; {
exit; print $result['faultstring']."\n";
} $result=0;
}
if (! $result)
{
//var_dump($soapclient);
print $soapclient->error_str;
print "\n<br>\n";
print $soapclient->request;
print "\n<br>\n";
print $soapclient->response;
print "\n";
} }
print __METHOD__." result=".$result."\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<br>\n";
print $soapclient->request;
print "\n<br>\n";
print $soapclient->response;
print "\n";
}
print __METHOD__." result=".$result."\n";
$this->assertEquals('NOT_FOUND',$result['result']['result_code']);
return $result; return $result;
} }