mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 01:28:19 +01:00
Fix phpunit
This commit is contained in:
@@ -125,22 +125,9 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
$this->api_url=DOL_MAIN_URL_ROOT.'/api/index.php';
|
||||
|
||||
$login='admin';
|
||||
$password='adminadmin';
|
||||
$url=$this->api_url.'/login?login='.$login.'&password='.$password;
|
||||
// Call the API login method to save api_key for this test class
|
||||
$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);
|
||||
$this->assertNotNull($object, "Parsing of json result must not be null");
|
||||
$this->assertEquals('200', $object['success']['code']);
|
||||
$this->api_key = 'admin'; // Test on API to get this token is inside RestAPIUserTest.php
|
||||
|
||||
$this->api_key = $object['success']['token'];
|
||||
print __METHOD__." api_key: $this->api_key \n";
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +142,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
|
||||
/**
|
||||
* testRestGetUser
|
||||
* testRestGetContact
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -168,7 +155,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
print __METHOD__." Request GET url=".$url."\n";
|
||||
$result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2);
|
||||
//print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n";
|
||||
print __METHOD__." result for get on unexisting contact: ".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);
|
||||
@@ -180,7 +167,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
print __METHOD__." Request GET url=".$url."\n";
|
||||
$result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2);
|
||||
print __METHOD__." result for get on an existing user: ".var_export($result, true)."\n";
|
||||
print __METHOD__." result for get on an existing contact: ".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);
|
||||
@@ -188,6 +175,14 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(1, $object['statut']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRestCreateContact
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @depends testRestGetContact
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testRestCreateContact()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
@@ -277,6 +272,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -118,22 +118,9 @@ class RestAPIDocumentTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
$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
|
||||
$result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2);
|
||||
echo __METHOD__.' result = '.var_export($result, true)."\n";
|
||||
echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n";
|
||||
$this->assertEquals($result['curl_error_no'], '');
|
||||
$object = json_decode($result['content'], true);
|
||||
$this->assertNotNull($object, 'Parsing of json result must no be null');
|
||||
$this->assertEquals('200', $object['success']['code']);
|
||||
$this->api_key = 'admin'; // Test on API to get this token is inside RestAPIUserTest.php
|
||||
|
||||
$this->api_key = $object['success']['token'];
|
||||
echo __METHOD__." api_key: $this->api_key \n";
|
||||
|
||||
echo __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -139,8 +139,6 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
$this->api_key = $object['success']['token'];
|
||||
print __METHOD__." api_key: $this->api_key \n";
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,12 +183,17 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase
|
||||
$object=json_decode($result['content'], true);
|
||||
$this->assertNotNull($object, "Parsing of json result must not be null");
|
||||
$this->assertEquals(1, $object['statut']);
|
||||
|
||||
return $object['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* testRestCreateUser
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @depends testRestGetUser
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testRestCreateUser()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user