You are here

public function SearchByPageAttachUploadsTest::attachFileUpload in Search by Page 6

Attaches a file to a node, using Upload module.

Parameters

$node: Node object to attach to.

$filename: File name, not including path (assumed to be in test directory).

$listed: Whether to mark as listed (TRUE) or not (FALSE).

$desc: Description to put on the file upload.

1 call to SearchByPageAttachUploadsTest::attachFileUpload()
SearchByPageAttachUploadsTest::makeContent in tests/search_by_page.test
Makes 2 nodes with attachments, for search testing.
1 method overrides SearchByPageAttachUploadsTest::attachFileUpload()
SearchByPageAttachCCKTest::attachFileUpload in tests/search_by_page.test
Attaches a file to a node, using CCK module.

File

tests/search_by_page.test, line 2014
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPageAttachUploadsTest
Functionality test 1 for Search by Page Attachments with Uploads module.

Code

public function attachFileUpload($node, $filename, $listed, $desc) {
  $path = realpath(drupal_get_path('module', 'search_by_page') . "/tests/" . $filename);

  // First attach the file.
  $this
    ->drupalPost('node/' . $node->nid . '/edit', array(
    'files[upload]' => $path,
  ), t('Save'));

  // Find the file ID of the file we just uploaded
  $node = node_load($node->nid, NULL, TRUE);
  $thisfid = 0;
  foreach ($node->files as $fid => $stuff) {
    if ($stuff->filename == $filename) {
      $thisfid = $fid;
      break;
    }
  }
  $this
    ->assertTrue($thisfid > 0, "Found the file ID for uploaded file");

  // Now go back and edit node again, updating listed and description.
  $this
    ->drupalPost('node/' . $node->nid . '/edit', array(
    'files[' . $thisfid . '][list]' => $listed,
    'files[' . $thisfid . '][description]' => $desc,
  ), t('Save'));
}