function FileFieldTestBase::getTestFile

Same name in this branch
  1. 8.9.x core/modules/file/src/Tests/FileFieldTestBase.php \Drupal\file\Tests\FileFieldTestBase::getTestFile()
Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::getTestFile()
  2. 10 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::getTestFile()
  3. 11.x core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::getTestFile()

Retrieves a sample file of the specified type.

Return value

\Drupal\file\FileInterface The new unsaved file entity.

28 calls to FileFieldTestBase::getTestFile()
FileFieldAnonymousSubmissionTest::doTestNodeWithFileWithoutTitle in core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php
Helper method to test file submissions with missing node titles.
FileFieldAnonymousSubmissionTest::testAnonymousNodeWithFile in core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php
Tests file submission for an anonymous visitor.
FileFieldAttributesTest::setUp in core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php
FileFieldDisplayTest::testDefaultFileFieldDisplay in core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
Tests default display of File Field.
FileFieldDisplayTest::testDescriptionDefaultFileFieldDisplay in core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
Tests description display of File Field.

... See full list

File

core/modules/file/tests/src/Functional/FileFieldTestBase.php, line 71

Class

FileFieldTestBase
Provides methods specifically for testing File module's field handling.

Namespace

Drupal\Tests\file\Functional

Code

public function getTestFile($type_name, $size = NULL) {
    // Get a file to upload.
    $file = current($this->drupalGetTestFiles($type_name, $size));
    // Add a filesize property to files as would be read by
    // \Drupal\file\Entity\File::load().
    $file->filesize = filesize($file->uri);
    return File::create((array) $file);
}

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