public function QuizTakingTestCase::testQuestionRepeatUntilCorrect in Quiz 7.5
Same name and namespace in other branches
- 7.6 tests/QuizTakingTestCase.test \QuizTakingTestCase::testQuestionRepeatUntilCorrect()
Test the repeat until correct behavior.
We also test that the answer is passed to feedback before being discarded.
File
- tests/
QuizTakingTestCase.test, line 25
Class
Code
public function testQuestionRepeatUntilCorrect() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->drupalCreateQuiz(array(
'repeat_until_correct' => 1,
'review_options' => array(
'question' => array(
'answer_feedback' => 'answer_feedback',
),
),
));
$settings = array();
$settings['alternatives'][0]['answer']['value'] = 'A';
$settings['alternatives'][0]['answer']['format'] = 'filtered_html';
$settings['alternatives'][0]['feedback_if_chosen']['value'] = 'You chose A';
$settings['alternatives'][0]['feedback_if_chosen']['format'] = 'filtered_html';
$settings['alternatives'][0]['feedback_if_not_chosen']['value'] = '';
$settings['alternatives'][0]['feedback_if_not_chosen']['format'] = '';
$settings['alternatives'][0]['score_if_chosen'] = 1;
$settings['alternatives'][0]['score_if_not_chosen'] = 0;
$settings['alternatives'][1]['answer']['value'] = 'B';
$settings['alternatives'][1]['answer']['format'] = 'filtered_html';
$settings['alternatives'][1]['feedback_if_chosen']['value'] = 'You chose B';
$settings['alternatives'][1]['feedback_if_chosen']['format'] = 'filtered_html';
$settings['alternatives'][1]['feedback_if_not_chosen']['value'] = '';
$settings['alternatives'][1]['feedback_if_not_chosen']['format'] = '';
$settings['alternatives'][1]['score_if_chosen'] = 0;
$settings['alternatives'][1]['score_if_not_chosen'] = 0;
$settings['type'] = 'multichoice';
$question_node = $this
->drupalCreateNode($settings + array(
'choice_multi' => 0,
'choice_random' => 0,
'choice_boolean' => 0,
));
$this
->linkQuestionToQuiz($question_node, $quiz_node);
$this
->drupalLogin($this->user);
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost(NULL, array(
"question[{$question_node->nid}][answer][user_answer]" => 2,
), t('Finish'));
$this
->assertText('The answer was incorrect. Please try again.');
$this
->assertText('You chose B');
// Check that we are still on the question.
$this
->assertUrl("node/{$quiz_node->nid}/take/1");
$this
->drupalPost(NULL, array(
"question[{$question_node->nid}][answer][user_answer]" => 1,
), t('Finish'));
$this
->assertNoText('The answer was incorrect. Please try again.');
}