You are here

public function QuickEditLoadingTest::testImageField in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditLoadingTest::testImageField()
  2. 9 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditLoadingTest::testImageField()

Tests that Quick Edit can handle an image field.

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php, line 344

Class

QuickEditLoadingTest
Tests loading of in-place editing functionality and lazy loading of its in-place editors.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

public function testImageField() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert = $this
    ->assertSession();

  // Add an image field to the content type.
  FieldStorageConfig::create([
    'field_name' => 'field_image',
    'type' => 'image',
    'entity_type' => 'node',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_image',
    'field_type' => 'image',
    'label' => 'Image',
    'entity_type' => 'node',
    'bundle' => 'article',
  ])
    ->save();
  \Drupal::service('entity_display.repository')
    ->getFormDisplay('node', 'article', 'default')
    ->setComponent('field_image', [
    'type' => 'image_image',
  ])
    ->save();
  $display = EntityViewDisplay::load('node.article.default');
  $display
    ->setComponent('field_image', [
    'type' => 'image',
  ])
    ->save();

  // Add an image to the node.
  $this
    ->drupalLogin($this->editorUser);
  $this
    ->drupalGet('node/1/edit');
  $image = $this
    ->drupalGetTestFiles('image')[0];
  $image_path = $this->container
    ->get('file_system')
    ->realpath($image->uri);
  $page
    ->attachFileToField('files[field_image_0]', $image_path);
  $alt_field = $assert
    ->waitForField('field_image[0][alt]');
  $this
    ->assertNotEmpty($alt_field);
  $this
    ->submitForm([
    'field_image[0][alt]' => 'The quick fox',
  ], 'Save');

  // The image field form should load normally.
  // Wait "Quick edit" button for node.
  $assert
    ->waitForElement('css', '[data-quickedit-entity-id="node/1"] .contextual .quickedit');

  // Click by "Quick edit".
  $this
    ->clickContextualLink('[data-quickedit-entity-id="node/1"]', 'Quick edit');

  // Switch to body field.
  $assert
    ->waitForElement('css', '[data-quickedit-field-id="node/1/field_image/en/full"]')
    ->click();
  $field_locator = '.field--name-field-image';
  $assert
    ->waitForElementVisible('css', $field_locator);
}