You are here

function SaveUploadTest::testDrupalMovingUploadedFileError in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/SaveUploadTest.php \Drupal\file\Tests\SaveUploadTest::testDrupalMovingUploadedFileError()

Tests for log entry on failing destination.

File

core/modules/file/src/Tests/SaveUploadTest.php, line 341
Contains \Drupal\file\Tests\SaveUploadTest.

Class

SaveUploadTest
Tests the file_save_upload() function.

Namespace

Drupal\file\Tests

Code

function testDrupalMovingUploadedFileError() {

  // Create a directory and make it not writable.
  $test_directory = 'test_drupal_move_uploaded_file_fail';
  drupal_mkdir('temporary://' . $test_directory, 00);
  $this
    ->assertTrue(is_dir('temporary://' . $test_directory));
  $edit = array(
    'file_subdir' => $test_directory,
    'files[file_test_upload]' => drupal_realpath($this->image
      ->getFileUri()),
  );
  \Drupal::state()
    ->set('file_test.disable_error_collection', TRUE);
  $this
    ->drupalPostForm('file-test/upload', $edit, t('Submit'));
  $this
    ->assertResponse(200, 'Received a 200 response for posted test file.');
  $this
    ->assertRaw(t('File upload error. Could not move uploaded file.'), 'Found the failure message.');
  $this
    ->assertRaw(t('Epic upload FAIL!'), 'Found the failure message.');

  // Uploading failed. Now check the log.
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertResponse(200);
  $this
    ->assertRaw(t('Upload error. Could not move uploaded file @file to destination @destination.', array(
    '@file' => $this->image
      ->getFilename(),
    '@destination' => 'temporary://' . $test_directory . '/' . $this->image
      ->getFilename(),
  )), 'Found upload error log entry.');
}