static function resume_text($string, $length = 255) { if (Toolbox::strlen($string) > $length) { $string = Toolbox::substr($string, 0, $length) . " (...)"; } return $string; }
/** * @covers Html::resume_text */ public function testResume_text() { $origin = 'This is a very long string which will be truncated by a dedicated method. ' . 'If the string is not truncated, well... We\'re wrong and got a very serious issue in our codebase!' . 'And if the string has been correctly truncated, well... All is ok then, let\'s show if all the other tests are OK :)'; $expected = 'This is a very long string which will be truncated by a dedicated method. ' . 'If the string is not truncated, well... We\'re wrong and got a very serious issue in our codebase!' . 'And if the string has been correctly truncated, well... All is ok then, let\'s show i (...)'; $this->assertEquals($expected, Html::resume_text($origin)); $origin = 'A string that is longer than 10 characters.'; $expected = 'A string t (...)'; $this->assertEquals($expected, Html::resume_text($origin, 10)); }