public function truncate($text, $length = 30) { if (strlen($text) > $length) { require_once 'Kornak/Filter/MaxLength.php'; $filter = new Kornak_Filter_MaxLength($length - 1); $text = $filter->filter($text) . '…'; } return $text; }
public function testFilter() { $filter = new Kornak_Filter_MaxLength(10); $this->assertSame('A dummy bu', $filter->filter('A dummy but quite long string'), 'The filter should cut the string to the defined length'); }