/** * Test that shorten() returns a shortened string (in the middle) if it is too long. */ public function testShorten() { $this->assertEquals('Lorem … nibh.', String::shorten($this->lipsum, 10)); $this->assertEquals('Lorem ipsum … tellus nibh.', String::shorten($this->lipsum, 25)); $this->assertEquals('Lorem ipsum dolor sit … Morbi eget tellus nibh.', String::shorten($this->lipsum, 50)); $this->assertEquals($this->lipsum, String::shorten($this->lipsum, 100)); // custom $this->assertEquals('Lorem ... nibh.', String::shorten($this->lipsum, 10, ' ... ')); }
function str_shorten($string, $limit = 25, $glue = ' … ') { return String::shorten($string, $limit, $glue); }