public function QuizFileUploadTestCase::testFilesizeValidation in Quiz File Upload 7.5
Test filesize validation.
File
- tests/
quizfileupload.test, line 189 - Unit tests for the quizfileupload Module.
Class
- QuizFileUploadTestCase
- Test class for the file upload question type.
Code
public function testFilesizeValidation() {
// Login as our privileged user.
$this
->drupalLogin($this->admin);
// Create file objects.
$small_file = $this
->getTestFile('text', 131072);
$large_file = $this
->getTestFile('text', 1310720);
// Create the quiz with a fileupload question.
$quiz_node = $this
->drupalCreateQuiz();
$question_node = $this
->testCreateQuizQuestion(array(
'filetypes' => 'txt',
'filesize' => '1MB',
'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 uploading a small file.
$this
->drupalPost('node/' . $quiz_node->nid . '/take', array(
'files[question_' . $question_node->nid . '_answer]' => drupal_realpath($small_file->uri),
), t('Finish'));
$this
->assertText('Your score: 100%');
// Test uploading a file which is to large.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost('node/' . $quiz_node->nid . '/take', array(
'files[question_' . $question_node->nid . '_answer]' => drupal_realpath($large_file->uri),
), t('Finish'));
$this
->assertText('You must upload a file.');
}