Upload an image to a node.
$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.
function uploadNodeImage($image, $field_name, $type) {
$edit = array(
'title' => $this
->randomName(),
);
$edit['files[' . $field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_0]'] = drupal_realpath($image->uri);
$this
->drupalPost('node/add/' . $type, $edit, t('Save and publish'));
// 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;
}