You are here

function ImageFieldDisplayTestCase::testDefaultImage in ImageField 6.3

Test normal formatter display on node display.

File

tests/imagefield.test, line 82

Class

ImageFieldDisplayTestCase
Test class to check that formatters are working properly.

Code

function testDefaultImage() {
  $field_name = 'field_' . strtolower($this
    ->randomName());
  $type = $this
    ->drupalCreateContentType();
  $type->url_name = str_replace('_', '-', $type->name);
  $field = $this
    ->createImageField($field_name, $type->name);
  $test_file = $this
    ->getTestFile('image');

  // Set a default image.
  $destination = file_directory_path();
  $default_image = field_file_save_file($test_file->filepath, array(), $destination);
  $widget_options = array(
    'use_default_image' => '1',
    'default_image' => $default_image,
  );
  $field = $this
    ->updateFileField($field_name, $type->name, array(), $widget_options);

  // TODO: Figure out why saving through the form in SimpleTest doesn't work.

  /**
      // Set a default image.
      $edit = array(
        'use_default_image' => '1',
        'files[default_image_upload]' => realpath($test_file->filepath),
      );
      $this->drupalPost('admin/content/node-type/' . $type->url_name . '/fields/' . $field['field_name'], $edit, t('Save field settings'));

      // Check that the field was saved.
      $field = content_fields($field['field_name'], $type->name);
      **/

  // Create a new node without a file and check the default.
  $edit = array(
    'title' => $this
      ->randomName(),
  );
  $this
    ->drupalPost('node/add/' . $type->url_name, $edit, t('Save'));

  // Check that the image formatter is displaying.
  $class = 'imagefield imagefield-' . $field['field_name'];
  $default_output = theme('imagefield_image', $default_image, NULL, NULL, array(
    'class' => $class,
  ));
  $this
    ->assertRaw($default_output, t('Default image displaying correctly on full node view.'));
}