fix tests

This commit is contained in:
Frédéric FRANCE
2021-02-21 13:32:54 +01:00
parent 2ad63f36e7
commit 6e3a1a1d41
2 changed files with 10 additions and 10 deletions

View File

@@ -3173,12 +3173,12 @@ function dol_substr($string, $start, $length, $stringencoding = '', $trunconbyte
/** /**
* Truncate a string to a particular length adding '...' if string larger than length. * Truncate a string to a particular length adding '' if string larger than length.
* If length = max length+1, we do no truncate to avoid having just 1 char replaced with '...'. * If length = max length+1, we do no truncate to avoid having just 1 char replaced with ''.
* MAIN_DISABLE_TRUNC=1 can disable all truncings * MAIN_DISABLE_TRUNC=1 can disable all truncings
* *
* @param string $string String to truncate * @param string $string String to truncate
* @param int $size Max string size visible (excluding …). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added ..., or if size was max+1 or max+2 or max+3 so it does not worse to replace with ...) * @param int $size Max string size visible (excluding …). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added , or if size was max+1 so it does not worse to replace with ...)
* @param string $trunc Where to trunc: 'right', 'left', 'middle' (size must be a 2 power), 'wrap' * @param string $trunc Where to trunc: 'right', 'left', 'middle' (size must be a 2 power), 'wrap'
* @param string $stringencoding Tell what is source string encoding * @param string $stringencoding Tell what is source string encoding
* @param int $nodot Truncation do not add … after truncation. So it's an exact truncation. * @param int $nodot Truncation do not add … after truncation. So it's an exact truncation.

View File

@@ -765,21 +765,21 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
*/ */
public function testDolTrunc() public function testDolTrunc()
{ {
// Default trunc (will add ... if truncation truncation or keep last char if only one char) // Default trunc (will add if truncation truncation or keep last char if only one char)
$input="éeéeéeàa"; $input="éeéeéeàa";
$after=dol_trunc($input, 3); $after=dol_trunc($input, 3);
$this->assertEquals("éeé...", $after, 'Test A1'); $this->assertEquals("éeé", $after, 'Test A1');
$after=dol_trunc($input, 2); $after=dol_trunc($input, 2);
$this->assertEquals("ée...", $after, 'Test A2'); $this->assertEquals("ée", $after, 'Test A2');
$after=dol_trunc($input, 1); $after=dol_trunc($input, 1);
$this->assertEquals("é...", $after, 'Test A3'); $this->assertEquals("é", $after, 'Test A3');
$input="éeéeé"; $input="éeéeé";
$after=dol_trunc($input, 3); $after=dol_trunc($input, 3);
$this->assertEquals("éeéeé", $after, 'Test B1'); $this->assertEquals("éeéeé", $after, 'Test B1');
$after=dol_trunc($input, 2); $after=dol_trunc($input, 2);
$this->assertEquals("éeéeé", $after, 'Test B2'); $this->assertEquals("éeéeé", $after, 'Test B2');
$after=dol_trunc($input, 1); $after=dol_trunc($input, 1);
$this->assertEquals("é...", $after, 'Test B3'); $this->assertEquals("é", $after, 'Test B3');
$input="éeée"; $input="éeée";
$after=dol_trunc($input, 3); $after=dol_trunc($input, 3);
$this->assertEquals("éeée", $after, 'Test C1'); $this->assertEquals("éeée", $after, 'Test C1');
@@ -794,7 +794,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
$this->assertEquals("éeé", $after, 'Test D'); $this->assertEquals("éeé", $after, 'Test D');
$after=dol_trunc($input, 1); $after=dol_trunc($input, 1);
$this->assertEquals("éeé", $after, 'Test E'); $this->assertEquals("éeé", $after, 'Test E');
// Trunc with no ... // Trunc with no
$input="éeéeéeàa"; $input="éeéeéeàa";
$after=dol_trunc($input, 3, 'right', 'UTF-8', 1); $after=dol_trunc($input, 3, 'right', 'UTF-8', 1);
$this->assertEquals("éeé", $after, 'Test F'); $this->assertEquals("éeé", $after, 'Test F');
@@ -809,7 +809,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
$this->assertEquals("é", $after, 'Test J'); $this->assertEquals("é", $after, 'Test J');
$input="éeéeéeàa"; $input="éeéeéeàa";
$after=dol_trunc($input, 4, 'middle'); $after=dol_trunc($input, 4, 'middle');
$this->assertEquals("ée...àa", $after, 'Test K'); $this->assertEquals("éeàa", $after, 'Test K');
return true; return true;
} }