function FileManagedFileElementTest::testManagedFileRemoved

Same name and namespace in other branches
  1. 8.9.x core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testManagedFileRemoved()
  2. 10 core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testManagedFileRemoved()
  3. 11.x core/modules/file/tests/src/Functional/FileManagedFileElementTest.php \Drupal\Tests\file\Functional\FileManagedFileElementTest::testManagedFileRemoved()

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

File

core/modules/file/tests/src/Functional/FileManagedFileElementTest.php, line 149

Class

FileManagedFileElementTest
Tests the 'managed_file' element type.

Namespace

Drupal\Tests\file\Functional

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::service('file_system')->realpath($test_file->getFileUri()),
    ];
    $this->submitForm($edit, 'Upload');
    $fid = $this->getLastFileId();
    $file = \Drupal::entityTypeManager()->getStorage('file')
        ->load($fid);
    $file->delete();
    $this->submitForm($edit, 'Upload');
    // We expect the title 'Managed <em>file & butter</em>' which got escaped
    // via a t() call before.
    $this->assertSession()
        ->responseContains('The file referenced by the Managed <em>file &amp; butter</em> field does not exist.');
}

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