You are here

public function ImageFieldTestBase::previewNodeImage in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/image/tests/src/Functional/ImageFieldTestBase.php \Drupal\Tests\image\Functional\ImageFieldTestBase::previewNodeImage()
  2. 9 core/modules/image/tests/src/Functional/ImageFieldTestBase.php \Drupal\Tests\image\Functional\ImageFieldTestBase::previewNodeImage()

Preview an image in a node.

Parameters

\Drupal\Core\Image\ImageInterface $image: A file object representing the image to upload.

string $field_name: Name of the image field the image should be attached to.

string $type: The type of node to create.

File

core/modules/image/tests/src/Functional/ImageFieldTestBase.php, line 83

Class

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

Namespace

Drupal\Tests\image\Functional

Code

public function previewNodeImage($image, $field_name, $type) {
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
  ];
  $edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')
    ->realpath($image->uri);
  $this
    ->drupalGet('node/add/' . $type);
  $this
    ->submitForm($edit, 'Preview');
}