You are here

public function SearchByPageAttachCCKTest::attachFileUpload in Search by Page 6

Attaches a file to a node, using CCK 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.

Overrides SearchByPageAttachUploadsTest::attachFileUpload

2 calls to SearchByPageAttachCCKTest::attachFileUpload()
SearchbyPageAttachNotReadable::makeContent in tests/search_by_page.test
Makes a node with an unreadable attachment, for search testing.
SearchbyPageAttachReindexTest::makeContent in tests/search_by_page.test
Makes several nodes with attachments, for search testing.

File

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

Class

SearchByPageAttachCCKTest
Functionality test 1 for Search by Page Attachments with CCK module.

Code

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

  // Save any previous file information.
  $savefiles = $node->field_myfile;

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

  // Find the file we just uploaded and add description.
  $node = node_load($node->nid, NULL, TRUE);
  $thisfid = 0;
  $thisindex = 0;
  foreach ($node->field_myfile as $stuff) {
    if ($stuff['filename'] == $filename) {
      $node->field_myfile[$thisindex]['list'] = $listed;
      $tmp = array(
        'description' => $desc,
      );
      $node->field_myfile[$thisindex]['data'] = $tmp;
      $thisfid = $node->field_myfile[$thisindex]['fid'];
    }
    else {

      // Something bad is happening to the description when we save above,
      // and I'm not sure why, but...
      $node->field_myfile[$thisindex]['data'] = $savefiles[$thisindex]['data'];
    }
    $thisindex++;
  }
  $this
    ->assertTrue($thisfid > 0, "Found the file ID for uploaded file");
  node_save($node);

  // Load the node again and verify the information is there.
  $node = node_load($node->nid, NULL, TRUE);
  $thisindex = 0;
  foreach ($node->field_myfile as $stuff) {
    if ($stuff['filename'] == $filename) {
      $this
        ->assertEqual($node->field_myfile[$thisindex]['list'], $listed, 'Listed value was saved correctly');
      $this
        ->assertEqual($node->field_myfile[$thisindex]['data']['description'], $desc, 'Description was saved correctly');
    }
    $thisindex++;
  }
}