private function PollVoteJavascriptTest::pollGenerateEdit in Poll 8
Generates POST values for the poll node form, specifically poll choices.
Parameters
string $question: The poll question.
array $choices: An array containing poll choices, as generated by PollTestBase::generateChoices().
int $index: (optional) The amount/number of already submitted poll choices. Defaults to 0.
Return value
array An indexed array containing:
- The generated POST values, suitable for Drupal\simpletest\WebTestBase::drupalPostForm().
- The number of poll choices contained in 'edit', for potential re-usage in subsequent invocations of this function.
1 call to PollVoteJavascriptTest::pollGenerateEdit()
- PollVoteJavascriptTest::pollCreate in tests/
src/ FunctionalJavascript/ PollVoteJavascriptTest.php - Creates a poll.
File
- tests/
src/ FunctionalJavascript/ PollVoteJavascriptTest.php, line 146
Class
- PollVoteJavascriptTest
- Tests voting on a poll using Javascript.
Namespace
Drupal\Tests\poll\FunctionalJavascriptCode
private function pollGenerateEdit($question, array $choices, $index = 0) {
$max_new_choices = 1;
$already_submitted_choices = array_slice($choices, 0, $index);
$new_choices = array_values(array_slice($choices, $index, $max_new_choices));
$edit = [
'question[0][value]' => $question,
];
foreach ($already_submitted_choices as $k => $text) {
$edit['choice[' . $k . '][choice]'] = $text;
}
foreach ($new_choices as $k => $text) {
$edit['choice[' . $k . '][choice]'] = $text;
}
return [
$edit,
count($already_submitted_choices) + count($new_choices),
];
}