[Console] Fixed different behaviour of key and value user inputs in multiple choice question
This commit is contained in:
parent
c4abc1566d
commit
2861bd7b01
@ -135,7 +135,7 @@ class ChoiceQuestion extends Question
|
||||
|
||||
if ($multiselect) {
|
||||
// Check for a separated comma values
|
||||
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
|
||||
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
|
||||
throw new \InvalidArgumentException(sprintf($errorMessage, $selected));
|
||||
}
|
||||
$selectedChoices = explode(',', $selectedChoices);
|
||||
|
@ -273,6 +273,37 @@ class QuestionHelperTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider specialCharacterInMultipleChoice
|
||||
*/
|
||||
public function testSpecialCharacterChoiceFromMultipleChoiceList($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'.',
|
||||
'src',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the directory', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
public function specialCharacterInMultipleChoice()
|
||||
{
|
||||
return array(
|
||||
array('.', array('.')),
|
||||
array('., src', array('.', 'src')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mixedKeysChoiceListAnswerProvider
|
||||
*/
|
||||
|
Reference in New Issue
Block a user