diff --git a/htdocs/compta/paiement/class/cpaiement.class.php b/htdocs/compta/paiement/class/cpaiement.class.php index 7ee79cc969c..683e9fc3679 100644 --- a/htdocs/compta/paiement/class/cpaiement.class.php +++ b/htdocs/compta/paiement/class/cpaiement.class.php @@ -49,24 +49,24 @@ class Cpaiement public $code; /** - * @var int ID + * @var int ID */ public $id; /** - * @var string[] array of errors messages + * @var string[] array of errors messages */ public $errors; /** - * @var string + * @var string * @deprecated * @see $label */ public $libelle; /** - * @var string + * @var string */ public $label; diff --git a/test/phpunit/RestAPIContactTest.php b/test/phpunit/RestAPIContactTest.php index a2a2011145b..88309f09e7d 100644 --- a/test/phpunit/RestAPIContactTest.php +++ b/test/phpunit/RestAPIContactTest.php @@ -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,32 +142,32 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase /** - * testRestGetUser + * testRestGetContact * * @return int */ public function testRestGetContact() { global $conf,$user,$langs,$db; - //fetch Non-Existent contact + //fetch Non-Existent contact $url = $this->api_url.'/contacts/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(), array('http', 'https'), 2); - //print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; + $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); + 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); $this->assertNotNull($object, "Parsing of json result must not be null"); $this->assertEquals(404, $object['error']['code'], 'Error code is not 404'); - //fetch an existent contact + //fetch an existent contact $url = $this->api_url.'/contacts/1?api_key='.$this->api_key; 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,13 +175,21 @@ 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; // attempt to create without mandatory fields $url = $this->api_url.'/contacts?api_key='.$this->api_key; $addheaders=array('Content-Type: application/json'); - + $bodyobj= array( "firstname" => "firstname" ); @@ -217,9 +212,9 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase "firstname" => "testRestContact" . mt_rand(), "lastname" => "testRestContact", ); - + $body = json_encode($bodyobj); - + $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); $this->assertEquals($result['curl_error_no'], ''); @@ -231,36 +226,36 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase //update the contact // Update the firstname of the contact - /* + /* $updateBody = array( "firstname" => "UpdatedFirstName", ); - + $updateRequestBody = json_encode($updateBody); $updateUrl = $this->api_url . '/contacts/' . $resid. '?api_key=' . $this->api_key; $updateResult = getURLContent($updateUrl, 'PUT', $updateRequestBody, 1, $addheaders, array('http', 'https'), 2); $this->assertEquals($updateResult['curl_error_no'], ''); $updateResponse = json_decode($updateResult['content'], true); - + $this->assertNotNull($updateResponse, "Parsing of JSON result must not be null"); - print_r($updateResponse); - - // Check if the updated fields match the changes you made - if ($updateResponse['firstname'] === $updateBody['firstname']) { - // Update was successful - $this->assertTrue(true); - } else { - // Update might have failed - $this->assertTrue(false, "Update might have failed"); - } + print_r($updateResponse); + + // Check if the updated fields match the changes you made + if ($updateResponse['firstname'] === $updateBody['firstname']) { + // Update was successful + $this->assertTrue(true); + } else { + // Update might have failed + $this->assertTrue(false, "Update might have failed"); + } // Deleting the Contact $deleteUrl = $this->api_url . '/contacts/' . $resid . '?api_key=' . $this->api_key; $deleteResult = getURLContent($deleteUrl, 'DELETE', '', 1, $addheaders, array('http', 'https'), 2); - + $this->assertEquals($deleteResult['curl_error_no'], ''); $deleteResponse = json_decode($deleteResult['content'], true); @@ -269,14 +264,15 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase - // Update Non-Existent Contact - + // Update Non-Existent Contact - // Delete Non-Existent Contact + + // Delete Non-Existent Contact */ + + return 0; } - -} \ No newline at end of file +} diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index f487593a9b8..819cc03a464 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -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"; } /** diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index ba18c5aa6bb..4224691298a 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -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() {