You are here

protected function FileEntityTestBase::createFileEntity in File Entity (fieldable files) 8.2

Create a file in the database and on disk, asserting its success.

Parameters

array $values: (optional) Values of the new file. Default values are supplied.

Return value

FileEntity The newly created file.

5 calls to FileEntityTestBase::createFileEntity()
FileEntityAdminTest::testFilesAdminPages in tests/src/Functional/FileEntityAdminTest.php
Tests files overview with different user permissions.
FileEntityAdminTest::testFilesAdminSort in tests/src/Functional/FileEntityAdminTest.php
Tests that the table sorting works on the files admin pages.
FileEntityAdminTest::testUsageView in tests/src/Functional/FileEntityAdminTest.php
Tests the file usage view.
FileEntityCacheTagsTest::testFileEntityEdit in tests/src/Functional/FileEntityCacheTagsTest.php
Check file edit functionality.
FileEntityPathautoTest::testPathauto in tests/src/Functional/FileEntityPathautoTest.php
Tests Pathauto support.

File

tests/src/Functional/FileEntityTestBase.php, line 181

Class

FileEntityTestBase
Base class for file entity tests.

Namespace

Drupal\Tests\file_entity\Functional

Code

protected function createFileEntity($values = array()) {

  // Populate defaults array.
  $values += array(
    // Prefix filename with non-latin characters to ensure that all
    // file-related tests work with international filenames.
    'filename' => 'Файл для тестирования ' . $this
      ->randomMachineName(),
    'filemime' => 'text/plain',
    'uid' => 1,
    'status' => FILE_STATUS_PERMANENT,
    'contents' => "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.",
    'scheme' => \Drupal::config('system.file')
      ->get('default_scheme'),
  );
  $values['uri'] = $values['scheme'] . '://' . $values['filename'];
  file_put_contents($values['uri'], $values['contents']);
  $this
    ->assertTrue(is_file($values['uri']), t('The test file exists on the disk.'), 'Create test file');
  $file = FileEntity::create($values);

  // Save the file and assert success.
  $result = $file
    ->save();
  $this
    ->assertIdentical(SAVED_NEW, $result, t('The file was added to the database.'), 'Create test file');
  return $file;
}