mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-05 16:42:53 +01:00
Add more REST phpunit tests
This commit is contained in:
@@ -123,21 +123,25 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$this->api_url=DOL_MAIN_URL_ROOT.'/api/index.php';
|
||||
$this->api_url = DOL_MAIN_URL_ROOT.'/api/index.php';
|
||||
|
||||
$login='admin';
|
||||
$password='admin';
|
||||
$url=$this->api_url.'/login?login='.$login.'&password='.$password;
|
||||
// Call the API login method to save api_key for this test class
|
||||
// Call the API login method to save api_key for this test class.
|
||||
// At first call, if token is not defined a random value is generated and returned.
|
||||
$result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2);
|
||||
print __METHOD__." result = ".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); // If success content is just an id, if not an array
|
||||
|
||||
$this->assertNotNull($object, "Parsing of json result must not be null");
|
||||
$this->assertNotEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']);
|
||||
$this->assertEquals('200', $object['success']['code']);
|
||||
|
||||
$this->api_key = $object['success']['token'];
|
||||
|
||||
print __METHOD__." api_key: $this->api_key \n";
|
||||
}
|
||||
|
||||
@@ -223,17 +227,19 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase
|
||||
"login"=>"testRestLogin".mt_rand(),
|
||||
"lastname"=>"testRestUser",
|
||||
"password"=>"testRestPassword",
|
||||
"email"=>"test@restuser.com"
|
||||
"email"=>"test".mt_rand()."@restuser.com"
|
||||
);
|
||||
$body = json_encode($bodyobj);
|
||||
print __METHOD__." Request POST url=".$url."\n";
|
||||
$result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2);
|
||||
print __METHOD__." rclsesult code for creating user ".var_export($result, true)."\n";
|
||||
print __METHOD__." result code for creating non existing user = ".var_export($result, true)."\n";
|
||||
print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n";
|
||||
$this->assertEquals($result['curl_error_no'], '');
|
||||
$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']);
|
||||
$object = json_decode($result['content'], true); // If success content is just an id, if not an array
|
||||
|
||||
$this->assertNotNull($object, "Parsing of json result must no be null");
|
||||
$this->assertNotEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']);
|
||||
$this->assertGreaterThan(0, $object, $object['error']['code'].' '.$object['error']['message']);
|
||||
|
||||
// attempt to create duplicated user
|
||||
print __METHOD__." Request POST url=".$url."\n";
|
||||
|
||||
Reference in New Issue
Block a user