You are here

public function QuickEditImageControllerTest::uploadImage in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/quickedit/tests/src/Functional/QuickEditImageControllerTest.php \Drupal\Tests\quickedit\Functional\QuickEditImageControllerTest::uploadImage()

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.

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,
  ]);
}