function QuickEditImageControllerTest::uploadImage

Same name 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.

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

File

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

Class

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

Namespace

Drupal\Tests\image\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,
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.