protected function AdvPollTestBase::createPoll in Advanced Poll 7.3
Generate a advpoll node.
@returns The poll node.
Parameters
int $total_choices: Optional. The total number of choices in the poll.
int $max_choices: Optional. The maximum number of choices a user may select.
string $results: Optional. If and when to display poll results.
- 'aftervote': Display the results after the user votes.
- 'afterclose': Display results only after closing the poll.
- 'never': Never display the results to users.
string $status: Optional. The status of the poll. Must be one of the following:
- 'open': The poll is open and accepting votes.
- 'closed': The poll is closed and not accepting votes.
1 call to AdvPollTestBase::createPoll()
File
- tests/
AdvPollTestBase.test, line 91 - Advanced Poll Test Base.
Class
- AdvPollTestBase
- @file Advanced Poll Test Base.
Code
protected function createPoll($total_choices = 5, $max_choices = 1, $results = 'aftervote', $status = 'open') {
// Generate some poll choices.
$options = array();
for ($i = 0; $i < $total_choices; $i++) {
$options[] = $this
->randomName();
}
$poll_node = new stdClass();
// Information for base node
$poll_node->type = 'advpoll';
$poll_node->uid = $this->admin->uid;
$poll_node->status = 1;
$poll_node->is_new = TRUE;
$poll_node->promote = 1;
$poll_node->sticky = 0;
$poll_node->title = $this
->randomName(16);
$poll_node->comment = 0;
$poll_node->active = 1;
$poll_node->language = LANGUAGE_NONE;
// Loop through the options and create them
foreach ($options as $option) {
$poll_node->advpoll_choice[LANGUAGE_NONE][] = array(
// Random id (uses the same method as the module) - advpoll_node_presave ensure it's unique
'choice_id' => dechex(time() * rand(5, 50)),
'choice' => $option,
'write_in' => 0,
);
}
// Set some additional poll options.
$poll_node->advpoll_max_choices[LANGUAGE_NONE][0]['value'] = $max_choices;
$poll_node->advpoll_closed[LANGUAGE_NONE][0]['value'] = $status;
$poll_node->advpoll_results[LANGUAGE_NONE][0]['value'] = $results;
// Save the new poll.
node_save($poll_node);
// Return the node.
return $poll_node;
}