You are here

private function PollTestBase::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:

1 call to PollTestBase::pollGenerateEdit()
PollTestBase::pollCreate in tests/src/Functional/PollTestBase.php
Creates a poll.

File

tests/src/Functional/PollTestBase.php, line 154

Class

PollTestBase
Defines a base class for testing the Poll module.

Namespace

Drupal\Tests\poll\Functional

Code

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 = array(
    '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 array(
    $edit,
    count($already_submitted_choices) + count($new_choices),
  );
}