function FileFieldTestBase::replaceNodeFile

Replaces a file within a node.

File

core/modules/file/src/Tests/FileFieldTestBase.php, line 259

Class

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

Namespace

Drupal\file\Tests

Code

public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) {
  $edit = [
    'files[' . $field_name . '_0]' => \Drupal::service('file_system')->realpath($file->getFileUri()),
    'revision' => (string) (int) $new_revision,
  ];
  $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove'));
  $this->drupalPostForm(NULL, $edit, t('Save'));
}

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