function FileFieldTestCase::uploadNodeFile

7.x file.test FileFieldTestCase::uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array())

Uploads a file to a node.

10 calls to FileFieldTestCase::uploadNodeFile()
FileFieldDisplayTestCase::testNodeDisplay in drupal-7.x/modules/file/tests/file.test
Tests normal formatter display on node display.
FileFieldPathTestCase::testUploadPath in drupal-7.x/modules/file/tests/file.test
Tests the normal formatter display on node display.
FileFieldRevisionTestCase::testRevisions in drupal-7.x/modules/file/tests/file.test
Tests creating multiple revisions of a node and managing attached files.
FileFieldValidateTestCase::testFileExtension in drupal-7.x/modules/file/tests/file.test
Tests file extension checking.
FileFieldValidateTestCase::testFileMaxSize in drupal-7.x/modules/file/tests/file.test
Tests the max file size validator.

... See full list

File

drupal-7.x/modules/file/tests/file.test, line 124
Tests for file.module.

Class

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

Code

function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) {
  $langcode = LANGUAGE_NONE;
  $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.
    $this->drupalCreateNode(get_object_vars($node));
    $node = node_load($nid, NULL, TRUE);
    $this->assertNotEqual($nid, $node->vid, 'Node revision exists.');
  }

  // Attach a file to the node.
  $edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($file->uri);
  $this->drupalPost("node/$nid/edit", $edit, t('Save'));

  return $nid;
}