// 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())));
$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.'));
$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 {
$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 {
$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 {
$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 {
$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.'));