You are here

function MediaFileFieldTestCase::attachNodeFile in D7 Media 7.2

Same name and namespace in other branches
  1. 7.4 tests/media.test \MediaFileFieldTestCase::attachNodeFile()
  2. 7.3 tests/media.test \MediaFileFieldTestCase::attachNodeFile()

Attaches a file to a node.

3 calls to MediaFileFieldTestCase::attachNodeFile()
MediaFileFieldDisplayTestCase::testNodeDisplay in tests/media.test
Tests normal formatter display on node display.
MediaFileFieldRevisionTestCase::testRevisions in tests/media.test
Tests creating multiple revisions of a node and managing attached files.
MediaFileFieldValidateTestCase::testRequired in tests/media.test
Tests the required property on file fields.

File

tests/media.test, line 163
Tests for media.module.

Class

MediaFileFieldTestCase
Provides methods specifically for testing Media module's field handling.

Code

function attachNodeFile($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[$field_name . '[' . $langcode . '][0][fid]'] = $file->fid;
  $this
    ->drupalPost("node/{$nid}/edit", $edit, t('Save'));
  return $nid;
}