[Console] Fix disabling ChoiceQuestion answer trimming
This commit is contained in:
parent
119ac78792
commit
44ee0569bb
@ -135,9 +135,15 @@ class ChoiceQuestion extends Question
|
||||
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
|
||||
}
|
||||
|
||||
$selectedChoices = array_map('trim', explode(',', $selected));
|
||||
$selectedChoices = explode(',', $selected);
|
||||
} else {
|
||||
$selectedChoices = [trim($selected)];
|
||||
$selectedChoices = [$selected];
|
||||
}
|
||||
|
||||
if ($this->isTrimmable()) {
|
||||
foreach ($selectedChoices as $k => $v) {
|
||||
$selectedChoices[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
|
||||
$multiselectChoices = [];
|
||||
|
@ -61,4 +61,20 @@ class ChoiceQuestionTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testNonTrimmable()
|
||||
{
|
||||
$question = new ChoiceQuestion('A question', [
|
||||
'First response ',
|
||||
' Second response',
|
||||
' Third response ',
|
||||
]);
|
||||
$question->setTrimmable(false);
|
||||
|
||||
$this->assertSame(' Third response ', $question->getValidator()(' Third response '));
|
||||
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertSame(['First response ', ' Second response'], $question->getValidator()('First response , Second response'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user