function ImageFieldTestCase::uploadNodeImage

7.x image.test ImageFieldTestCase::uploadNodeImage($image, $field_name, $type)

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 drupal-7.x/modules/image/image.test
Test deleting a style and choosing a replacement style.
ImageFieldDisplayTestCase::testImageFieldDefaultImage in drupal-7.x/modules/image/image.test
Test use of a default image with an image field.
ImageFieldDisplayTestCase::testImageFieldSettings in drupal-7.x/modules/image/image.test
Tests for image field settings.
ImageFieldDisplayTestCase::_testImageFieldFormatters in drupal-7.x/modules/image/image.test
Test image formatters on node display.
ImageFieldValidateTestCase::testResolution in drupal-7.x/modules/image/image.test
Test min/max resolution settings.

File

drupal-7.x/modules/image/image.test, line 90
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;
}