You are here

public function FileEntityCreationTest::testSingleFileEntityCreation in File Entity (fieldable files) 8.2

Create a "document" file and verify its consistency in the database.

Unset the private folder so it skips the scheme selecting page.

File

tests/src/Functional/FileEntityCreationTest.php, line 41

Class

FileEntityCreationTest
Tests creating and saving a file.

Namespace

Drupal\Tests\file_entity\Functional

Code

public function testSingleFileEntityCreation() {

  // Configure private file system path.
  // Unset private file system path so it skips the scheme selecting, because
  // there is only one file system path available (public://) by default.
  new Settings([
    'file_private_path' => NULL,
  ] + Settings::getAll());
  $this
    ->rebuildContainer();
  $test_file = $this
    ->getTestFile('text');

  // Create a file.
  $edit = array();
  $edit['files[upload]'] = \Drupal::service('file_system')
    ->realpath($test_file->uri);
  $this
    ->drupalPostForm('file/add', $edit, t('Next'));

  // Check that the document file has been uploaded.
  $this
    ->assertRaw(t('@type %name was uploaded.', array(
    '@type' => 'Document',
    '%name' => 'text-0_0.txt',
  )), t('Document file uploaded.'));

  // Check that the file exists in the database.
  $file = $this
    ->getFileByFilename('text-0_0.txt');
  $this
    ->assertInstanceOf(FileInterface::class, $file, t('File found in database.'));
}