You are here

protected function PDFToImageTest::uploadNodeFile in PDF to ImageField 7.3

Uploads a file to a node.

Utility.

See also

file.test

1 call to PDFToImageTest::uploadNodeFile()
PDFToImageTest::testAttachingPdf in tests/pdf_to_image.test
Save a document with an attached PDF, check that the image was generated.

File

tests/pdf_to_image.test, line 141
Test the file attachment and process.

Class

PDFToImageTest
Test attaching a PDF.

Code

protected 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);.
  }

  // 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;
}