1 file.test FileURLRewritingTest::testPublicCreatedFileURL()

Test the generating of rewritten public created file URLs.

File

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

Class

FileURLRewritingTest
Tests for file URL rewriting.

Code

function testPublicCreatedFileURL() {
  // Test generating an URL to a created file.

  // Test alteration of file URLs to use a CDN.
  state_set('file_test_hook_file_url_alter', 'cdn');
  $file = $this->createFile();
  $url = file_create_url($file->uri);
  $public_directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
  $this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $public_directory_path . '/' . $file->filename, $url, 'Correctly generated a CDN URL for a created file.');

  // Test alteration of file URLs to use root-relative URLs.
  state_set('file_test_hook_file_url_alter', 'root-relative');
  $file = $this->createFile();
  $url = file_create_url($file->uri);
  $this->assertEqual(base_path() . '/' . $public_directory_path . '/' . $file->filename, $url, 'Correctly generated a root-relative URL for a created file.');

  // Test alteration of file URLs to use a protocol-relative URLs.
  state_set('file_test_hook_file_url_alter', 'protocol-relative');
  $file = $this->createFile();
  $url = file_create_url($file->uri);
  $this->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . $file->filename, $url, 'Correctly generated a protocol-relative URL for a created file.');
}