You are here

public function ShortAnswerTestCase::testGradeAnswerRegex in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 question_types/short_answer/short_answer.test \ShortAnswerTestCase::testGradeAnswerRegex()

Test regex graded questions.

File

question_types/short_answer/short_answer.test, line 97
Unit tests for the short_answer Module.

Class

ShortAnswerTestCase
Test class for short answer.

Code

public function testGradeAnswerRegex() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->drupalCreateQuiz();
  $question_node = $this
    ->testCreateQuizQuestion(array(
    'correct_answer_evaluation' => ShortAnswerQuestion::ANSWER_REGEX,
    'correct_answer' => '/Zero One Infinity/i',
  ));
  $this
    ->linkQuestionToQuiz($question_node, $quiz_node);

  // Test incorrect.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer]" => 'um some rule, I forget',
  ), t('Finish'));
  $this
    ->assertText('Your score: 0%');

  // Test correct.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer]" => 'the answer is the zero one infinity rule',
  ), t('Finish'));
  $this
    ->assertText('Your score: 100%');
}