function FileFieldTestBase::replaceNodeFile

Same name in this branch
  1. 8.9.x core/modules/file/src/Tests/FileFieldTestBase.php \Drupal\file\Tests\FileFieldTestBase::replaceNodeFile()
Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::replaceNodeFile()
  2. 10 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::replaceNodeFile()
  3. 11.x core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::replaceNodeFile()

Replaces a file within a node.

1 call to FileFieldTestBase::replaceNodeFile()
FileFieldRevisionTest::testRevisions in core/modules/file/tests/src/Functional/FileFieldRevisionTest.php
Tests creating multiple revisions of a node and managing attached files.

File

core/modules/file/tests/src/Functional/FileFieldTestBase.php, line 213

Class

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

Namespace

Drupal\Tests\file\Functional

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.