function NavigationLogoTest::createFile

Helper function to create a file entity.

Return value

\Drupal\file\FileInterface The file entity.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to NavigationLogoTest::createFile()
NavigationLogoTest::testSettingsLogoOptionsForm in core/modules/navigation/tests/src/Functional/NavigationLogoTest.php
Tests Navigation logo configuration base options.

File

core/modules/navigation/tests/src/Functional/NavigationLogoTest.php, line 112

Class

NavigationLogoTest
Tests for \Drupal\navigation\Form\SettingsForm.

Namespace

Drupal\Tests\navigation\Functional

Code

protected function createFile() {
    // Define the file URI and path.
    $file_name = 'test-logo.png';
    $temp_dir = $this->fileSystem
        ->getTempDirectory();
    $file_uri = 'public://' . $file_name;
    $logo_path = __DIR__ . '/../../assets/image_test_files/' . $file_name;
    $file_contents = file_get_contents($logo_path);
    file_put_contents($temp_dir . '/' . $file_name, $file_contents);
    // Create a file entity for testing.
    $file = File::create([
        'uri' => $file_uri,
    ]);
    try {
        $file->setPermanent();
        $file->save();
    } catch (EntityStorageException $e) {
        $this->fail(sprintf('Failed to create file entity: %s', $e->getMessage()));
    }
    return $file;
}

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