function PollTestBase::pollCreate in Poll 8
Creates a poll.
Parameters
int $choice_count: (optional) The number of choices to generate. Defaults to 7.
\Drupal\user\UserInterface $account: (optional) Poll creator user. Defaults to NULL, then use $this->admin_user.
boolean $preview: (optional) Whether to test if the preview is working or not. Defaults to TRUE.
Return value
mixed The created poll entity, or FALSE on error.
6 calls to PollTestBase::pollCreate()
- PollCreateTest::testwithRestrictedUser in tests/
src/ Functional/ PollCreateTest.php - Poll create with restricted user.
- PollListTest::testViewListPolls in tests/
src/ Functional/ PollListTest.php - Test if a list of polls is displayed properly.
- PollTestBase::setUp in tests/
src/ Functional/ PollTestBase.php - PollTokenReplaceTest::testPollTokenReplacement in tests/
src/ Functional/ PollTokenReplaceTest.php - Creates a poll, then tests the tokens generated from it.
- PollVoteMultilingualTest::setUp in tests/
src/ Functional/ PollVoteMultilingualTest.php
File
- tests/
src/ Functional/ PollTestBase.php, line 92
Class
- PollTestBase
- Defines a base class for testing the Poll module.
Namespace
Drupal\Tests\poll\FunctionalCode
function pollCreate($choice_count = 7, $account = NULL, $preview = TRUE) {
if (!$account) {
$this
->drupalLogin($this->admin_user);
}
else {
$this
->drupalLogin($account);
}
// Get the form first to initialize the state of the internal browser.
$this
->drupalGet('poll/add');
$question = $this
->randomMachineName();
$choices = $this
->generateChoices($choice_count);
list($edit, $index) = $this
->pollGenerateEdit($question, $choices);
// Re-submit the form until all choices are filled in.
if (count($choices) > 0) {
for ($delta = 0; $delta <= count($choices); $delta++) {
$this
->drupalPostForm(NULL, $edit, t('Add another item'));
list($edit, $index) = $this
->pollGenerateEdit($question, $choices, $index);
}
}
// if ($preview) {
// $this->drupalPostForm('poll/add', $edit, t('Preview'));
// $this->assertPollChoiceOrder($choices, $index, TRUE);
// list($edit, $index) = $this->pollGenerateEdit($title, $choices, $index);
// }
$this
->drupalPostForm(NULL, $edit, t('Save'));
// Load the first poll returned from the database.
$polls = \Drupal::entityTypeManager()
->getStorage('poll')
->loadByProperties(array(
'question' => $question,
));
$poll = reset($polls);
$this
->assertText(t('The poll @question has been added.', array(
'@question' => $question,
)));
$this
->assertInstanceOf(PollInterface::class, $poll);
return $poll instanceof PollInterface ? $poll : FALSE;
}