mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing issue where value of '$and' was appended to output string even when list array contained only one element. Fixed #285
This commit is contained in:
parent
3f9813a9ec
commit
59a4732eb8
2 changed files with 11 additions and 1 deletions
|
@ -336,7 +336,11 @@ class TextHelper extends AppHelper {
|
|||
* @access public
|
||||
*/
|
||||
function toList($list, $and = 'and', $separator = ', ') {
|
||||
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
|
||||
if (count($list) > 1) {
|
||||
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
|
||||
} else {
|
||||
return array_pop($list);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -355,6 +355,12 @@ class TextHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testListGeneration() {
|
||||
$result = $this->Text->toList(array());
|
||||
$this->assertEqual($result, '');
|
||||
|
||||
$result = $this->Text->toList(array('One'));
|
||||
$this->assertEqual($result, 'One');
|
||||
|
||||
$result = $this->Text->toList(array('Larry', 'Curly', 'Moe'));
|
||||
$this->assertEqual($result, 'Larry, Curly and Moe');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue