diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-12-11 01:32:20 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-12-11 01:32:20 +0000 |
commit | 4f1f28ae4c80b532348abee9e413fa4b37e8a021 (patch) | |
tree | c927d9cd6a03a66cd676afc4fd85710edbba5670 /modules/file | |
parent | 43fac0b20e71d6b643b1e9fa3fd29ae1872ba0f6 (diff) | |
download | brdo-4f1f28ae4c80b532348abee9e413fa4b37e8a021.tar.gz brdo-4f1f28ae4c80b532348abee9e413fa4b37e8a021.tar.bz2 |
- Patch #992674 by carlos8f, scor, alexanderpas: private file download returns access denied.
Diffstat (limited to 'modules/file')
-rw-r--r-- | modules/file/file.module | 2 | ||||
-rw-r--r-- | modules/file/tests/file.test | 25 |
2 files changed, 15 insertions, 12 deletions
diff --git a/modules/file/file.module b/modules/file/file.module index df0d11e34..81c6000e5 100644 --- a/modules/file/file.module +++ b/modules/file/file.module @@ -141,7 +141,7 @@ function file_file_download($uri, $field_type = 'file') { } // Find out which (if any) fields of this type contain the file. - $references = file_get_file_references($file, NULL, FIELD_LOAD_REVISION, $field_type); + $references = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT, $field_type); // If there are no references, stop processing, to avoid returning headers // for files controlled by other modules. diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test index 88d8afcda..bf74b8b71 100644 --- a/modules/file/tests/file.test +++ b/modules/file/tests/file.test @@ -121,20 +121,23 @@ class FileFieldTestCase extends DrupalWebTestCase { ); if (is_numeric($nid_or_type)) { - $node = node_load($nid_or_type, NULL, TRUE); - $delta = isset($node->{$field_name}[LANGUAGE_NONE]) ? count($node->{$field_name}[LANGUAGE_NONE]) : 0; - $edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_' . $delta . ']'] = drupal_realpath($file->uri); - $this->drupalPost('node/' . $nid_or_type . '/edit', $edit, t('Save')); + $nid = $nid_or_type; } else { - $edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_0]'] = drupal_realpath($file->uri); - $type_name = str_replace('_', '-', $nid_or_type); - $this->drupalPost('node/add/' . $type_name, $edit, t('Save')); + // Add a new node. + $node = $this->drupalCreateNode(array('type' => $nid_or_type)); + $nid = $node->nid; + // Save at least one revision to better simulate a real site. + $this->drupalCreateNode(get_object_vars($node)); + $node = node_load($nid, NULL, TRUE); + $this->assertNotEqual($nid, $node->vid, t('Node revision exists.')); } - $matches = array(); - preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); - return isset($matches[1]) ? $matches[1] : FALSE; + // Attach a file to the node. + $edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($file->uri); + $this->drupalPost("node/$nid/edit", $edit, t('Save')); + + return $nid; } /** @@ -1001,7 +1004,7 @@ class FileTokenReplaceTestCase extends FileFieldTestCase { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Load the node and the file. - $node = node_load($nid); + $node = node_load($nid, NULL, TRUE); $file = (object) $node->{$field_name}[LANGUAGE_NONE][0]; $file->description = 'File description.'; |