function ImageFieldTestCase::uploadNodeImage

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.

7 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::testMissingImageFieldDisplay in modules/image/image.test
Tests the display of image field with the missing FID.
ImageFieldDisplayTestCase::_testImageFieldFormatters in modules/image/image.test
Test image formatters on node display.

... See full list

File

modules/image/image.test, line 113

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.