You are here

function QuestionsImportTestCase::shortanswerHelper in Quiz 6.6

2 calls to QuestionsImportTestCase::shortanswerHelper()
QuestionsImportTestCase::testAikenShortAnswer in includes/questions_import/questions_import.test
QuestionsImportTestCase::testCsvShortAnswer in includes/questions_import/questions_import.test

File

includes/questions_import/questions_import.test, line 407

Class

QuestionsImportTestCase

Code

function shortanswerHelper($import_type) {
  $import_questions = array();
  switch ($import_type) {
    case 'aiken':
      $import_settings['import_type'] = 'native_aiken';
      $filetype = '.txt';
      break;
    case 'csv':
      $import_settings['import_type'] = 'native_csv';
      $filetype = '.csv';
      break;
  }
  $filepath = file_create_filename($import_type . '_shortanswer' . $filetype, file_directory_temp());
  $handle = fopen($filepath, "w+");
  for ($i = 0; $i < 20; $i++) {
    $question = new stdClass();
    $question->answer = "The answer is {$i}.";
    $question->question = "Question #{$i}:";
    $question->type = "short_answer";
    $question->value = mt_rand(1, 5);
    $question->sat = mt_rand(0, 3);
    switch ($question->sat) {
      case 0:
        $question->shortanswertype = "case sensitive match";
        break;
      case 1:
        $question->shortanswertype = "case insensitive match";
        break;
      case 2:
        $question->shortanswertype = "regular expression match";
        break;
      case 3:
        $question->shortanswertype = "manually score match";
        break;
    }
    $write = $this
      ->writeImport($import_type, $question);
    fwrite($handle, $write);
    $import_questions[] = $question;
  }
  fclose($handle);
  $import_settings['quiz_node'] = '1';
  $import_settings['field_separator'] = ',';
  $import_settings['files[upload]'] = $filepath;
  $msg = $this
    ->drupalPost('admin/quiz/questions_import', $import_settings, 'Import');
  $this
    ->assertPattern('/20 questions were imported successfully/', t('Checking import success message'));
  $this
    ->quizHelper($import_questions);
}