You are here

public function FileFieldPathsTokensTest::testTokensUtf in File (Field) Paths 8

Test token value with a UTF file.

See also

https://www.drupal.org/node/1292436

File

tests/src/Functional/FileFieldPathsTokensTest.php, line 93

Class

FileFieldPathsTokensTest
Test token functionality.

Namespace

Drupal\Tests\filefield_paths\Functional

Code

public function testTokensUtf() {

  // Prepare a test text file.

  /** @var \Drupal\file\Entity\File $text_file */
  $text_file = $this
    ->getTestFile('text');

  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = \Drupal::service('file_system');
  $file_system
    ->copy($text_file
    ->getFileUri(), 'public://тест.txt');
  $files = $file_system
    ->scanDirectory('public://', '/тест\\.txt/');
  $utf_file = current($files);

  /** @var \Drupal\file\Entity\File $utf_file */
  $utf_file = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->create((array) $utf_file);
  $utf_file
    ->save();

  // Ensure tokens are processed correctly.
  $data = [
    'file' => $utf_file,
  ];
  $this
    ->assertToken('[file:ffp-name-only]', 'тест', $data);
}