You are here

function QuizCreationTestCase::testQuizRevisioning in Quiz 7.6

Same name and namespace in other branches
  1. 7.5 tests/QuizCreationTestCase.test \QuizCreationTestCase::testQuizRevisioning()

Test quiz revisioning.

File

tests/QuizCreationTestCase.test, line 114
Unit tests for the quiz question Module.

Class

QuizCreationTestCase
Test aspects of quiz creation including global and user defaults.

Code

function testQuizRevisioning() {
  $this
    ->drupalLogin($this->admin);
  $question_node = $this
    ->drupalCreateNode(array(
    'title' => 'Revision 1',
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Revision 1',
        ),
      ),
    ),
    'type' => 'truefalse',
    'correct_answer' => 1,
  ));
  $quiz_node = $this
    ->linkQuestionToQuiz($question_node);

  // Set feedback.
  $entities = entity_load('quiz_question', FALSE, array(
    'nid' => $question_node->nid,
    'vid' => $question_node->vid,
  ));
  $quiz_question = reset($entities);
  $quiz_question->feedback = 'Question feedback for Revision 1';
  $quiz_question->feedback_format = filter_default_format();
  entity_save('quiz_question', $quiz_question);

  // Check for first revision.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText("Revision 1");

  // Update question. There are already attempts now so we expect a new
  // revision.
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet("node/{$question_node->nid}/edit");
  $this
    ->drupalPost(NULL, array(
    'title' => 'Revision 2',
    'body[und][0][value]' => 'Revision 2',
    'correct_answer' => 0,
    'feedback[value]' => 'Question feedback for Revision 2',
  ), t('Save'));

  // Finish on same revision.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText("Revision 1");
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer]" => 1,
  ), t('Finish'));
  $this
    ->assertText('You got 1 of 1 possible points.');
  $this
    ->assertText('Question feedback for Revision 1');

  // Take quiz again. Should be on SAME revision. We have not yet updated the
  // Quiz.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText("Revision 1");

  // Update the quiz to use the latest revision.
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet("node/{$quiz_node->nid}/quiz/questions");
  $this
    ->drupalPost(NULL, array(
    "revision[{$question_node->nid}-{$question_node->vid}]" => TRUE,
  ), t('Submit'));

  // Take quiz again. Should be on SAME revision. We have not yet finished
  // this attempt.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText("Revision 1");

  // Finish the attempt.
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer]" => 1,
  ), t('Finish'));
  $this
    ->assertText('You got 1 of 1 possible points.');
  $this
    ->assertText('Question feedback for Revision 1');

  // Take quiz again we should be on the new result, finally.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText("Revision 2");

  // Finish the attempt.
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer]" => 1,
  ), t('Finish'));
  $this
    ->assertText('You got 0 of 1 possible points.');
  $this
    ->assertText('Question feedback for Revision 2');
}