FileFieldPathsTransliterationTest.php in File (Field) Paths 8
File
tests/src/Functional/FileFieldPathsTransliterationTest.php
View source
<?php
namespace Drupal\Tests\filefield_paths\Functional;
use Drupal\Component\Utility\Unicode;
class FileFieldPathsTransliterationTest extends FileFieldPathsTestBase {
public function testUi() {
$field_name = mb_strtolower($this
->randomMachineName());
$this
->createFileField($field_name, 'node', $this->contentType);
$this
->drupalGet("admin/structure/types/manage/{$this->contentType}/fields/node.{$this->contentType}.{$field_name}");
foreach ([
'path',
'name',
] as $field) {
$this
->assertField("third_party_settings[filefield_paths][file_{$field}][options][transliterate]");
$element = $this
->xpath('//input[@name=:name]/@disabled', [
':name' => "third_party_settings[filefield_paths][file_{$field}][options][transliterate]",
]);
$this
->assertEmpty($element, 'Transliteration checkbox is not disabled in File ' . Unicode::ucfirst($field) . ' settings.');
}
}
public function testTransliteration() {
$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);
$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');
$matches = [];
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
$nid = $matches[1];
$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');
}
}