public function PollKernelTestBase::createPoll in Poll 8
Creates and saves a poll.
Parameters
int $choice_count: (optional) The number of choices to generate. Defaults to 7.
Return value
\Drupal\poll\PollInterface A poll.
2 calls to PollKernelTestBase::createPoll()
- PollResultsTest::testPollResults in tests/
src/ Kernel/ PollResultsTest.php - Tests results generation for Polls.
- PollVoteStorageTest::testGetUserVote in tests/
src/ Kernel/ PollVoteStorageTest.php - @covers ::getUserVote
File
- tests/
src/ Kernel/ PollKernelTestBase.php, line 39
Class
- PollKernelTestBase
- Base class for Poll Kernel tests.
Namespace
Drupal\Tests\poll\KernelCode
public function createPoll($choice_count = 2) {
/** @var \Drupal\poll\PollInterface $poll */
$poll = Poll::create([
'question' => $this
->randomMachineName(),
]);
$poll_choice_ids = [];
for ($i = 1; $i <= $choice_count; $i++) {
$poll_choice = PollChoice::create([
'choice' => $this
->randomMachineName(),
]);
$poll_choice
->save();
$poll_choice_ids[] = $poll_choice
->id();
}
$poll
->set('anonymous_vote_allow', TRUE)
->set('choice', $poll_choice_ids)
->save();
return $poll;
}