You are here

public function QuickEditImageControllerTest::uploadImage in Drupal 9

Uploads an image using the image module's Quick Edit route.

Parameters

object $image: The image to upload.

int $nid: The target node ID.

string $field_name: The target field machine name.

string $langcode: The langcode to use when setting the field's value.

2 calls to QuickEditImageControllerTest::uploadImage()
QuickEditImageControllerTest::testInvalidUpload in core/modules/quickedit/tests/src/Functional/QuickEditImageControllerTest.php
Tests that uploading an invalid image does not work.
QuickEditImageControllerTest::testValidImageUpload in core/modules/quickedit/tests/src/Functional/QuickEditImageControllerTest.php
Tests that uploading a valid image works.

File

core/modules/quickedit/tests/src/Functional/QuickEditImageControllerTest.php, line 182

Class

QuickEditImageControllerTest
Tests the endpoints used by the "image" in-place editor.

Namespace

Drupal\Tests\quickedit\Functional

Code

public function uploadImage($image, $nid, $field_name, $langcode) {
  $filepath = $this->container
    ->get('file_system')
    ->realpath($image->uri);
  $path = 'quickedit/image/upload/node/' . $nid . '/' . $field_name . '/' . $langcode . '/default';
  $this
    ->prepareRequest();
  $client = $this
    ->getSession()
    ->getDriver()
    ->getClient();
  $client
    ->request('POST', $this
    ->buildUrl($path, []), [], [
    'files[image]' => $filepath,
  ]);
}