2
0
forked from Wavyzz/dolibarr

Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur
2024-10-13 20:32:52 +02:00
5 changed files with 34 additions and 179 deletions

View File

@@ -10589,27 +10589,15 @@ function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring = '1'
//print $s."<br>\n"; //print $s."<br>\n";
if ($returnvalue) { if ($returnvalue) {
if ($hideerrors) { ob_start(); // An evaluation has no reason to output data
ob_start(); // An evaluation has no reason to output data $isObBufferActive = true;
$isObBufferActive = true; $tmps = $hideerrors ? @eval('return ' . $s . ';') : eval('return ' . $s . ';');
$tmps = @eval('return '.$s.';'); $tmpo = ob_get_clean();
$tmpo = ob_get_clean(); $isObBufferActive = false;
$isObBufferActive = false; if ($tmpo) {
if ($tmpo) { print 'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
print 'Bad string syntax to evaluate. Some data were output when it should not when evaluating: '.$s;
}
return $tmps;
} else {
ob_start(); // An evaluation has no reason to output data
$isObBufferActive = true;
$tmps = eval('return '.$s.';');
$tmpo = ob_get_clean();
$isObBufferActive = false;
if ($tmpo) {
print 'Bad string syntax to evaluate. Some data were output when it should not when evaluating: '.$s;
}
return $tmps;
} }
return $tmps;
} else { } else {
dol_syslog('Do not use anymore dol_eval with param returnvalue=0', LOG_WARNING); dol_syslog('Do not use anymore dol_eval with param returnvalue=0', LOG_WARNING);
if ($hideerrors) { if ($hideerrors) {

View File

@@ -143,9 +143,9 @@ if ($result >= 0) {
foreach ($ldaprecords as $key => $ldapgroup) { foreach ($ldaprecords as $key => $ldapgroup) {
$group = new UserGroup($db); $group = new UserGroup($db);
$group->fetch('', $ldapgroup[getDolGlobalString('LDAP_KEY_GROUPS')]); $group->fetch('', $ldapgroup[getDolGlobalString('LDAP_KEY_GROUPS')]);
$group->name = $ldapgroup[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')]; $group->name = $ldapgroup[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] ?? null;
$group->nom = $group->name; // For backward compatibility $group->nom = $group->name; // For backward compatibility
$group->note = $ldapgroup[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')]; $group->note = $ldapgroup[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] ?? null;
$group->entity = $conf->entity; $group->entity = $conf->entity;
// print_r($ldapgroup); // print_r($ldapgroup);

View File

@@ -202,30 +202,30 @@ if ($result >= 0) {
} }
// Propriete membre // Propriete membre
$fuser->firstname = $ldapuser[getDolGlobalString('LDAP_FIELD_FIRSTNAME')]; $fuser->firstname = $ldapuser[getDolGlobalString('LDAP_FIELD_FIRSTNAME')] ?? null;
$fuser->lastname = $ldapuser[getDolGlobalString('LDAP_FIELD_NAME')]; $fuser->lastname = $ldapuser[getDolGlobalString('LDAP_FIELD_NAME')] ?? null;
$fuser->login = $ldapuser[getDolGlobalString('LDAP_FIELD_LOGIN')]; $fuser->login = $ldapuser[getDolGlobalString('LDAP_FIELD_LOGIN')] ?? null;
$fuser->pass = $ldapuser[getDolGlobalString('LDAP_FIELD_PASSWORD')]; $fuser->pass = $ldapuser[getDolGlobalString('LDAP_FIELD_PASSWORD')] ?? null;
$fuser->pass_indatabase_crypted = $ldapuser[getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED')]; $fuser->pass_indatabase_crypted = $ldapuser[getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED')] ?? null;
// $user->societe; // $user->societe;
/* /*
* $fuser->address=$ldapuser[getDolGlobalString('LDAP_FIELD_ADDRESS')]; * $fuser->address=$ldapuser[getDolGlobalString('LDAP_FIELD_ADDRESS')] ?? null;
* $fuser->zip=$ldapuser[getDolGlobalString('LDAP_FIELD_ZIP')]; * $fuser->zip=$ldapuser[getDolGlobalString('LDAP_FIELD_ZIP')] ?? null;
* $fuser->town=$ldapuser[getDolGlobalString('LDAP_FIELD_TOWN')]; * $fuser->town=$ldapuser[getDolGlobalString('LDAP_FIELD_TOWN')] ?? null;
* $fuser->country=$ldapuser[getDolGlobalString('LDAP_FIELD_COUNTRY')]; * $fuser->country=$ldapuser[getDolGlobalString('LDAP_FIELD_COUNTRY')] ?? null;
* $fuser->country_id=$countries[$hashlib2rowid[strtolower($fuser->country)]]['rowid']; * $fuser->country_id=$countries[$hashlib2rowid[strtolower($fuser->country)]]['rowid'];
* $fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code']; * $fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
*/ */
$fuser->office_phone = $ldapuser[getDolGlobalString('LDAP_FIELD_PHONE')]; $fuser->office_phone = $ldapuser[getDolGlobalString('LDAP_FIELD_PHONE')] ?? null;
$fuser->user_mobile = $ldapuser[getDolGlobalString('LDAP_FIELD_MOBILE')]; $fuser->user_mobile = $ldapuser[getDolGlobalString('LDAP_FIELD_MOBILE')] ?? null;
$fuser->office_fax = $ldapuser[getDolGlobalString('LDAP_FIELD_FAX')]; $fuser->office_fax = $ldapuser[getDolGlobalString('LDAP_FIELD_FAX')] ?? null;
$fuser->email = $ldapuser[getDolGlobalString('LDAP_FIELD_MAIL')]; $fuser->email = $ldapuser[getDolGlobalString('LDAP_FIELD_MAIL')] ?? null;
$fuser->ldap_sid = $ldapuser[getDolGlobalString('LDAP_FIELD_SID')]; $fuser->ldap_sid = $ldapuser[getDolGlobalString('LDAP_FIELD_SID')] ?? null;
$fuser->job = $ldapuser[getDolGlobalString('LDAP_FIELD_TITLE')]; $fuser->job = $ldapuser[getDolGlobalString('LDAP_FIELD_TITLE')] ?? null;
$fuser->note = $ldapuser[getDolGlobalString('LDAP_FIELD_DESCRIPTION')]; $fuser->note = $ldapuser[getDolGlobalString('LDAP_FIELD_DESCRIPTION')] ?? null;
$fuser->admin = 0; $fuser->admin = 0;
$fuser->socid = 0; $fuser->socid = 0;
$fuser->contact_id = 0; $fuser->contact_id = 0;
@@ -237,7 +237,7 @@ if ($result >= 0) {
* if (isset($ldapuser[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')])) { * if (isset($ldapuser[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')])) {
* $fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); * $fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
* $fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); * $fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
* $fuser->statut=$ldapuser[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')]; * $fuser->statut=$ldapuser[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] ?? null;
* } * }
*/ */
// if ($fuser->statut > 1) $fuser->statut=1; // if ($fuser->statut > 1) $fuser->statut=1;

View File

@@ -25,22 +25,7 @@
* \remarks To run this script as CLI: phpunit filename.php * \remarks To run this script as CLI: phpunit filename.php
*/ */
global $conf,$user,$langs,$db; require_once __DIR__."/AbstractRestAPITest.php";
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php';
require_once dirname(__FILE__).'/CommonClassTest.class.php';
if (empty($user->id)) {
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
$conf->global->MAIN_UMASK = '0666';
/** /**
* Class for PHPUnit tests * Class for PHPUnit tests
@@ -49,65 +34,11 @@ $conf->global->MAIN_UMASK = '0666';
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/ */
class RestAPIContactTest extends CommonClassTest class RestAPIContactTest extends AbstractRestAPITest
{ {
protected $api_url; protected $api_url;
protected $api_key; protected $api_key;
/**
* setUpBeforeClass
*
* @return void
*/
public static function setUpBeforeClass(): void
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
if (!isModEnabled('api')) {
print __METHOD__." module api must be enabled.\n";
die(1);
}
print __METHOD__."\n";
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp(): void
{
global $conf,$user,$langs,$db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
$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.
// 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); // 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, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message']));
$this->assertEquals('200', $object['success']['code']);
$this->api_key = $object['success']['token'];
print __METHOD__." api_key: $this->api_key \n";
}
/** /**
* testRestGetContact * testRestGetContact
* *
@@ -184,6 +115,8 @@ class RestAPIContactTest extends CommonClassTest
$body = json_encode($bodyobj); $body = json_encode($bodyobj);
var_export($body);
$result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2);
$this->assertEquals($result['curl_error_no'], ''); $this->assertEquals($result['curl_error_no'], '');

View File

@@ -24,22 +24,9 @@
* \brief PHPUnit test * \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php. * \remarks To run this script as CLI: phpunit filename.php.
*/ */
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php';
require_once dirname(__FILE__).'/CommonClassTest.class.php';
if (empty($user->id)) { require_once __DIR__."/AbstractRestAPITest.php";
echo "Load permissions for admin user nb 1\n"; require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php';
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
$conf->global->MAIN_UMASK = '0666';
/** /**
* Class for PHPUnit tests. * Class for PHPUnit tests.
@@ -48,64 +35,11 @@ $conf->global->MAIN_UMASK = '0666';
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/ */
class RestAPIDocumentTest extends CommonClassTest class RestAPIDocumentTest extends AbstractRestAPITest
{ {
protected $api_url; protected $api_url;
protected $api_key; protected $api_key;
/**
* setUpBeforeClass
*
* @return void
*/
public static function setUpBeforeClass(): void
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
if (!isModEnabled('api')) {
print __METHOD__." module api must be enabled.\n";
die(1);
}
echo __METHOD__."\n";
}
/**
* Init phpunit tests.
*
* @return void
*/
protected function setUp(): void
{
global $conf,$user,$langs,$db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
$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.
// 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); // 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, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message']));
$this->assertEquals('200', $object['success']['code']);
$this->api_key = $object['success']['token'];
echo __METHOD__." api_key: $this->api_key \n";
}
/** /**
* testPushDocument. * testPushDocument.
* *