You are here

public function FileManagedFileElementTest::testFileNameTrim in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testFileNameTrim()
  2. 9 core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testFileNameTrim()

Tests file names have leading . removed.

File

core/modules/file/tests/src/Functional/FileManagedFileElementTest.php, line 170

Class

FileManagedFileElementTest
Tests the 'managed_file' element type.

Namespace

Drupal\Tests\file\Functional

Code

public function testFileNameTrim() {
  file_put_contents('public://.leading-period.txt', $this
    ->randomString(32));
  $last_fid_prior = $this
    ->getLastFileId();
  $this
    ->drupalGet('file/test/0/0/0');
  $this
    ->submitForm([
    'files[file]' => \Drupal::service('file_system')
      ->realpath('public://.leading-period.txt'),
  ], 'Save');
  $next_fid = $this
    ->getLastFileId();
  $this
    ->assertGreaterThan($last_fid_prior, $next_fid);
  $file = File::load($next_fid);
  $this
    ->assertEquals('leading-period.txt', $file
    ->getFilename());
}