function QuickEditImageControllerTest::testValidImageUpload

Tests that uploading a valid image works.

File

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

Class

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

Namespace

Drupal\Tests\quickedit\Functional

Code

public function testValidImageUpload() {
  // Create a test Node.
  $node = $this->drupalCreateNode([
    'type' => 'article',
    'title' => 'Test Node',
  ]);
  // We want a test image that is a valid size.
  $valid_image = FALSE;
  $image_factory = $this->container
    ->get('image.factory');
  foreach ($this->drupalGetTestFiles('image') as $image) {
    $image_file = $image_factory->get($image->uri);
    if ($image_file->getWidth() > 50 && $image_file->getWidth() < 100) {
      $valid_image = $image;
      break;

    }
  }
  $this->assertNotFalse($valid_image);
  $this->drupalLogin($this->contentAuthorUser);
  $this->uploadImage($valid_image, $node->id(), $this->fieldName, $node->language()
    ->getId());
  $this->assertStringContainsString('"fid":"1"', $this->getSession()
    ->getPage()
    ->getContent(), 'Valid upload completed successfully.');
}

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