public function QuizFileUploadTestCase::testAutomaticallyGradeAnswer in Quiz File Upload 7.5
Test automatically graded questions.
File
- tests/
quizfileupload.test, line 66 - Unit tests for the quizfileupload Module.
Class
- QuizFileUploadTestCase
- Test class for the file upload question type.
Code
public function testAutomaticallyGradeAnswer() {
// Login as our privileged user.
$this
->drupalLogin($this->admin);
// Create file objects.
$text_file = $this
->getTestFile('text');
$image_file = $this
->getTestFile('image');
// Create the quiz with a fileupload question.
$quiz_node = $this
->drupalCreateQuiz();
$question_node = $this
->testCreateQuizQuestion(array(
'filetypes' => 'txt',
'correct_answer_evaluation' => QuizfileuploadQuestion::ANSWER_MATCH,
));
$this
->linkQuestionToQuiz($question_node, $quiz_node);
// Update the default max score for each question.
$this
->drupalPost('node/' . $quiz_node->nid . '/quiz/questions', array(
'max_scores[' . $question_node->nid . '-' . $question_node->vid . ']' => 5,
), t('Submit'));
// Test with a correct file extension.
$this
->drupalPost('node/' . $quiz_node->nid . '/take', array(
'files[question_' . $question_node->nid . '_answer]' => drupal_realpath($text_file->uri),
), t('Finish'));
$this
->assertText('Your score: 100%');
// Test with a wrong file extension.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost('node/' . $quiz_node->nid . '/take', array(
'files[question_' . $question_node->nid . '_answer]' => drupal_realpath($image_file->uri),
), t('Finish'));
$this
->assertText('The specified file image-test.png could not be uploaded. Only files with the following extensions are allowed: txt.');
// Test without a file.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost('node/' . $quiz_node->nid . '/take', array(), t('Finish'));
$this
->assertText('You must upload a file.');
// Test skipping the question.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost('node/' . $quiz_node->nid . '/take', array(), t('Leave blank and finish'));
$this
->assertText('Your score: 0%');
}