bug #32781 [Console] Fix disabling ChoiceQuestion answer trimming (chalasr)
This PR was merged into the 4.4 branch.
Discussion
----------
[Console] Fix disabling ChoiceQuestion answer trimming
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
44ee0569bb
[Console] Fix disabling ChoiceQuestion answer trimming
This commit is contained in:
commit
a29aff0370
@ -135,9 +135,15 @@ class ChoiceQuestion extends Question
|
|||||||
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
|
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectedChoices = array_map('trim', explode(',', $selected));
|
$selectedChoices = explode(',', $selected);
|
||||||
} else {
|
} else {
|
||||||
$selectedChoices = [trim($selected)];
|
$selectedChoices = [$selected];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isTrimmable()) {
|
||||||
|
foreach ($selectedChoices as $k => $v) {
|
||||||
|
$selectedChoices[$k] = trim($v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$multiselectChoices = [];
|
$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