You are here

public function QuickEditLoadingTest::testImageField in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditLoadingTest::testImageField()
  2. 10 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 345

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' => t('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
    ->drupalPostForm(NULL, [
    'field_image[0][alt]' => 'Vivamus aliquet elit',
  ], t('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();
  $assert
    ->assertWaitOnAjaxRequest();
  $field_locator = '.field--name-field-image';
  $assert
    ->waitForElementVisible('css', $field_locator);
}