public function QuizNavigationTestCase::testQuestionNavigationBasic in Quiz 7.5
Same name and namespace in other branches
- 7.6 tests/QuizNavigationTestCase.test \QuizNavigationTestCase::testQuestionNavigationBasic()
Test the question navigation and access.
File
- tests/
QuizNavigationTestCase.test, line 29 - Unit tests for the quiz question Module.
Class
- QuizNavigationTestCase
- Base test class for Quiz questions.
Code
public function testQuestionNavigationBasic() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->drupalCreateQuiz();
// 3 questions.
$question_node1 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
));
$this
->linkQuestionToQuiz($question_node1, $quiz_node);
$question_node2 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
));
$this
->linkQuestionToQuiz($question_node2, $quiz_node);
$question_node3 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
));
$this
->linkQuestionToQuiz($question_node3, $quiz_node);
// Testing basic navigation. Ensure next questions are not yet available.
$this
->drupalLogin($this->user);
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalGet("node/{$quiz_node->nid}/take/1");
$this
->assertText("Page 1 of 3");
$this
->assertResponse(200);
$this
->drupalGet("node/{$quiz_node->nid}/take/2");
$this
->assertResponse(403);
$this
->drupalGet("node/{$quiz_node->nid}/take/3");
$this
->assertResponse(403);
// Answer a question, ensure next question is available.
$this
->drupalGet("node/{$quiz_node->nid}/take/1");
$this
->drupalPost(NULL, array(
"question[{$question_node1->nid}][answer]" => 1,
), t('Next'));
$this
->drupalGet("node/{$quiz_node->nid}/take/2");
$this
->assertText("Page 2 of 3");
$this
->assertResponse(200);
$this
->drupalGet("node/{$quiz_node->nid}/take/3");
$this
->assertResponse(403);
}