public function FileFieldPathsTransliterationTest::testTransliteration in File (Field) Paths 8
Test Transliteration cleanup in File (Field) Paths.
File
- tests/
src/ Functional/ FileFieldPathsTransliterationTest.php, line 37
Class
- FileFieldPathsTransliterationTest
- Test transliteration functionality.
Namespace
Drupal\Tests\filefield_paths\FunctionalCode
public function testTransliteration() {
// Create a File field.
$field_name = mb_strtolower($this
->randomMachineName());
$third_party_settings['filefield_paths']['file_path']['value'] = 'node/[node:title]';
$third_party_settings['filefield_paths']['file_path']['options']['transliterate'] = TRUE;
$third_party_settings['filefield_paths']['file_name']['value'] = '[node:title].[file:ffp-extension-original]';
$third_party_settings['filefield_paths']['file_name']['options']['transliterate'] = TRUE;
$this
->createFileField($field_name, 'node', $this->contentType, [], [], $third_party_settings);
// Create a node with a test file.
/** @var \Drupal\file\Entity\File $test_file */
$test_file = $this
->getTestFile('text');
$edit['title[0][value]'] = 'тест';
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')
->realpath($test_file
->getFileUri());
$this
->drupalGet("node/add/{$this->contentType}");
$this
->submitForm($edit, 'Save');
// Get created Node ID.
$matches = [];
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
$nid = $matches[1];
// Ensure that file path/name have been processed correctly by
// Transliteration.
$node = \Drupal::entitytypeManager()
->getStorage('node')
->load($nid);
$this
->assertEqual($node->{$field_name}[0]->entity
->getFileUri(), "public://node/test/test.txt", 'File path/name has been processed correctly by Transliteration');
}