Skip to content
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...
1 parent 4a08bd1 commit 398113f8288701bedc82a7e3bfd04f5db9d5ad06 @dogmatic69 dogmatic69 committed with markstory
Showing with 11 additions and 6 deletions.
  1. +8 −6 cake/libs/view/helpers/text.php
  2. +3 −0 cake/tests/cases/libs/view/helpers/text.test.php
View
14 cake/libs/view/helpers/text.php
@@ -332,15 +332,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;
}
}
?>
View
3 cake/tests/cases/libs/view/helpers/text.test.php
@@ -362,6 +362,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 398113f

Please sign in to comment.
Something went wrong with that request. Please try again.