Commit fb300d1f authored by Dries's avatar Dries
Browse files

- Patch #895308 by Damien Tournoud: remove file_directory_path().

parent d62224dc
......@@ -4587,7 +4587,7 @@ function _drupal_bootstrap_full() {
// Running inside the simpletest child site, log fatal errors to test
// specific file directory.
ini_set('log_errors', 1);
ini_set('error_log', file_directory_path() . '/error.log');
ini_set('error_log', 'public://error.log');
}
// Initialize $_GET['q'] prior to invoking hook_init().
......
......@@ -222,6 +222,16 @@ function file_uri_target($uri) {
return count($data) == 2 ? trim($data[1], '\/') : FALSE;
}
/**
* Get the default file stream implementation.
*
* @return
* 'public', 'private' or any other file scheme defined as the default.
*/
function file_default_scheme() {
return variable_get('file_default_scheme', 'public');
}
/**
* Normalizes a URI by making it syntactically correct.
*
......@@ -317,11 +327,9 @@ function file_stream_wrapper_get_instance_by_scheme($scheme) {
* @see http://drupal.org/node/515192
*
* There are two kinds of local files:
* - "created files", i.e. those in the files directory (which is stored in
* the file_directory_path variable and can be retrieved using
* file_directory_path()). These are files that have either been uploaded by
* users or were generated automatically (for example through CSS
* aggregation).
* - "managed files", i.e. those stored by a Drupal-compatible stream wrapper.
* These are files that have either been uploaded by users or were generated
* automatically (for example through CSS aggregation).
* - "shipped files", i.e. those outside of the files directory, which ship as
* part of Drupal core or contributed modules or themes.
*
......@@ -829,7 +837,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
* Given a relative path, construct a URI into Drupal's default files location.
*/
function file_build_uri($path) {
$uri = variable_get('file_default_scheme', 'public') . '://' . $path;
$uri = file_default_scheme() . '://' . $path;
return file_stream_wrapper_uri_normalize($uri);
}
......@@ -1888,33 +1896,6 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
return $files;
}
/**
* Determines the local directory path of a given wrapper.
*
* This function will return the directory path of a stream wrapper. A stream
* is referenced as: "scheme://target". For example, a scheme of "public"
* might return "sites/default/files" or "temporary" might return "/tmp".
*
* @param $scheme
* A string representing the scheme of a stream. The default wrapper is
* is assumed if this is not provided.
*
* @return
* A string containing the directory path of a stream. FALSE is returned if
* the scheme is invalid or a wrapper could not be instantiated.
*/
function file_directory_path($scheme = NULL) {
if (empty($scheme)) {
$scheme = variable_get('file_default_scheme', 'public');
}
if ($wrapper = file_stream_wrapper_get_instance_by_scheme($scheme)) {
return $wrapper->getDirectoryPath();
}
else {
return FALSE;
}
}
/**
* Determine the maximum file upload size by querying the PHP settings.
*
......@@ -2269,9 +2250,9 @@ function file_directory_temp() {
}
}
// if a directory has been found, use it, otherwise default to 'files/tmp' or 'files\\tmp'.
if (empty($temporary_directory)) {
$temporary_directory = file_directory_path() . $path_delimiter . 'tmp';
// If no directory has been found default to 'files/tmp' or 'files\\tmp'.
$temporary_directory = variable_get('file_public_path', conf_path() . '/files') . $path_delimiter . 'tmp';
}
// Save the path of the discovered directory.
variable_set('file_directory_temp', $temporary_directory);
......
......@@ -368,7 +368,7 @@ public function makeBackup(&$filetransfer, $from, $to) {
* Return the full path to a directory where backups should be written.
*/
public function getBackupDir() {
return file_directory_path('temporary');
return file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath();
}
/**
......
......@@ -193,15 +193,7 @@ function _file_generic_settings_extensions($element, &$form_state) {
function _file_generic_settings_file_directory_validate($element, &$form_state) {
// Strip slashes from the beginning and end of $widget['file_directory'].
$value = trim($element['#value'], '\\/');
// Do not allow the file path to be the same as the file_directory_path().
// This causes all sorts of problems with things like file_create_url().
if (strpos($value, file_directory_path()) === 0) {
form_error($element, t('The file directory (@file_directory) cannot start with the system files directory (@files_directory), as this may cause conflicts when building file URLs.', array('@file_directory' => $form_state['values']['file_directory'], '@files_directory' => file_directory_path())));
}
else {
form_set_value($element, $value, $form_state);
}
form_set_value($element, $value, $form_state);
}
/**
......
......@@ -11,8 +11,8 @@
*/
function image_install() {
// Create the styles directory and ensure it's writable.
$path = file_directory_path() . '/styles';
file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$directory = file_default_scheme() . '://styles';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
/**
......@@ -20,8 +20,7 @@ function image_install() {
*/
function image_uninstall() {
// Remove the styles directory and generated images.
$path = file_directory_path() . '/styles';
file_unmanaged_delete_recursive($path);
file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
}
/**
......
......@@ -75,11 +75,12 @@ function image_menu() {
// If clean URLs are disabled, image derivatives will always be served
// through the menu system.
// If clean URLs are enabled and the image derivative already exists,
// PHP will be bypassed.
$items[file_directory_path('public') . '/styles/%image_style'] = array(
// PHP will be bypassed.
$directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
$items[$directory_path . '/styles/%image_style'] = array(
'title' => 'Generate image style',
'page callback' => 'image_style_deliver',
'page arguments' => array(count(explode('/', file_directory_path())) + 1),
'page arguments' => array(count(explode('/', $directory_path)) + 1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
......@@ -763,7 +764,7 @@ function image_style_create_derivative($style, $source, $destination) {
* An image style array.
*/
function image_style_flush($style) {
$style_directory = drupal_realpath(variable_get('file_default_scheme', 'public') . '://styles/' . $style['name']);
$style_directory = drupal_realpath(file_default_scheme() . '://styles/' . $style['name']);
if (is_dir($style_directory)) {
file_unmanaged_delete_recursive($style_directory);
}
......@@ -808,7 +809,7 @@ function image_style_url($style_name, $path) {
}
else {
$destination = image_style_path($style_name, $path);
$url = url(file_directory_path($scheme) . '/' . file_uri_target($destination), array('absolute' => TRUE));
$url = url(file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath() . '/' . file_uri_target($destination), array('absolute' => TRUE));
}
return $url;
}
......@@ -834,7 +835,7 @@ function image_style_path($style_name, $uri) {
}
else {
$path = $uri;
$scheme = variable_get('file_default_scheme', 'public');
$scheme = file_default_scheme();
}
return $scheme . '://styles/' . $style_name . '/' . $scheme . '/' . $path;
}
......
......@@ -334,8 +334,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
* Count the number of images currently create for a style.
*/
function getImageCount($style) {
$directory = file_directory_path() . '/styles/' . $style['name'];
return count(file_scan_directory($directory, '/.*/'));
return count(file_scan_directory('public://styles/' . $style['name'], '/.*/'));
}
/**
......@@ -482,7 +481,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
$this->drupalPost('admin/config/media/image-styles/delete/' . $style_name, array(), t('Delete'));
// Confirm the style directory has been removed.
$directory = file_directory_path() . '/styles/' . $style_name;
$directory = file_default_scheme() . '://styles/' . $style_name;
$this->assertFalse(is_dir($directory), t('Image style %style directory removed on style deletion.', array('%style' => $style['name'])));
drupal_static_reset('image_styles');
......
......@@ -758,7 +758,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
* Additional options to pass to the translation import form.
*/
function importPoFile($contents, array $options = array()) {
$name = tempnam(file_directory_path('temporary'), "po_") . '.po';
$name = tempnam('temporary://', "po_") . '.po';
file_put_contents($name, $contents);
$options['files[file]'] = $name;
$this->drupalPost('admin/config/regional/translate/import', $options, t('Import'));
......@@ -905,7 +905,7 @@ class LocaleExportFunctionalTest extends DrupalWebTestCase {
function testExportTranslation() {
// First import some known translations.
// This will also automatically enable the 'fr' language.
$name = tempnam(file_directory_path('temporary'), "po_") . '.po';
$name = tempnam('temporary://', "po_") . '.po';
file_put_contents($name, $this->getPoFile());
$this->drupalPost('admin/config/regional/translate/import', array(
'langcode' => 'fr',
......
......@@ -416,7 +416,7 @@ protected function error($message = '', $group = 'Other', array $caller = NULL)
*/
public function run() {
// Initialize verbose debugging.
simpletest_verbose(NULL, file_directory_path(), get_class($this));
simpletest_verbose(NULL, variable_get('file_public_path', conf_path() . '/files'), get_class($this));
// HTTP auth settings (<username>:<password>) for the simpletest browser
// when sending requests to the test site.
......@@ -568,7 +568,7 @@ protected function setUp() {
global $conf;
// Store necessary current values before switching to the test environment.
$this->originalFileDirectory = file_directory_path();
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
spl_autoload_register('db_autoload');
......@@ -903,9 +903,8 @@ protected function drupalGetTestFiles($type, $size = NULL) {
// Copy other test files from simpletest.
$original = drupal_get_path('module', 'simpletest') . '/files';
$files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');
$destination_path = file_directory_path('public');
foreach ($files as $file) {
file_unmanaged_copy($file->uri, $destination_path);
file_unmanaged_copy($file->uri, variable_get('file_public_path', conf_path() . '/files'));
}
$this->generatedTestFiles = TRUE;
......@@ -914,7 +913,7 @@ protected function drupalGetTestFiles($type, $size = NULL) {
$files = array();
// Make sure type is valid.
if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) {
$files = file_scan_directory(file_directory_path('public'), '/' . $type . '\-.*/');
$files = file_scan_directory(variable_get('file_public_path', conf_path() . '/files'), '/' . $type . '\-.*/');
// If size is set then remove any files that are not of that size.
if ($size !== NULL) {
......@@ -1152,7 +1151,7 @@ protected function setUp() {
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = file_directory_path();
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->originalProfile = drupal_get_profile();
$clean_url_original = variable_get('clean_url', 0);
......
......@@ -20,7 +20,7 @@ function simpletest_uninstall() {
variable_del('simpletest_verbose');
// Remove generated files.
$path = file_directory_path() . '/simpletest';
$path = 'public://simpletest';
$files = file_scan_directory($path, '/.*/');
foreach ($files as $file) {
file_unmanaged_delete($file->uri);
......
......@@ -131,7 +131,7 @@ function simpletest_run_tests($test_list, $reporter = 'drupal') {
->execute();
// Clear out the previous verbose files.
file_unmanaged_delete_recursive(file_directory_path() . '/simpletest/verbose');
file_unmanaged_delete_recursive('public://simpletest/verbose');
// Get the info for the first test being run.
$first_test = array_shift($test_list);
......@@ -406,7 +406,7 @@ function simpletest_generate_file($filename, $width, $lines, $type = 'binary-tex
$text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symetrical file.
// Create filename.
file_put_contents(file_directory_path() . '/' . $filename . '.txt', $text);
file_put_contents('public://' . $filename . '.txt', $text);
return $filename;
}
......
......@@ -433,11 +433,13 @@ class SimpleTestFolderTestCase extends DrupalWebTestCase {
);
}
function setUp() {
return parent::setUp('image');
}
function testFolderSetup() {
if (module_exists('image')) {
$path = file_directory_path() . '/styles';
$this->assertTrue(file_prepare_directory($path, FALSE), "Directory created.");
}
$directory = file_default_scheme() . '://styles';
$this->assertTrue(file_prepare_directory($directory, FALSE), "Directory created.");
}
}
......
......@@ -175,7 +175,7 @@ class FileTestCase extends DrupalWebTestCase {
function createDirectory($path = NULL) {
// A directory to operate on.
if (is_null($path)) {
$path = file_directory_path() . '/' . $this->randomName();
$path = file_default_scheme() . '://' . $this->randomName();
}
$this->assertTrue(drupal_mkdir($path) && is_dir($path), t('Directory was created successfully.'));
return $path;
......@@ -428,9 +428,8 @@ class FileValidatorTest extends DrupalWebTestCase {
// Maximum size.
if (image_get_toolkit()) {
// Copy the image so that the original doesn't get resized.
$temp_dir = file_directory_path('temporary');
copy(drupal_realpath('misc/druplicon.png'), drupal_realpath($temp_dir) . '/druplicon.png');
$this->image->uri = $temp_dir . '/druplicon.png';
copy(drupal_realpath('misc/druplicon.png'), 'temporary://druplicon.png');
$this->image->uri = 'temporary://druplicon.png';
$errors = file_validate_image_resolution($this->image, '10x5');
$this->assertEqual(count($errors), 0, t('No errors should be reported when an oversized image can be scaled down.'), 'File');
......@@ -439,7 +438,7 @@ class FileValidatorTest extends DrupalWebTestCase {
$this->assertTrue($info['width'] <= 10, t('Image scaled to correct width.'), 'File');
$this->assertTrue($info['height'] <= 5, t('Image scaled to correct height.'), 'File');
drupal_unlink(drupal_realpath($temp_dir . '/druplicon.png'));
drupal_unlink(drupal_realpath('temporary://druplicon.png'));
}
else {
// TODO: should check that the error is returned if no toolkit is available.
......@@ -532,13 +531,12 @@ class FileUnmanagedSaveDataTest extends FileTestCase {
// No filename.
$filepath = file_unmanaged_save_data($contents);
$this->assertTrue($filepath, t('Unnamed file saved correctly.'));
$this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($filepath)), t("File was placed in Drupal's files directory."));
$this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), t("File was placed in Drupal's files directory."));
$this->assertEqual($contents, file_get_contents(drupal_realpath($filepath)), t('Contents of the file are correct.'));
// Provide a filename.
$filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
$this->assertTrue($filepath, t('Unnamed file saved correctly.'));
$this->assertEqual(file_directory_path('public'), file_directory_path(file_uri_scheme($filepath)), t("File was placed in Drupal's files directory."));
$this->assertEqual('asdf.txt', basename($filepath), t('File was named correctly.'));
$this->assertEqual($contents, file_get_contents(drupal_realpath($filepath)), t('Contents of the file are correct.'));
$this->assertFilePermissions($filepath, variable_get('file_chmod_file', 0664));
......@@ -876,11 +874,11 @@ class FileDirectoryTest extends FileTestCase {
}
/**
* Test the file_directory_path() function.
* Test directory handling functions.
*/
function testFileCheckDirectory() {
function testFileCheckDirectoryHandling() {
// A directory to operate on.
$directory = file_directory_path() . '/' . $this->randomName() . '/' . $this->randomName();
$directory = file_stream_wrapper_get_instance_by_scheme(file_default_scheme())->getDirectoryPath() . '/' . $this->randomName() . '/' . $this->randomName();
$this->assertFalse(is_dir($directory), t('Directory does not exist prior to testing.'));
// Non-existent directory.
......@@ -899,6 +897,7 @@ class FileDirectoryTest extends FileTestCase {
// in the directory on any recent version of Windows.
// Make directory read only.
debug($directory);
@drupal_chmod($directory, 0444);
$this->assertFalse(file_prepare_directory($directory, 0), t('Error reported for a non-writeable directory.'), 'File');
......@@ -910,35 +909,15 @@ class FileDirectoryTest extends FileTestCase {
$this->assertDirectoryPermissions($directory, variable_get('file_chmod_directory', 0775));
// Remove .htaccess file to then test that it gets re-created.
$directory = file_directory_path();
@drupal_unlink($directory . '/.htaccess');
$this->assertFalse(is_file($directory . '/.htaccess'), t('Successfully removed the .htaccess file in the files directory.'), 'File');
@drupal_unlink(file_default_scheme() . '://.htaccess');
$this->assertFalse(is_file(file_default_scheme() . '://.htaccess'), t('Successfully removed the .htaccess file in the files directory.'), 'File');
file_ensure_htaccess();
$this->assertTrue(is_file($directory . '/.htaccess'), t('Successfully re-created the .htaccess file in the files directory.'), 'File');
$this->assertTrue(is_file(file_default_scheme() . '://.htaccess'), t('Successfully re-created the .htaccess file in the files directory.'), 'File');
// Verify contents of .htaccess file.
$file = file_get_contents(file_directory_path() . '/.htaccess');
$file = file_get_contents(file_default_scheme() . '://.htaccess');
$this->assertEqual($file, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks", t('The .htaccess file contains the proper content.'), 'File');
}
/**
* Check file_directory_path('public').
*/
function testFileDirectoryPath() {
// Directory path.
$path = variable_get('file_public_path', '');
$this->assertEqual($path, file_directory_path('public'), t('Properly returns the stored file directory path.'), 'File');
}
/**
* Check file_directory_path() and file_directory_path('temporary').
*/
function testFileDirectoryTemp() {
// Temporary directory handling.
variable_set('file_directory_temp', NULL);
$temp = file_directory_temp();
$this->assertTrue(!is_null($temp), t('Properly set and retrieved temp directory %directory.', array('%directory' => $temp)), 'File');
}
/**
* This will take a directory and path, and find a valid filepath that is not
* taken by another file.
......@@ -1154,7 +1133,7 @@ class FileUnmanagedDeleteTest extends FileTestCase {
*/
function testMissing() {
// Try to delete a non-existing file
$this->assertTrue(file_unmanaged_delete(file_directory_path() . '/' . $this->randomName()), t('Returns true when deleting a non-existent file.'));
$this->assertTrue(file_unmanaged_delete(file_default_scheme() . '/' . $this->randomName()), t('Returns true when deleting a non-existent file.'));
}
/**
......@@ -1188,7 +1167,7 @@ class FileUnmanagedDeleteRecursiveTest extends FileTestCase {
*/
function testSingleFile() {
// Create a file for testing
$filepath = file_directory_path() . '/' . $this->randomName();
$filepath = file_default_scheme() . '://' . $this->randomName();
file_put_contents($filepath, '');
// Delete the file.
......@@ -2073,7 +2052,7 @@ class FileSaveDataTest extends FileHookTestCase {
$result = file_save_data($contents);
$this->assertTrue($result, t('Unnamed file saved correctly.'));
$this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory."));
$this->assertEqual(file_default_scheme(), file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
$this->assertEqual($result->filename, basename($result->uri), t("Filename was set to the file's basename."));
$this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.'));
$this->assertEqual($result->filemime, 'application/octet-stream', t('A MIME type was set.'));
......@@ -2095,7 +2074,7 @@ class FileSaveDataTest extends FileHookTestCase {
$result = file_save_data($contents, 'public://' . 'asdf.txt');
$this->assertTrue($result, t('Unnamed file saved correctly.'));
$this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory."));
$this->assertEqual('public', file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
$this->assertEqual('asdf.txt', basename($result->uri), t('File was named correctly.'));
$this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.'));
$this->assertEqual($result->filemime, 'text/plain', t('A MIME type was set.'));
......@@ -2119,7 +2098,7 @@ class FileSaveDataTest extends FileHookTestCase {
$result = file_save_data($contents, $existing->uri, FILE_EXISTS_RENAME);
$this->assertTrue($result, t("File saved sucessfully."));
$this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory."));
$this->assertEqual('public', file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
$this->assertEqual($result->filename, $existing->filename, t("Filename was set to the basename of the source, rather than that of the renamed file."));
$this->assertEqual($contents, file_get_contents($result->uri), t("Contents of the file are correct."));
$this->assertEqual($result->filemime, 'application/octet-stream', t("A MIME type was set."));
......@@ -2147,7 +2126,7 @@ class FileSaveDataTest extends FileHookTestCase {
$result = file_save_data($contents, $existing->uri, FILE_EXISTS_REPLACE);
$this->assertTrue($result, t('File saved sucessfully.'));
$this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory."));
$this->assertEqual('public', file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
$this->assertEqual($result->filename, $existing->filename, t('Filename was set to the basename of the existing file, rather than preserving the original name.'));
$this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.'));
$this->assertEqual($result->filemime, 'application/octet-stream', t('A MIME type was set.'));
......@@ -2208,7 +2187,7 @@ class FileDownloadTest extends FileTestCase {
// Test generating an URL to a created file.
$file = $this->createFile();
$url = file_create_url($file->uri);
$this->assertEqual($GLOBALS['base_url'] . '/' . file_directory_path() . '/' . $file->filename, $url, t('Correctly generated a URL for a created file.'));
$this->assertEqual($GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . $file->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.'));
......@@ -2265,7 +2244,7 @@ class FileDownloadTest extends FileTestCase {
'%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';
$this->checkUrl('public', '', $basename, $base_url . '/' . file_directory_path() . '/' . $basename_encoded);
$this->checkUrl('public', '', $basename, $base_url . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . $basename_encoded);
$this->checkUrl('private', '', $basename, $base_url . '/system/files/' . $basename_encoded);
$this->checkUrl('private', '', $basename, $base_url . '/?q=system/files/' . $basename_encoded, '0');
}
......@@ -2378,19 +2357,20 @@ class FileURLRewritingTest extends FileTestCase {
variable_set('file_test_hook_file_url_alter', 'cdn');
$file = $this->createFile();
$url = file_create_url($file->uri);
$this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . file_directory_path() . '/' . $file->filename, $url, t('Correctly generated a CDN URL for a created file.'));
$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, t('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() . '/' . file_directory_path() . '/' . $file->filename, $url, t('Correctly generated a root-relative URL for a created file.'));
$this->assertEqual(base_path() . '/' . $public_directory_path . '/' . $file->filename, $url, t('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() . '/' . file_directory_path() . '/' . $file->filename, $url, t('Correctly generated a protocol-relative URL for a created file.'));
$this->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . $file->filename, $url, t('Correctly generated a protocol-relative URL for a created file.'));
}
}
......@@ -2599,17 +2579,13 @@ class StreamWrapperTest extends DrupalWebTestCase {
$this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', t('Got a valid stream target from public://foo/bar.txt.'));
$this->assertFalse(file_uri_target('foo/bar.txt'), t('foo/bar.txt is not a valid stream.'));
// Test file_build_uri() and file_directory_path().
// Test file_build_uri() and DrupalLocalStreamWrapper::getDirectoryPath().
$this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', t('Expected scheme was added.'));
$this->assertEqual(file_directory_path(), variable_get('file_public_path'), t('Expected default directory path was returned.'));
$this->assertEqual(file_directory_path('public'), variable_get('file_public_path'), t('Expected public directory path was returned.'));
$this->assertEqual(file_directory_path('temporary'), variable_get('file_temporary_path'), t('Expected temporary directory path was returned.'));
$this->assertEqual(file_directory_path($this->scheme), variable_get('stream_public_path', 'sites/default/files'), t('Expected dummy directory path was returned.'));
$this->assertFalse(file_directory_path('non-existent'), t('No directory path returned for invalid scheme.'));
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), variable_get('file_public_path'), t('Expected default directory path was returned.'));
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), variable_get('file_temporary_path'), t('Expected temporary directory path was returned.'));
variable_set('file_default_scheme', 'private');
$this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', t('Got a valid URI from foo/bar.txt.'));
$this->assertEqual(file_directory_path(), variable_get('file_private_path'), t('Expected default directory path was returned.'));
$this->assertEqual(file_directory_path('private'), variable_get('file_private_path'), t('Expected private directory path was returned.'));
}
/**
......
......@@ -36,7 +36,7 @@ class FileTranferTest extends DrupalWebTestCase {
}
function _buildFakeModule() {
$location = file_directory_path('temporary') . '/fake';
$location = 'temporary://fake';
if (is_dir($location)) {
$ret = 0;
$output = array();
......@@ -80,7 +80,7 @@ class FileTranferTest extends DrupalWebTestCase {
$gotit = TRUE;
try {
$this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/'. file_directory_path());
$this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/'. variable_get('file_public_path', conf_path() . '/files'));
}
catch (FileTransferException $e) {
$gotit = FALSE;
......
......@@ -444,7 +444,7 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
$correct_colors = $this->colorsAreEqual($color, $corner);
}
$directory = file_directory_path() . '/imagetests';
$directory = file_default_scheme() . '://imagetests';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
image_save($image, $directory . '/' . $op . '.' . $image->info['extension']);
......
......@@ -64,7 +64,7 @@ class RegistryParseFilesTestCase extends DrupalWebTestCase {
foreach ($this->fileTypes as $fileType) {
$chrs = hash('sha256', microtime() . mt_rand());
$this->$fileType = new stdClass();
$this->$fileType->fileName = file_directory_path() . '/registry_test_' . substr($chrs, 0, 16);
$this->$fileType->fileName = 'public://registry_test_' . substr($chrs, 0, 16);
$this->$fileType->className = 'registry_test_class' . substr($chrs, 16, 16);
$this->$fileType->interfaceName = 'registry_test_interface' . substr($chrs, 32, 16);
$this->$fileType->contents = $this->getFileContents($fileType);
......
......@@ -191,7 +191,7 @@ class SessionTestCase extends DrupalWebTestCase {
$this->loggedInUser = FALSE;
// Change cookie file for user.
$this->cookieFile = file_directory_path('temporary') . '/cookie.' . $uid . '.txt';
$this->cookieFile = file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath() . '/cookie.' . $uid . '.txt';
$this->additionalCurlOptions[CURLOPT_COOKIEFILE] = $this->cookieFile;
$this->additionalCurlOptions[CURLOPT_COOKIESESSION] = TRUE;
$this->drupalGet('session-test/get');
......
......@@ -58,7 +58,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = file_directory_path();
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->originalProfile = drupal_get_profile();</