Skip to content

Commit

Permalink
Qual: Show skeletons to add phpunit for webservices
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 1, 2013
1 parent f464b7b commit eff6757
Show file tree
Hide file tree
Showing 6 changed files with 963 additions and 63 deletions.
13 changes: 11 additions & 2 deletions test/phpunit/AllTests.php
Expand Up @@ -141,8 +141,17 @@ public static function suite()
require_once dirname(__FILE__).'/CategorieTest.php';
$suite->addTestSuite('CategorieTest');

require_once dirname(__FILE__).'/WebservicesTest.php';
$suite->addTestSuite('WebservicesTest');
require_once dirname(__FILE__).'/WebservicesInvoices.php';
$suite->addTestSuite('WebservicesInvoices');
require_once dirname(__FILE__).'/WebservicesOrders.php';
$suite->addTestSuite('WebservicesOrders');
require_once dirname(__FILE__).'/WebservicesOther.php';
$suite->addTestSuite('WebservicesOther');
require_once dirname(__FILE__).'/WebservicesThirparty.php';
$suite->addTestSuite('WebservicesThirdparty');
require_once dirname(__FILE__).'/WebservicesUserTest.php';
$suite->addTestSuite('WebservicesUserTest');

require_once dirname(__FILE__).'/ExportTest.php';
$suite->addTestSuite('ExportTest');
require_once dirname(__FILE__).'/ImportTest.php';
Expand Down
Expand Up @@ -47,7 +47,7 @@
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class WebservicesTest extends PHPUnit_Framework_TestCase
class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
{
protected $savconf;
protected $savuser;
Expand Down Expand Up @@ -116,67 +116,64 @@ protected function tearDown()
print __METHOD__."\n";
}

/**
* testWSVersion
*
* @return int
*/
public function testWSGetVersions()
{
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_other.php';
//$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
$WS_METHOD = 'getVersions';
$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
if ($WS_METHOD)
{
$parameters = array('authentication'=>$authentication);
print __METHOD__."Call method ".$WS_METHOD."\n";
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
if (! $result)
{
//var_dump($soapclient);
//print_r($soapclient);
print $soapclient->error_str;
print "<br>\n\n";
print $soapclient->request;
print "<br>\n\n";
print $soapclient->response;
exit;
}
}

print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']);

return $result;

/**
* testWSInvoices_xxx
*
* @return int
*/
public function testWSInvoices_xxx()
{
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_invoice.php';
$WS_METHOD = 'xxx';
$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
if ($WS_METHOD)
{
$parameters = array('authentication'=>$authentication);
print __METHOD__."Call method ".$WS_METHOD."\n";
$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;
exit;
}
}

print __METHOD__." result=".$result."\n";
//$this->assertEquals('OK',$result['result']['result_code']);

return $result;
}


}
?>

0 comments on commit eff6757

Please sign in to comment.