/** * @inheritdoc */ public function decorate($content, $length = null, $default = null) { if (is_numeric($length)) { $content = HtmlUtilities::excerpt(!empty($content) ? $content : $default, intval($length)) . PHP_EOL; } return $content; }
public function testExcerpt() { $shortText = 'This is short text, it will be truncated with an excerpt length of 50 but not 100.'; $shortTextExcerptLength50 = 'This is short text, it will be truncated with...'; $longText = 'This is long text, it is longer than the default excerpt length and will therefore be truncated by calling excerpt() with an excerpt length argument of 50 or 100'; $longTextExcerptLength50 = 'This is long text, it is longer than the...'; $longTextExcerptLength100 = 'This is long text, it is longer than the default excerpt length and will therefore be truncated...'; $this->assertEquals($shortTextExcerptLength50, HtmlUtilities::excerpt($shortText, 50)); $this->assertEquals($shortText, HtmlUtilities::excerpt($shortText, 100)); $this->assertEquals($longTextExcerptLength50, HtmlUtilities::excerpt($longText, 50)); $this->assertEquals($longTextExcerptLength100, HtmlUtilities::excerpt($longText, 100)); }