diff --git a/htdocs/admin/system/filecheck.php b/htdocs/admin/system/filecheck.php index dbb9e5a2e77..bb6007ef1c1 100644 --- a/htdocs/admin/system/filecheck.php +++ b/htdocs/admin/system/filecheck.php @@ -190,7 +190,7 @@ if (GETPOST('target') == 'remote') { $xmlarray = getURLContent($xmlremote, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only. Same is used into api_setup.class.php. // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) - if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '400' && $xmlarray['http_code'] != '404') { + if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != 400 && $xmlarray['http_code'] != 404) { $xmlfile = $xmlarray['content']; //print "xmlfilestart".$xmlfile."xmlfileend"; if (LIBXML_VERSION < 20900) { diff --git a/htdocs/ai/class/ai.class.php b/htdocs/ai/class/ai.class.php index ad1642c52d3..0ba6852a021 100644 --- a/htdocs/ai/class/ai.class.php +++ b/htdocs/ai/class/ai.class.php @@ -339,7 +339,7 @@ class Ai 'error' => true, 'message' => $errormessage, 'code' => (empty($response['http_code']) ? 0 : $response['http_code']), - 'curl_error_no' => (!empty($response['curl_error_no']) ? $response['curl_error_no'] : ''), + 'curl_error_no' => (empty($response['curl_error_no']) ? 0 : $response['curl_error_no']), 'format' => $format, 'service' => $this->apiService, 'function' => $function diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index e32d9cadf37..dc3e8045494 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -2555,7 +2555,7 @@ class Setup extends DolibarrApi $xmlarray = getURLContent($xmlremote, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only. Same is used into filecheck.php. // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) - if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '400' && $xmlarray['http_code'] != '404') { + if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != 400 && $xmlarray['http_code'] != 404) { $xmlfile = $xmlarray['content']; //print "xmlfilestart".$xmlfile."endxmlfile"; $xml = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET); diff --git a/htdocs/partnership/class/partnershiputils.class.php b/htdocs/partnership/class/partnershiputils.class.php index a829a65c257..fdf0d7f6619 100644 --- a/htdocs/partnership/class/partnershiputils.class.php +++ b/htdocs/partnership/class/partnershiputils.class.php @@ -540,10 +540,10 @@ class PartnershipUtils // $website = 'https://nextgestion.com/'; // For Test $tmpgeturl = getURLContent($website, 'GET', '', 1, array(), array('http', 'https'), 0); - if ($tmpgeturl['curl_error_no']) { + if (!empty($tmpgeturl['curl_error_no'])) { $error++; dol_syslog('Error getting '.$website.': '.$tmpgeturl['curl_error_msg']); - } elseif ($tmpgeturl['http_code'] != '200') { + } elseif ($tmpgeturl['http_code'] != 200) { $error++; dol_syslog('Error getting '.$website.': '.$tmpgeturl['curl_error_msg']); } else { diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 3abb5465ce5..4e84c28bcc2 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -865,11 +865,11 @@ if ($action == 'addcontainer' && $usercanedit) { } } - if ($tmp['curl_error_no']) { + if (!empty($tmp['curl_error_no'])) { $error++; setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors'); $action = 'createcontainer'; - } elseif ($tmp['http_code'] != '200') { + } elseif ($tmp['http_code'] != 200) { $error++; setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors'); $action = 'createcontainer'; @@ -989,14 +989,14 @@ if ($action == 'addcontainer' && $usercanedit) { /* $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0); - if ($tmpgeturl['curl_error_no']) + if (!empty($tmpgeturl['curl_error_no'])) { $error++; setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); $errorforsubresource++; $action='createcontainer'; } - elseif ($tmpgeturl['http_code'] != '200') + elseif ($tmpgeturl['http_code'] != 200) { $error++; setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); @@ -1053,12 +1053,12 @@ if ($action == 'addcontainer' && $usercanedit) { } $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0); - if ($tmpgeturl['curl_error_no']) { + if (!empty($tmpgeturl['curl_error_no'])) { $errorforsubresource++; setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']); $action = 'createcontainer'; - } elseif ($tmpgeturl['http_code'] != '200') { + } elseif ($tmpgeturl['http_code'] != 200) { $errorforsubresource++; setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']); diff --git a/test/phpunit/AbstractRestAPITest.php b/test/phpunit/AbstractRestAPITest.php index bacdaa1e812..4fb8c0b01e8 100644 --- a/test/phpunit/AbstractRestAPITest.php +++ b/test/phpunit/AbstractRestAPITest.php @@ -94,7 +94,7 @@ abstract class AbstractRestAPITest extends CommonClassTest $result = getURLContent($url, 'GET', '', 1, $addheaders, 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'], "$test Should not have a curl error"); + $this->assertEquals(0, $result['curl_error_no'], "$test Should not have a curl error"); $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); diff --git a/test/phpunit/RestAPIContactTest.php b/test/phpunit/RestAPIContactTest.php index 770d32ebe8f..d73b32cf74a 100644 --- a/test/phpunit/RestAPIContactTest.php +++ b/test/phpunit/RestAPIContactTest.php @@ -55,7 +55,7 @@ class RestAPIContactTest extends AbstractRestAPITest $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'], ''); + $this->assertEquals(0, $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'); @@ -67,7 +67,7 @@ class RestAPIContactTest extends AbstractRestAPITest $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); 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'], ''); + $this->assertEquals(0, $result['curl_error_no']); $object = json_decode($result['content'], true); $this->assertNotNull($object, "Parsing of json result must not be null"); $this->assertEquals(1, $object['statut']); @@ -98,7 +98,7 @@ class RestAPIContactTest extends AbstractRestAPITest $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); //print __METHOD__." Result for creating incomplete contact".var_export($result, true)."\n"; //print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); + $this->assertEquals(0, $result['curl_error_no']); $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->assertEquals(400, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); @@ -119,7 +119,7 @@ class RestAPIContactTest extends AbstractRestAPITest $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); - $this->assertEquals($result['curl_error_no'], ''); + $this->assertEquals(0, $result['curl_error_no']); $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"); diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index 1a944abf97e..9a47b7287b3 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -80,7 +80,7 @@ class RestAPIDocumentTest extends AbstractRestAPITest echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; $object = json_decode($result['content'], true); $this->assertNotNull($object, 'Parsing of json result must not be null'); - $this->assertEquals('400', $result['http_code'], 'Test to push a document on a non existing dir does not return 400'); + $this->assertEquals(400, $result['http_code'], 'Test to push a document on a non existing dir does not return 400'); $this->assertEquals('400', (empty($object['error']['code']) ? '' : $object['error']['code']), 'Test to push a document on a non existing dir does not return 400'); diff --git a/test/phpunit/RestAPIMosTest.php b/test/phpunit/RestAPIMosTest.php index 36e92f32a32..ff24dda70df 100644 --- a/test/phpunit/RestAPIMosTest.php +++ b/test/phpunit/RestAPIMosTest.php @@ -73,18 +73,18 @@ class RestAPIMosTest extends AbstractRestAPITest $result = getURLContent($url, $method, $body, 1, $addheaders, array('http', 'https'), 2); - $this->assertEquals('', $result['curl_error_no'], "{$test_title}Should not have a curl error"); + $this->assertEquals(0, $result['curl_error_no'], $test_title." Should not have a curl error"); $object = json_decode($result['content'], true); $dbg_info = PHP_EOL.json_encode($result, JSON_PRETTY_PRINT); - $this->assertNotNull($object, "{$test_title}Parsing of JSON result must not be null$dbg_info"); + $this->assertNotNull($object, $test_title." Parsing of JSON result must not be null ".$dbg_info); $result['content'] = $object; $dbg_info = PHP_EOL.json_encode($result, JSON_PRETTY_PRINT); - $this->assertEquals($expected_error, (empty($object['error']['code']) ? 0 : $object['error']['code']), "{$test_title}Error code is not $expected_error$dbg_info"); + $this->assertEquals($expected_error, (empty($object['error']['code']) ? 0 : $object['error']['code']), $test_title." Error code is not ".$expected_error.$dbg_info); return $result; } diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index 1d95870abc9..4ab12505514 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -1,7 +1,7 @@ - * Copyright (C) 2023 Alexandre Janniaux - * Copyright (C) 2024 MDW +/* Copyright (C) 2010-2025 Laurent Destailleur + * Copyright (C) 2023 Alexandre Janniaux + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,8 +46,6 @@ class RestAPIUserTest extends AbstractRestAPITest */ public function testRestGetUser() { - global $conf,$user,$langs,$db; - $test = "Invalid User -"; $url = $this->api_url.'/users/123456789?api_key='.$this->api_key; //$addheaders=array('Content-Type: application/json'); @@ -56,7 +54,7 @@ class RestAPIUserTest extends AbstractRestAPITest $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__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals('', $result['curl_error_no'], "$test Should not have a curl error"); + $this->assertEquals(0, $result['curl_error_no'], "$test Should not have a curl error"); $object = json_decode($result['content'], true); $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); $this->assertEquals(404, (empty($object['error']['code']) ? 0 : $object['error']['code']), "$test Error code is not 404"); @@ -68,7 +66,7 @@ class RestAPIUserTest extends AbstractRestAPITest $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); print __METHOD__." $test result for get: ".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals('', $result['curl_error_no'], "$test should have no error"); + $this->assertEquals(0, $result['curl_error_no'], "$test should have no error"); $object = json_decode($result['content'], true); $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); $this->assertEquals(1, $object['statut']); @@ -102,7 +100,7 @@ class RestAPIUserTest extends AbstractRestAPITest $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); //print __METHOD__." Result for creating incomplete user".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals('', $result['curl_error_no'], "$test Should not have a curl error"); + $this->assertEquals(0, $result['curl_error_no'], "$test Should not have a curl error"); $object = json_decode($result['content'], true); $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); $this->assertEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), "$test Error".(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); @@ -121,7 +119,7 @@ class RestAPIUserTest extends AbstractRestAPITest $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); 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'], "$test Should not have a curl error"); + $this->assertEquals(0, $result['curl_error_no'], "$test Should not have a curl error"); $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); @@ -134,7 +132,7 @@ class RestAPIUserTest extends AbstractRestAPITest $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); //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'], "$test Should not have a curl error"); + $this->assertEquals(0, $result['curl_error_no'], "$test Should not have a curl error"); $object = json_decode($result['content'], true); $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); $this->assertEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), "$test Error".(empty($object['error']['message']) ? '' : ' '.$object['error']['message']));