function ImageFieldTestBase::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.

8 calls to ImageFieldTestBase::uploadNodeImage()
ImageAdminStylesTest::testConfigImport in drupal/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
Tests image style configuration import that does a delete.
ImageAdminStylesTest::testStyleReplacement in drupal/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
Test deleting a style and choosing a replacement style.
ImageFieldDisplayTest::testImageFieldDefaultImage in drupal/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
Test use of a default image with an image field.
ImageFieldDisplayTest::testImageFieldSettings in drupal/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
Tests for image field settings.
ImageFieldDisplayTest::_testImageFieldFormatters in drupal/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
Test image formatters on node display.

... See full list

File

drupal/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php, line 118
Definition of Drupal\image\Tests\ImageFieldTestBase.

Class

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

Namespace

Drupal\image\Tests

Code

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