1 image.test public 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.

File

core/modules/image/tests/image.test, line 98
Tests for image.module.

Class

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

Code

public function uploadNodeImage($image, $field_name, $type) {
  $edit = array(
    'title' => $this->randomName(),
  );
  $edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_0]'] = backdrop_realpath($image->uri);
  $this->backdropPost('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;
}