You are here

function FileFieldDisplayTestCase::testNodeDisplay in FileField 6.3

Test normal formatter display on node display.

File

tests/filefield.test, line 300

Class

FileFieldDisplayTestCase
Test class to check that formatters are working properly.

Code

function testNodeDisplay() {
  $field_name = 'field_' . strtolower($this
    ->randomName());
  $type = $this
    ->drupalCreateContentType();
  $field_options = array(
    'description_field' => '1',
    'list_field' => '1',
    'list_default' => '1',
  );
  $field = $this
    ->createFileField($field_name, $type->name, $field_options);
  $test_file = $this
    ->getTestFile('text');

  // Create a new node with the uploaded file.
  $nid = $this
    ->uploadNodeFile($test_file, $field, $type->name);
  $this
    ->drupalGet('node/' . $nid);

  // Check that the default formatter is displaying with the file name.
  $node = node_load($nid, NULL, TRUE);
  $node_file = $node->{$field['field_name']}[0];
  $default_output = theme('filefield_file', $node_file);
  $this
    ->assertRaw($default_output, t('Default formatter displaying correctly on full node view.'));

  // Turn the "list" option off and check that the file is no longer listed.
  $edit = array(
    $field['field_name'] . '[0][list]' => FALSE,
  );
  $this
    ->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
  $this
    ->assertNoRaw($default_output, t('Field is hidden when "list" option is unchecked.'));
}