public function FileFieldPathsGeneralTestCase::testUploadFileMultivalue in File (Field) Paths 7
Tests a multivalue file upload with File (Field) Paths.
File
- tests/
filefield_paths.general.test, line 108 - Tests for the File (Field) Paths module.
Class
- FileFieldPathsGeneralTestCase
- Class FileFieldPathsGeneralTestCase
Code
public function testUploadFileMultivalue() {
$langcode = LANGUAGE_NONE;
// Create a multivalue File field with 'node/[node:nid]' as the File path
// and '[file:fid].txt' as the File name.
$field_name = drupal_strtolower($this
->randomName());
$field_settings['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
$instance_settings['filefield_paths']['file_path']['value'] = 'node/[node:nid]';
$instance_settings['filefield_paths']['file_name']['value'] = '[file:fid].txt';
$this
->createFileField($field_name, $this->content_type, $field_settings, $instance_settings);
// Create a node with three (3) test files.
$text_files = $this
->drupalGetTestFiles('text');
$this
->drupalGet("node/add/{$this->content_type}");
$this
->drupalPost(NULL, array(
"files[{$field_name}_{$langcode}_0]" => drupal_realpath($text_files[0]->uri),
), t('Upload'));
$this
->drupalPost(NULL, array(
"files[{$field_name}_{$langcode}_1]" => drupal_realpath($text_files[1]->uri),
), t('Upload'));
$edit = array(
'title' => $this
->randomName(),
"files[{$field_name}_{$langcode}_2]" => drupal_realpath($text_files[1]->uri),
);
$this
->drupalPost(NULL, $edit, t('Save'));
// Get created Node ID.
$matches = array();
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
$nid = $matches[1];
// Ensure that the File path has been processed correctly.
$this
->assertRaw("{$this->public_files_directory}/node/{$nid}/1.txt", t('The first File path has been processed correctly.'));
$this
->assertRaw("{$this->public_files_directory}/node/{$nid}/2.txt", t('The second File path has been processed correctly.'));
$this
->assertRaw("{$this->public_files_directory}/node/{$nid}/3.txt", t('The third File path has been processed correctly.'));
}