function FileURLRewritingTest::testPublicCreatedFileURL

Test the generating of rewritten public created file URLs.

File

modules/simpletest/tests/file.test, line 2780

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.
    variable_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.
    variable_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.
    variable_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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.