You are here

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

Test token values with a multi-extension text file.

File

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

Class

FileFieldPathsTokensTest
Test token functionality.

Namespace

Drupal\Tests\filefield_paths\Functional

Code

public function testTokensMultiExtension() {

  // 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://text.multiext.txt');
  $files = $file_system
    ->scanDirectory('public://', '/text\\.multiext\\.txt/');
  $multiext_file = current($files);

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

  // Ensure tokens are processed correctly.
  $data = [
    'file' => $multiext_file,
  ];
  $this
    ->assertToken('[file:ffp-name-only]', 'text.multiext', $data);
  $this
    ->assertToken('[file:ffp-name-only-original]', 'text.multiext', $data);
  $this
    ->assertToken('[file:ffp-extension-original]', 'txt', $data);
}