You are here

protected function PluginsTest::getLastUploadedFile in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/PluginsTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\PluginsTest::getLastUploadedFile()

Get the most recently uploaded file.

Return value

\Drupal\file\FileInterface File entity.

Throws

\Drupal\Core\Entity\Sql\SqlContentEntityStorageException Thrown if no results from query.

1 call to PluginsTest::getLastUploadedFile()
PluginsTest::testIframeDisplayPlugin in tests/src/FunctionalJavascript/PluginsTest.php
Tests the Entity browser iframe display plugin.

File

tests/src/FunctionalJavascript/PluginsTest.php, line 241

Class

PluginsTest
Tests the entity_browser plugins.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

protected function getLastUploadedFile() {
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $results = $entity_type_manager
    ->getStorage('file')
    ->getQuery()
    ->range(0, 1)
    ->sort('fid', 'DESC')
    ->execute();
  if (!empty($results)) {
    return $entity_type_manager
      ->getStorage('file')
      ->load(reset($results));
  }
  else {
    throw new SqlContentEntityStorageException('File not found');
  }
}