2
0
forked from Wavyzz/dolibarr

Add phpunit test

This commit is contained in:
ldestailleur
2025-03-26 21:01:46 +01:00
parent d9753254b1
commit 33c7378d2d
2 changed files with 46 additions and 5 deletions

View File

@@ -11960,7 +11960,7 @@ function dolExplodeIntoArray($string, $delimiter = ';', $kv = '=')
} }
/** /**
* Explode a search string into an array but do not explode with keys are inside quotes. * Explode a search string into an array but do not explode when keys are inside quotes.
* For example "a 'b c'" will be array("a", "b c"). * For example "a 'b c'" will be array("a", "b c").
* *
* @param string $input String to explode * @param string $input String to explode
@@ -12037,7 +12037,7 @@ function dol_getmypid()
* 1=value is a numeric test (Example ">5.5 <10"), * 1=value is a numeric test (Example ">5.5 <10"),
* 2=value is a list of ID separated with comma (Example '1,3,4'), -2 is for exclude list, * 2=value is a list of ID separated with comma (Example '1,3,4'), -2 is for exclude list,
* 3=value is list of string separated with comma (Example 'text 1,text 2'), -3 if for exclude list, * 3=value is list of string separated with comma (Example 'text 1,text 2'), -3 if for exclude list,
* 4=value is a list of ID separated with comma (Example '2,7') to be used to search into a multiselect string '1,2,3,4' * 4=value is a list of ID separated with comma (Example '2,7') to be used to search inside a string '1,2,3,4'
* @param integer $nofirstand 1=Do not output the first 'AND' * @param integer $nofirstand 1=Do not output the first 'AND'
* @return string $res The statement to append to the SQL query * @return string $res The statement to append to the SQL query
* @see dolSqlDateFilter() * @see dolSqlDateFilter()
@@ -12076,6 +12076,7 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
$crit = trim($crit); $crit = trim($crit);
$i2 = 0; // count the nb of valid criteria added for this this first criteria $i2 = 0; // count the nb of valid criteria added for this this first criteria
$newres = ''; $newres = '';
foreach ($fields as $field) { foreach ($fields as $field) {
if ($mode == 1) { if ($mode == 1) {
$tmpcrits = explode('|', $crit); $tmpcrits = explode('|', $crit);

View File

@@ -1881,7 +1881,7 @@ class FunctionsLibTest extends CommonClassTest
/** /**
* testFetchObjectByElement * testFetchObjectByElement
* *
* @return boolean; * @return boolean
*/ */
public function testFetchObjectByElement() public function testFetchObjectByElement()
{ {
@@ -1897,7 +1897,7 @@ class FunctionsLibTest extends CommonClassTest
/** /**
* testRoundUpToNextMultiple * testRoundUpToNextMultiple
* *
* @return void; * @return void
*/ */
public function testRoundUpToNextMultiple() public function testRoundUpToNextMultiple()
{ {
@@ -1921,7 +1921,7 @@ class FunctionsLibTest extends CommonClassTest
/** /**
* testNaturalSearch * testNaturalSearch
* *
* @return void; * @return void
*/ */
public function testNaturalSearch() public function testNaturalSearch()
{ {
@@ -1957,4 +1957,44 @@ class FunctionsLibTest extends CommonClassTest
$s = natural_search("t.field", "KØB", 3); // mode 3 is to provide a list of string separated with coma $s = natural_search("t.field", "KØB", 3); // mode 3 is to provide a list of string separated with coma
$this->assertEquals(" AND (t.field IN ('KØB'))", $s); $this->assertEquals(" AND (t.field IN ('KØB'))", $s);
} }
/**
* testDolExplodeKeepIfQuotes
*
* @return void
*/
public function testDolExplodeKeepIfQuotes()
{
global $db;
$result = dolExplodeKeepIfQuotes("a b");
$this->assertEquals("a", $result[0]);
$this->assertEquals("b", $result[1]);
$result = dolExplodeKeepIfQuotes("'a' 'b'");
$this->assertEquals("a", $result[0]);
$this->assertEquals("b", $result[1]);
$result = dolExplodeKeepIfQuotes("a 'b' c");
$this->assertEquals("a", $result[0]);
$this->assertEquals("b", $result[1]);
$this->assertEquals("c", $result[2]);
$result = dolExplodeKeepIfQuotes("a b'c");
$this->assertEquals("a", $result[0]);
$this->assertEquals("b'c", $result[1]);
$result = dolExplodeKeepIfQuotes("a 'b'c");
$this->assertEquals("a", $result[0]);
$this->assertEquals("b", $result[1]);
$this->assertEquals("c", $result[2]);
$result = dolExplodeKeepIfQuotes("a 'b c'");
$this->assertEquals("a", $result[0]);
$this->assertEquals("b c", $result[1]);
//$result = dolExplodeKeepIfQuotes("1 0");
//$this->assertEquals("1", $result[0]);
//$this->assertEquals("0", $result[1]);
}
} }