You are here

function QuestionsImportTestCase::answersHelper in Quiz 6.6

Compares import question with database question, checks that they match

Parameters

$import_q:

$db_q has nid, vid, type and body:

Return value

void

1 call to QuestionsImportTestCase::answersHelper()
QuestionsImportTestCase::quizHelper in includes/questions_import/questions_import.test
Loads a quiz and checks that it is behaving properly

File

includes/questions_import/questions_import.test, line 100

Class

QuestionsImportTestCase

Code

function answersHelper($import_q, $db_q) {
  $node_obj = (object) $db_q;
  switch ($import_q->type) {
    case 'multichoice':
      $mc = multichoice_load($node_obj);
      $this
        ->assertEqual(count($import_q->answers), count($mc->answers), "[multichoice] Matching number of options (expected " . count($import_q->answers) . ", got " . count($mc->answers) . ") " . print_r($mc, true) . print_r($db_q, true));
      foreach ($import_q->answers as $index => $import_answer) {
        $db_answer = $mc->answers[$index]['answer'];
        $this
          ->assertEqual($import_answer, $db_answer, "[multichoice] Matching option text (expected {$import_answer}, got {$db_answer})");
        if ($import_q->answer == $index) {
          $this
            ->assertEqual($mc->answers[$index]['is_correct'], 1, "[multichoice] Matching correct answer(s) (expected question answer to be correct)");
        }
        else {
          $this
            ->assertEqual($mc->answers[$index]['is_correct'], 0, "[multichoice] Matching incorrect answer(s) (expected question answer to be incorrect)");
        }
      }
      break;
    case 'true_false':
      $tf = quiz_question_load($node_obj);
      $correct = $tf->correct_answer == 0 ? 'false' : 'true';
      $this
        ->assertEqual($import_q->answer, $correct, "[true_false] Matching right answer (expected " . $import_q->answer . ", got " . $correct . ")");
      break;
    case 'short_answer':
      $sa = quiz_question_load($node_obj);
      $correct = $sa->correct_answer;
      $this
        ->assertEqual($import_q->answer, $correct, "[short_answer] Checking right answer (expected " . $import_q->answer . ", got " . $correct . ")" . print_r($sa, true));
      $this
        ->assertEqual($import_q->value, $sa->maximum_score, "[short_answer] Checking right score (expected " . $import_q->value . ", got " . $sa->maximum_score . ")");
      $this
        ->assertEqual($import_q->sat, $sa->correct_answer_evaluation, "[short_answer] Checking short answer evaluation type (expected " . $import_q->sat . " (i.e." . $import_q->shortanswertype . "), got " . $sa->correct_answer_evaluation . ")");
      break;
    case 'matching':
      $ma = quiz_question_load($node_obj);
      $ma = $ma['answer'];
      foreach ($import_q->matches as $index => $i_match) {
        $this
          ->assertEqual($i_match, $ma[$index]['question'], "[matching] Checking corresponding matches {$i_match}, {$ma[$index]['question']}");
        $this
          ->assertEqual($import_q->answers[$index], $ma[$index]['answer'], "[matching] Checking corresponding answers {$import_q->answers[$index]}, {$ma[$index]['answer']}");
      }
      break;
  }
}