You are here

function ImageFieldTestCase::uploadNodeImage in Drupal 7

Upload an image to a node.

Parameters

$image: A file object representing the image to upload.

$field_name: Name of the image field the image should be attached to.

$type: The type of node to create.

5 calls to ImageFieldTestCase::uploadNodeImage()
ImageAdminStylesUnitTest::testStyleReplacement in modules/image/image.test
Test deleting a style and choosing a replacement style.
ImageFieldDisplayTestCase::testImageFieldDefaultImage in modules/image/image.test
Test use of a default image with an image field.
ImageFieldDisplayTestCase::testImageFieldSettings in modules/image/image.test
Tests for image field settings.
ImageFieldDisplayTestCase::_testImageFieldFormatters in modules/image/image.test
Test image formatters on node display.
ImageFieldValidateTestCase::testResolution in modules/image/image.test
Test min/max resolution settings.

File

modules/image/image.test, line 108
Tests for image.module.

Class

ImageFieldTestCase
This class provides methods specifically for testing Image's field handling.

Code

function uploadNodeImage($image, $field_name, $type) {
  $edit = array(
    'title' => $this
      ->randomName(),
  );
  $edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_0]'] = drupal_realpath($image->uri);
  $this
    ->drupalPost('node/add/' . $type, $edit, t('Save'));

  // Retrieve ID of the newly created node from the current URL.
  $matches = array();
  preg_match('/node\\/([0-9]+)/', $this
    ->getUrl(), $matches);
  return isset($matches[1]) ? $matches[1] : FALSE;
}