function FileSelectionTest::testCanReferToPermanentFiles

Tests that entity reference should refer permanent files.

File

core/modules/file/tests/src/Kernel/Plugin/EntityReference/FileSelectionTest.php, line 57

Class

FileSelectionTest
Tests file selection plugin.

Namespace

Drupal\Tests\file\Kernel\Plugin\EntityReference

Code

public function testCanReferToPermanentFiles() : void {
  $expected_result = [];
  \file_put_contents('public://file.png', str_repeat('a', 10));
  $file = File::create([
    'uri' => 'public://file.png',
    'filename' => 'file.png',
    'label' => $this->randomMachineName(),
    'status' => FileInterface::STATUS_PERMANENT,
  ]);
  $file->save();
  $expected_result[$file->id()] = Html::escape($file->label());
  // Assert the result.
  $result = $this->selectionHandler
    ->getReferenceableEntities();
  self::assertEquals($expected_result, $result['file'], 'Permanent files can be referred by handler.');
}

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