1 file.test private FileDownloadTest::checkUrl($scheme, $directory, $filename, $expected_url, $clean_url = '1')

Download a file from the URL generated by file_create_url().

Create a file with the specified scheme, directory and filename; check that the URL generated by file_create_url() for the specified file equals the specified URL; fetch the URL and then compare the contents to the file.


$scheme: A scheme, e.g. "public"

$directory: A directory, possibly ""

$filename: A filename

$expected_url: The expected URL

$clean_url: The value of the clean_url setting


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


Tests for download/file transfer functions.


private function checkUrl($scheme, $directory, $filename, $expected_url, $clean_url = '1') {
  config_set('system.core', 'clean_url', $clean_url);

  // Convert $filename to a valid filename, i.e. strip characters not
  // supported by the filesystem, and create the file in the specified
  // directory.
  $filepath = file_create_filename($filename, $directory);
  $directory_uri = $scheme . '://' . dirname($filepath);
  file_prepare_directory($directory_uri, FILE_CREATE_DIRECTORY);
  $file = $this->createFile($filepath, NULL, $scheme);

  $url = file_create_url($file->uri);
  $this->assertEqual($url, $expected_url, 'Generated URL matches expected URL.');

  if ($scheme == 'private') {
    // Tell the implementation of hook_file_download() in file_test.module
    // that this file may be downloaded.
    file_test_set_return('download', array('x-foo' => 'Bar'));

  if ($this->assertResponse(200) == 'pass') {
    $this->assertRaw(file_get_contents($file->uri), 'Contents of the file are correct.');