Skip to content
Permalink
Browse files

fixes Text::toList to allow passing array( 1=>"abc", 2=>"abc" ) and t…

…he updated test case

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information...
dogmatic69 authored and markstory committed Nov 24, 2009
1 parent d758dbc commit 51d0805ce0e8795690c4796d9ef1a3783015b62d
Showing with 11 additions and 7 deletions.
  1. +8 −7 cake/libs/view/helpers/text.php
  2. +3 −0 cake/tests/cases/libs/view/helpers/text.test.php
@@ -309,16 +309,17 @@ function excerpt($text, $phrase, $radius = 100, $ending = "...") {
* @access public
*/
function toList($list, $and = 'and') {
$r = '';
$c = count($list) - 1;
$return = '';
$count = count($list) - 1;
$counter = 0;
foreach ($list as $i => $item) {
$r .= $item;
if ($c > 0 && $i < $c)
{
$r .= ($i < $c - 1 ? ', ' : " {$and} ");
$return .= $item;
if ($count > 0 && $counter < $count) {
$return .= ($counter < $count - 1 ? ', ' : " {$and} ");
}
$counter++;
}
return $r;
return $return;
}
/**
* Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax.
@@ -343,6 +343,9 @@ function testListGeneration() {
$result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y');
$this->assertEqual($result, 'Dusty, Lucky y Ned');
$result = $this->Text->toList(array( 1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'y');
$this->assertEqual($result, 'Dusty, Lucky y Ned');
}
}
?>

0 comments on commit 51d0805

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.