You are here

public function ShortAnswerTestCase::testGradeAnswerManualFeedback in Quiz 7.5

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

Test manually graded questions.

Note: we use two questions here to make sure the grading form is handled correctly.

File

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

Class

ShortAnswerTestCase
Test class for short answer.

Code

public function testGradeAnswerManualFeedback() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->drupalCreateQuiz();
  $question_node1 = $this
    ->testCreateQuizQuestion(array(
    'correct_answer_evaluation' => ShortAnswerQuestion::ANSWER_MANUAL,
    'correct_answer' => 'the Zero One Infinity rule',
  ));
  $this
    ->linkQuestionToQuiz($question_node1, $quiz_node);
  $question_node2 = $this
    ->testCreateQuizQuestion(array(
    'correct_answer_evaluation' => ShortAnswerQuestion::ANSWER_MANUAL,
    'correct_answer' => 'The number two is ridiculous and cannot exist',
  ));
  $this
    ->linkQuestionToQuiz($question_node2, $quiz_node);

  // Test correct.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node1->nid}][answer]" => 'the answer is the zero one infinity rule',
  ), t('Next'));
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node2->nid}][answer]" => 'the number two really is ridiculous',
  ), t('Finish'));
  $this
    ->assertText('Your score: 0%');

  // Strange behavior - extra spaces in HTML.

  //$this->assertText('Score ? of 10');
  $this
    ->assertText('This answer has not yet been scored.');
  $this
    ->assertNoFieldByName('question[0][score]');
  $this
    ->assertNoFieldByName('question[1][score]');
  $this
    ->assertNoFieldByName('question[0][answer_feedback][value]');
  $this
    ->assertNoFieldByName('question[1][answer_feedback][value]');
  $this
    ->assertNoRaw(t('Save score'));
  $url_of_result = $this
    ->getUrl();
  $admin_url_of_result = preg_replace('#quiz-results/(\\d+)#', 'quiz/results/$1', $this
    ->getUrl());

  // Test grading the question.
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet($admin_url_of_result);
  $this
    ->assertFieldByName('question[0][score]');
  $this
    ->assertFieldByName('question[1][score]');
  $this
    ->drupalPost(NULL, array(
    "question[0][score]" => 2,
    "question[1][score]" => 3,
    "question[0][answer_feedback][value]" => 'Feedback for answer 1.',
    "question[1][answer_feedback][value]" => 'Feedback for answer 2.',
    "question[0][answer_feedback][format]" => 'filtered_html',
    "question[1][answer_feedback][format]" => 'filtered_html',
  ), t('Save score'));
  $this
    ->assertText('The scoring data you provided has been saved.');

  // Test the score is visible to the user.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet($url_of_result);
  $this
    ->assertText('You got 5 of 10 possible points.');
  $this
    ->assertText('Your score: 50%');

  // Strange behavior - extra spaces in HTML.

  //$this->assertText('Score 2 of 5');

  //$this->assertText('Score 3 of 5');
  $this
    ->assertText('Feedback for answer 1.');
  $this
    ->assertText('Feedback for answer 2.');
}