You are here

public function FileManagedFileElementTest::testManagedFileRemoved in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Tests/FileManagedFileElementTest.php \Drupal\file\Tests\FileManagedFileElementTest::testManagedFileRemoved()

Ensure that warning is shown if file on the field has been removed.

File

core/modules/file/src/Tests/FileManagedFileElementTest.php, line 161
Contains \Drupal\file\Tests\FileManagedFileElementTest.

Class

FileManagedFileElementTest
Tests the 'managed_file' element type.

Namespace

Drupal\file\Tests

Code

public function testManagedFileRemoved() {
  $this
    ->drupalGet('file/test/1/0/1');
  $test_file = $this
    ->getTestFile('text');
  $file_field_name = 'files[nested_file][]';
  $edit = [
    $file_field_name => drupal_realpath($test_file
      ->getFileUri()),
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Upload'));
  $fid = $this
    ->getLastFileId();
  $file = \Drupal::entityManager()
    ->getStorage('file')
    ->load($fid);
  $file
    ->delete();
  $this
    ->drupalPostForm(NULL, $edit, t('Upload'));

  // We expect the title 'Managed <em>file & butter</em>' which got escaped
  // via a t() call before.
  $this
    ->assertRaw('The file referenced by the Managed <em>file &amp; butter</em> field does not exist.');
}