function FileFieldTestBase::uploadNodeFile

Uploads a file to a node.

11 calls to FileFieldTestBase::uploadNodeFile()
FileFieldDisplayTest::testNodeDisplay in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php
Tests normal formatter display on node display.
FileFieldPathTest::testUploadPath in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php
Tests the normal formatter display on node display.
FileFieldRevisionTest::testRevisions in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php
Tests creating multiple revisions of a node and managing attached files.
FileFieldRSSContentTest::testFileFieldRSSContent in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
Tests RSS enclosure formatter display for RSS feeds.
FileFieldValidateTest::testFileExtension in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
Tests file extension checking.

... See full list

File

drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php, line 137
Definition of Drupal\file\Tests\FileFieldTestBase.

Class

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

Namespace

Drupal\file\Tests

Code

function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) {
  $langcode = Language::LANGCODE_NOT_SPECIFIED;
  $edit = array(
    "title" => $this
      ->randomName(),
    'revision' => (string) (int) $new_revision,
  );
  if (is_numeric($nid_or_type)) {
    $nid = $nid_or_type;
  }
  else {

    // Add a new node.
    $extras['type'] = $nid_or_type;
    $node = $this
      ->drupalCreateNode($extras);
    $nid = $node->nid;

    // Save at least one revision to better simulate a real site.
    $node
      ->setNewRevision();
    $node
      ->save();
    $node = node_load($nid, TRUE);
    $this
      ->assertNotEqual($nid, $node->vid, t('Node revision exists.'));
  }

  // Attach a file to the node.
  $field = field_info_field($field_name);
  $name = 'files[' . $field_name . '_' . $langcode . '_0]';
  if ($field['cardinality'] != 1) {
    $name .= '[]';
  }
  $edit[$name] = drupal_realpath($file->uri);
  $this
    ->drupalPost("node/{$nid}/edit", $edit, t('Save and keep published'));
  return $nid;
}