public function FileFieldPathsPathautoCase::testPathauto in File (Field) Paths 7
Test Pathauto cleanup in File (Field) Paths.
File
- tests/
pathauto.test, line 52 - Pathauto module tests for the File (Field) Paths module.
Class
- FileFieldPathsPathautoCase
- Class FileFieldPathsPathautoCase
Code
public function testPathauto() {
$langcode = LANGUAGE_NONE;
// Create a File field.
$field_name = drupal_strtolower($this
->randomName());
$instance_settings['filefield_paths']['file_path']['value'] = 'node/[node:title]';
$instance_settings['filefield_paths']['file_path']['options']['pathauto'] = TRUE;
$instance_settings['filefield_paths']['file_name']['value'] = '[node:title].[file:ffp-extension-original]';
$instance_settings['filefield_paths']['file_name']['options']['pathauto'] = TRUE;
$this
->createFileField($field_name, $this->content_type, array(), $instance_settings);
// Create a node with a test file.
$test_file = $this
->getTestFile('text');
$edit['title'] = $this
->randomString() . ' ' . $this
->randomString();
$edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($test_file->uri);
$this
->drupalPost("node/add/{$this->content_type}", $edit, t('Save'));
// Ensure that file path/name have been processed correctly by Pathauto.
$node = node_load(1);
module_load_include('inc', 'pathauto');
$parts = explode('/', $node->title);
foreach ($parts as &$part) {
$part = pathauto_cleanstring($part);
}
$title = implode('/', $parts);
$this
->assertEqual($node->{$field_name}[$langcode][0]['uri'], "public://node/{$title}/{$title}.txt", t('File path/name has been processed correctly by Pathauto'));
}