예제 #1
0
 /**
  * Tests for log entry on failing destination.
  */
 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.');
 }
예제 #2
0
 /**
  * Asserts that two files have the same values (except timestamp).
  *
  * @param \Drupal\file\FileInterface $before
  *   File object to compare.
  * @param \Drupal\file\FileInterface $after
  *   File object to compare.
  */
 function assertFileUnchanged(FileInterface $before, FileInterface $after)
 {
     $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged');
     $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged');
     $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged');
     $this->assertEqual($before->getFileUri(), $after->getFileUri(), t('File path is the same: %file1 == %file2.', array('%file1' => $before->getFileUri(), '%file2' => $after->getFileUri())), 'File unchanged');
     $this->assertEqual($before->getMimeType(), $after->getMimeType(), t('File MIME type is the same: %file1 == %file2.', array('%file1' => $before->getMimeType(), '%file2' => $after->getMimeType())), 'File unchanged');
     $this->assertEqual($before->getSize(), $after->getSize(), t('File size is the same: %file1 == %file2.', array('%file1' => $before->getSize(), '%file2' => $after->getSize())), 'File unchanged');
     $this->assertEqual($before->isPermanent(), $after->isPermanent(), t('File status is the same: %file1 == %file2.', array('%file1' => $before->isPermanent(), '%file2' => $after->isPermanent())), 'File unchanged');
 }
예제 #3
0
 /**
  * Validate and set destination the destination URI.
  *
  * @param \Drupal\file\FileInterface $file
  *   The file entity object.
  * @param string $destination
  *   A string containing the URI that the file should be copied to. This must
  *   be a stream wrapper URI.
  *
  * @return bool
  *   True if the destination was sucesfully validated and set, otherwise
  *   false.
  */
 protected function prepareDestination(FileInterface $file, $destination)
 {
     // Assert that the destination contains a valid stream.
     $destination_scheme = file_uri_scheme($destination);
     if (!file_stream_wrapper_valid_scheme($destination_scheme)) {
         return FALSE;
     }
     // Prepare the destination dir.
     if (!file_exists($destination)) {
         $this->fileSystem->mkdir($destination);
     }
     // A file URI may already have a trailing slash or look like "public://".
     if (substr($destination, -1) != '/') {
         $destination .= '/';
     }
     $file->destination = file_destination($destination . $file->getFilename(), FILE_EXISTS_RENAME);
     $file->setFileUri($file->destination);
     return TRUE;
 }