You are here

public function QuickEditImageControllerTest::testValidImageUpload in Drupal 9

Tests that uploading a valid image works.

File

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

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' => t('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.');
}