Skip to content

Commit

Permalink
legacy support with test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Aug 17, 2012
1 parent 4039842 commit 7969062
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/Utility/StringTest.php
Expand Up @@ -459,6 +459,27 @@ public function testTruncate() {
$this->assertEquals($expected, $result);
}

/**
* testTruncate method with non utf8 sites
*
* @return void
*/
public function testTruncateLegacy() {
Configure::write('App.encoding', 'ISO-8859-1');
$text = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
$result = $this->Text->truncate($text, 31, array(
'exact' => false,
));
$expected = '<b>&copy; 2005-2007, Cake...';
$this->assertEquals($expected, $result);

$result = $this->Text->truncate($text, 31, array(
'exact' => true,
));
$expected = '<b>&copy; 2005-2007, Cake So...';
$this->assertEquals($expected, $result);
}

/**
* testTail method
*
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Utility/String.php
Expand Up @@ -480,11 +480,10 @@ public static function truncate($text, $length = 100, $options = array()) {
$default = array(
'ellipsis' => '...', 'exact' => true, 'html' => false
);
if (!empty($options['html'])) {
$default['ellipsis'] = chr(226);
}
if (isset($options['ending'])) {
$default['ellipsis'] = $options['ending'];
} elseif (!empty($options['html']) && Configure::read('App.encoding') == 'UTF-8') {
$default['ellipsis'] = chr(226);
}
$options = array_merge($default, $options);
extract($options);
Expand Down

0 comments on commit 7969062

Please sign in to comment.