function FileSelectionTest::testCanNotReferToTemporaryFiles

Tests that entity reference should avoid referring to temporary files.

File

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

Class

FileSelectionTest
Tests file selection plugin.

Namespace

Drupal\Tests\file\Kernel\Plugin\EntityReference

Code

public function testCanNotReferToTemporaryFiles() : void {
  \file_put_contents('public://test.png', str_repeat('b', 10));
  $file = File::create([
    'uri' => 'public://test.png',
    'filename' => 'test.png',
    'label' => $this->randomMachineName(),
  ]);
  $file->save();
  // Assert the result.
  $result = $this->selectionHandler
    ->getReferenceableEntities();
  self::assertEmpty($result, 'Temporary files can not be referred by handler.');
}

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