function QuizRandomTestCase::testRandomOrderInPages in Quiz 7.6
Same name and namespace in other branches
- 7.5 tests/QuizRandomTestCase.test \QuizRandomTestCase::testRandomOrderInPages()
Test that questions inside of pages are shuffled.
File
- tests/
QuizRandomTestCase.test, line 281
Class
- QuizRandomTestCase
- Tests for random questions.
Code
function testRandomOrderInPages() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->drupalCreateQuiz(array(
'randomization' => 1,
));
// Create the questions.
$question_node1 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'TF 1 body text',
),
),
),
));
$this
->linkQuestionToQuiz($question_node1, $quiz_node);
// QNR ID 1
$question_node2 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'TF 2 body text',
),
),
),
));
$this
->linkQuestionToQuiz($question_node2, $quiz_node);
// QNR ID 2
$question_node3 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'TF 3 body text',
),
),
),
));
$this
->linkQuestionToQuiz($question_node3, $quiz_node);
// QNR ID 3
// Create the pages.
$page_node1 = $this
->drupalCreateNode(array(
'type' => 'quiz_page',
));
$this
->linkQuestionToQuiz($page_node1, $quiz_node);
// QNR ID 4
$page_node2 = $this
->drupalCreateNode(array(
'type' => 'quiz_page',
));
$this
->linkQuestionToQuiz($page_node2, $quiz_node);
// QNR ID 5
// Go to the manage questions form.
$this
->drupalGet("node/{$quiz_node->nid}/quiz/questions");
$post = array(
// Make the questions have parents.
"qnr_pids[{$question_node1->nid}-{$question_node1->vid}]" => 4,
"qnr_pids[{$question_node2->nid}-{$question_node2->vid}]" => 4,
"qnr_pids[{$question_node3->nid}-{$question_node3->vid}]" => 5,
// Mirror what JS would have done by adjusting the weights.
"weights[{$page_node1->nid}-{$page_node1->vid}]" => 2,
"weights[{$question_node1->nid}-{$question_node1->vid}]" => 3,
"weights[{$question_node2->nid}-{$question_node2->vid}]" => 4,
"weights[{$page_node2->nid}-{$page_node2->vid}]" => 3,
"weights[{$question_node3->nid}-{$question_node3->vid}]" => 4,
);
$this
->drupalPost(NULL, $post, t('Submit'));
for ($i = 1; $i <= 5; $i++) {
$questions = quiz_build_question_list($quiz_node);
$out[$i] = '';
foreach ($questions as $question) {
$out[$i] .= $question['nid'];
}
}
// Check that at least one of the orders is different.
$this
->assertNotEqual(count(array_unique($out)), 1, t('At least one set of questions was different.'));
// Start the quiz.
$this
->drupalLogin($this->user);
$this
->drupalGet("node/{$quiz_node->nid}");
}