function FileManagedFileElementTest::testFileNameTrim

Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testFileNameTrim()
  2. 8.9.x core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testFileNameTrim()
  3. 10 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 179

Class

FileManagedFileElementTest
Tests the 'managed_file' element type.

Namespace

Drupal\Tests\file\Functional

Code

public function testFileNameTrim() : void {
    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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.