public function QuizTakingTestCase::testChangeAnswer in Quiz 7.5
Same name and namespace in other branches
- 7.6 tests/QuizTakingTestCase.test \QuizTakingTestCase::testChangeAnswer()
Test allow/restrict changing of answers.
File
- tests/
QuizTakingTestCase.test, line 231
Class
Code
public function testChangeAnswer() {
$quiz_node = $this
->drupalCreateQuiz(array(
'review_options' => array(
'question' => array(
'score' => 'score',
),
),
));
$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);
// Answer incorrectly.
$this
->drupalLogin($this->user);
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalGet("node/{$quiz_node->nid}/take/1");
$this
->drupalPost(NULL, array(
"question[{$question_node1->nid}][answer]" => 0,
), t('Next'));
$this
->assertText('Score: 0 of 1');
// Go back and correct the answer.
$this
->drupalGet("node/{$quiz_node->nid}/take/1");
$this
->drupalPost(NULL, array(
"question[{$question_node1->nid}][answer]" => 1,
), t('Next'));
$this
->assertText('Score: 1 of 1');
// Go back and incorrect the answer.
$this
->drupalGet("node/{$quiz_node->nid}/take/1");
$this
->drupalPost(NULL, array(
"question[{$question_node1->nid}][answer]" => 0,
), t('Next'));
$this
->assertText('Score: 0 of 1');
// Restrict change after answer. Turn auto revisioning off since we need to
// operate on the same result.
variable_set('quiz_auto_revisioning', 0);
$quiz_node->allow_change = 0;
node_save($quiz_node);
// Check that the answer cannot be changed.
$this
->drupalGet("node/{$quiz_node->nid}/take/1");
$disabled_field = $this
->xpath('//input[@id=:id and @disabled="disabled"]', array(
':id' => 'edit-question-2-answer-1',
));
$this
->assertTrue($disabled_field, t('The answer cannot be changed.'));
$this
->drupalPost(NULL, array(), t('Next'));
$this
->assertText('Score: 0 of 1');
// Check allow change/blank behavior.
$this
->drupalGet("node/{$quiz_node->nid}/take/2");
$this
->drupalPost(NULL, array(), t('Leave blank'));
$this
->drupalGet("node/{$quiz_node->nid}/take/2");
$disabled_field = $this
->xpath('//input[@id=:id and @disabled="disabled"]', array(
':id' => 'edit-question-3-answer-1',
));
$this
->assertTrue($disabled_field, t('The blank answer cannot be changed.'));
$quiz_node->allow_change_blank = 1;
node_save($quiz_node);
$this
->drupalGet("node/{$quiz_node->nid}/take/2");
$disabled_field = $this
->xpath('//input[@id=:id and @disabled="disabled"]', array(
':id' => 'edit-question-3-answer-1',
));
$this
->assertFalse($disabled_field, t('The blank answer can be changed.'));
}