mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-19 07:59:54 +00:00
fixes Text::toList to allow passing array( 1=>"abc", 2=>"abc" ) and the updated test case
Signed-off-by: Mark Story <mark@mark-story.com>
This commit is contained in:
parent
4a08bd120d
commit
398113f828
2 changed files with 11 additions and 6 deletions
|
@ -332,15 +332,17 @@ class TextHelper extends AppHelper {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function toList($list, $and = 'and') {
|
function toList($list, $and = 'and') {
|
||||||
$r = '';
|
$return = '';
|
||||||
$c = count($list) - 1;
|
$count = count($list) - 1;
|
||||||
|
$counter = 0;
|
||||||
foreach ($list as $i => $item) {
|
foreach ($list as $i => $item) {
|
||||||
$r .= $item;
|
$return .= $item;
|
||||||
if ($c > 0 && $i < $c) {
|
if ($count > 0 && $counter < $count) {
|
||||||
$r .= ($i < $c - 1 ? ', ' : " {$and} ");
|
$return .= ($counter < $count - 1 ? ', ' : " {$and} ");
|
||||||
}
|
}
|
||||||
|
$counter++;
|
||||||
}
|
}
|
||||||
return $r;
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -362,6 +362,9 @@ class TextHelperTest extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y');
|
$result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y');
|
||||||
$this->assertEqual($result, 'Dusty, Lucky y Ned');
|
$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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue