function FileSystemTest::testInvalidUTF8

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/File/FileSystemTest.php \Drupal\Tests\Core\File\FileSystemTest::testInvalidUTF8()
  2. 10 core/tests/Drupal/Tests/Core/File/FileSystemTest.php \Drupal\Tests\Core\File\FileSystemTest::testInvalidUTF8()
  3. 11.x core/tests/Drupal/Tests/Core/File/FileSystemTest.php \Drupal\Tests\Core\File\FileSystemTest::testInvalidUTF8()

Tests that invalid UTF-8 results in an exception.

@covers ::createFilename

File

core/tests/Drupal/Tests/Core/File/FileSystemTest.php, line 155

Class

FileSystemTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21File%21FileSystem.php/class/FileSystem/9" title="Provides helpers to operate on files and stream wrappers." class="local">\Drupal\Core\File\FileSystem</a>

Namespace

Drupal\Tests\Core\File

Code

public function testInvalidUTF8() {
    vfsStream::setup('dir');
    // cspell:disable-next-line
    $filename = "a\xffsdf\x80€" . '.txt';
    $this->expectException(FileException::class);
    $this->expectExceptionMessage("Invalid filename '{$filename}'");
    $this->fileSystem
        ->createFilename($filename, 'vfs://dir');
}

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