You are here

public function LongAnswerTestCase::testGradeAnswerManualFeedback in Quiz 7.6

Same name and namespace in other branches
  1. 7.5 question_types/long_answer/long_answer.test \LongAnswerTestCase::testGradeAnswerManualFeedback()

Test manually graded questions. Also test feedback here instead of its own test case.

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

File

question_types/long_answer/long_answer.test, line 34
Unit tests for the long_answer Module.

Class

LongAnswerTestCase
Test class for long answer.

Code

public function testGradeAnswerManualFeedback() {
  $this
    ->drupalLogin($this->admin);
  $question_node1 = $this
    ->testCreateQuizQuestion();
  $quiz_node = $this
    ->linkQuestionToQuiz($question_node1);
  $question_node2 = $this
    ->testCreateQuizQuestion();
  $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 spacing in the HTML.

  //$this->assertText('Score ? of 10');
  $this
    ->assertText('This answer has not yet been scored.');
  $this
    ->assertNoFieldByName('0[score]');
  $this
    ->assertNoFieldByName('1[score]');
  $url_of_result = $this
    ->getUrl();

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

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

  // Strange behavior - extra spacing in the HTML.

  //$this->assertText('Score 3 of 10');

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