function DownloadTest::testFileCreateUrl

Test file_create_url().

File

drupal/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php, line 88
Definition of Drupal\file\Tests\DownloadTest.

Class

DownloadTest
Tests for download/file transfer functions.

Namespace

Drupal\file\Tests

Code

function testFileCreateUrl() {

  // Tilde (~) is excluded from this test because it is encoded by
  // rawurlencode() in PHP 5.2 but not in PHP 5.3, as per RFC 3986.
  // @see http://www.php.net/manual/function.rawurlencode.php#86506
  $basename = " -._!\$'\"()*@[]?&+%#,;=:\n\0" . "%23%25%26%2B%2F%3F" . "éøïвβ中國書۞";

  // Characters from various non-ASCII alphabets.
  $basename_encoded = '%20-._%21%24%27%22%28%29%2A%40%5B%5D%3F%26%2B%25%23%2C%3B%3D%3A__' . '%2523%2525%2526%252B%252F%253F' . '%C3%A9%C3%B8%C3%AF%D0%B2%CE%B2%E4%B8%AD%E5%9C%8B%E6%9B%B8%DB%9E';

  // Public files should not be served by Drupal, so their URLs should not be
  // generated by url(), whereas private files should be served by Drupal, so
  // their URLs should be generated by url(). The difference is most apparent
  // when $script_path is not empty (i.e., when not using clean URLs).
  $clean_url_settings = array(
    'clean' => '',
    'unclean' => 'index.php/',
  );
  $generator = $this->container
    ->get('url_generator');
  foreach ($clean_url_settings as $clean_url_setting => $script_path) {
    $clean_urls = $clean_url_setting == 'clean';
    $request = $this
      ->prepareRequestForGenerator($clean_urls);
    $base_path = $request
      ->getSchemeAndHttpHost() . $request
      ->getBasePath();
    $this
      ->checkUrl('public', '', $basename, $base_path . '/' . file_stream_wrapper_get_instance_by_scheme('public')
      ->getDirectoryPath() . '/' . $basename_encoded);
    $this
      ->checkUrl('private', '', $basename, $base_path . '/' . $script_path . 'system/files/' . $basename_encoded);
  }
}