FileDownloadTest::testPublicFileTransfer

7 file.test FileDownloadTest::testPublicFileTransfer()
8 file.test FileDownloadTest::testPublicFileTransfer()

Test the public file transfer system.

File

modules/simpletest/tests/file.test, line 2353
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Code

function testPublicFileTransfer() {
  // Test generating an URL to a created file.
  $file = $this->createFile();
  $url = file_create_url($file->uri);
  // URLs can't contain characters outside the ASCII set so $filename has to be
  // encoded.
  $filename = $GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . rawurlencode($file->filename);
  $this->assertEqual($filename, $url, t('Correctly generated a URL for a created file.'));
  $this->drupalHead($url);
  $this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the created file.'));

  // Test generating an URL to a shipped file (i.e. a file that is part of
  // Drupal core, a module or a theme, for example a JavaScript file).
  $filepath = 'misc/jquery.js';
  $url = file_create_url($filepath);
  $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath, $url, t('Correctly generated a URL for a shipped file.'));
  $this->drupalHead($url);
  $this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
}
Login or register to post comments