public function FileFieldPathsGeneralTestCase::testReadOnly in File (Field) Paths 7
Test File (Field) Paths works with read-only stream wrappers.
File
- tests/
filefield_paths.general.test, line 283 - Tests for the File (Field) Paths module.
Class
- FileFieldPathsGeneralTestCase
- Class FileFieldPathsGeneralTestCase
Code
public function testReadOnly() {
// Create a File field.
$field_name = drupal_strtolower($this
->randomName());
$field_settings = array(
'uri_scheme' => 'ffp',
);
$instance_settings = array(
'file_directory' => "fields/{$field_name}",
);
$this
->createFileField($field_name, $this->content_type, $field_settings, $instance_settings);
// Get a test file.
$file = $this
->getTestFile('image');
// Prepare the file for the test 'ffp://' read-only stream wrapper.
$file->uri = str_replace('public', 'ffp', $file->uri);
$uri = file_stream_wrapper_uri_normalize($file->uri);
// Create a file object.
$file = new stdClass();
$file->fid = NULL;
$file->uri = $uri;
$file->filename = basename($file->uri);
$file->filemime = file_get_mimetype($file->uri);
$file->uid = $GLOBALS['user']->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->display = TRUE;
file_save($file);
// Attach the file to a node.
$node = array();
$node['type'] = $this->content_type;
$node[$field_name][LANGUAGE_NONE][0] = (array) $file;
$node = $this
->drupalCreateNode($node);
// Ensure file has been attached to a node.
$this
->assert(isset($node->{$field_name}[LANGUAGE_NONE][0]) && !empty($node->{$field_name}[LANGUAGE_NONE][0]), t('Read-only file is correctly attached to a node.'));
$edit = array();
$edit['instance[settings][filefield_paths][retroactive_update]'] = TRUE;
$edit['instance[settings][filefield_paths][file_path][value]'] = 'node/[node:nid]';
$this
->drupalPost("admin/structure/types/manage/{$this->content_type}/fields/{$field_name}", $edit, t('Save settings'));
// Ensure file is still in original location.
$this
->drupalGet("node/{$node->nid}");
$this
->assertRaw("{$this->public_files_directory}/{$file->filename}", t('Read-only file not affected by Retroactive updates.'));
}