From 8064659398c7c860ea121d1e42693d51aa89c9ad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Jun 2017 20:49:57 +0200 Subject: [PATCH] Fix phpunit --- test/phpunit/AdminLibTest.php | 14 ++++++++++---- test/phpunit/LangTest.php | 2 +- test/phpunit/RestAPIUserTest.php | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/test/phpunit/AdminLibTest.php b/test/phpunit/AdminLibTest.php index d7f3d17a583..7c9033fe2a6 100644 --- a/test/phpunit/AdminLibTest.php +++ b/test/phpunit/AdminLibTest.php @@ -142,21 +142,27 @@ class AdminLibTest extends PHPUnit_Framework_TestCase return $result; } - + /** * testEnableModule - * + * * @return void */ public function testEnableModule() { global $conf, $db, $langs, $user; - + require_once dirname(__FILE__).'/../../htdocs/core/modules/modExpenseReport.class.php'; print "Enable module modExpenseReport"; $moduledescriptor=new modExpenseReport($db); $moduledescriptor->init(); $conf->setValues($db); + + require_once dirname(__FILE__).'/../../htdocs/core/modules/modApi.class.php'; + print "Enable module modAPI"; + $moduledescriptor=new modApi($db); + $moduledescriptor->init(); + $conf->setValues($db); } - + } diff --git a/test/phpunit/LangTest.php b/test/phpunit/LangTest.php index 4487568c1d6..76c7a17d779 100644 --- a/test/phpunit/LangTest.php +++ b/test/phpunit/LangTest.php @@ -129,7 +129,7 @@ class LangTest extends PHPUnit_Framework_TestCase } /** - * testBank + * testLang * * @return string */ diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index a79739fef43..d38eb53c5b5 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -71,6 +71,8 @@ class RestAPIUserTest extends PHPUnit_Framework_TestCase $this->savlangs=$langs; $this->savdb=$db; + if (empty($conf->api->enabled)) { print __METHOD__." module api must be enabled.\n"; die(); } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; print "\n"; @@ -106,7 +108,7 @@ class RestAPIUserTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $this->api_url=DOL_MAIN_URL_ROOT.'/api/index.php'; $login='admin'; @@ -149,7 +151,7 @@ class RestAPIUserTest extends PHPUnit_Framework_TestCase $url = $this->api_url.'/users/123456789?api_key='.$this->api_key; //$addheaders=array('Content-Type: application/json'); - + print __METHOD__." Request GET url=".$url."\n"; $result=getURLContent($url, 'GET', '', 1, array()); //print __METHOD__." Result for unexisting user: ".var_export($result, true)."\n"; @@ -158,7 +160,7 @@ class RestAPIUserTest extends PHPUnit_Framework_TestCase $object=json_decode($result['content'], true); $this->assertNotNull($object, "Parsing of json result must no be null"); $this->assertEquals(404, $object['error']['code']); - + $url = $this->api_url.'/users/1?api_key='.$this->api_key; print __METHOD__." Request GET url=".$url."\n"; @@ -172,18 +174,18 @@ class RestAPIUserTest extends PHPUnit_Framework_TestCase } public function testRestCreateUser() { - + // attemp to create without mandatory fields : $url = $this->api_url.'/users?api_key='.$this->api_key; $addheaders=array('Content-Type: application/json'); - + $bodyobj = array( "lastname"=>"testRestUser", "password"=>"testRestPassword", "email"=>"test@restuser.com" ); $body = json_encode($bodyobj); - + print __METHOD__." Request POST url=".$url."\n"; $result=getURLContent($url, 'POST', $body, 1, $addheaders); //print __METHOD__." Result for creating incomplete user".var_export($result, true)."\n"; @@ -210,14 +212,14 @@ class RestAPIUserTest extends PHPUnit_Framework_TestCase $resid=json_decode($result['content'], true); $this->assertNotNull($resid, "Parsing of json result must no be null"); $this->assertGreaterThan(0, $resid, $object['error']['code'].' '.$object['error']['message']); - + // attempt to create duplicated user print __METHOD__." Request POST url=".$url."\n"; $result=getURLContent($url, 'POST', $body, 1, $addheaders); //print __METHOD__." Result for creating duplicate user".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; $this->assertEquals($result['curl_error_no'],''); - $object=json_decode($result['content'], true); + $object=json_decode($result['content'], true); $this->assertNotNull($object, "Parsing of json result must no be null"); $this->assertEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']); }