private function checkStringWordCut(string $string, int $max = 8, string $etc = '...') : string
{
$cut = StringUtil::cutWords($string, $max, $etc);
// … has length of 1
$cut2 = strtr(html_entity_decode($cut, ENT_COMPAT, 'utf-8'), ['…' => '.']);
$words = preg_split('~\\s+~', $string);
$trimmedWords = preg_split('~\\s+~', $cut2);
$this->assertEquals(count($trimmedWords), count($words));
foreach ($words as $i => $word) {
if (mb_strlen($word, 'utf-8') <= $max) {
$this->assertEquals($word, $trimmedWords[$i], 'Word trimmed even though it was short enough');
} else {
$this->assertLessThanOrEqual($max, mb_strlen($trimmedWords[$i], 'utf-8'));
$this->assertRegExp('~' . preg_quote($etc === '…' ? '.' : $etc) . '$~', $trimmedWords[$i], 'String does not end with ' . $etc);
}
}
return $cut;
}