ImageTest.php

Same filename in this branch
  1. 11.x core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php
  2. 11.x core/tests/Drupal/Tests/Core/Image/ImageTest.php
  3. 11.x core/tests/Drupal/Tests/Component/Utility/ImageTest.php
Same filename and directory in other branches
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTest.php
  2. 9 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php
  3. 9 core/tests/Drupal/Tests/Core/Image/ImageTest.php
  4. 9 core/tests/Drupal/Tests/Component/Utility/ImageTest.php
  5. 8.9.x core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php
  6. 8.9.x core/tests/Drupal/Tests/Core/Image/ImageTest.php
  7. 8.9.x core/tests/Drupal/Tests/Component/Utility/ImageTest.php
  8. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTest.php
  9. 10 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php
  10. 10 core/tests/Drupal/Tests/Core/Image/ImageTest.php
  11. 10 core/tests/Drupal/Tests/Component/Utility/ImageTest.php

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\ckeditor5\FunctionalJavascript;

// cspell:ignore imageresize imageupload

/**
 * @coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image
 * @group ckeditor5
 * @group #slow
 * @internal
 */
class ImageTest extends ImageTestTestBase {
  use ImageTestBaselineTrait;
  
  /**
   * Tests the ckeditor5_imageResize and ckeditor5_imageUpload settings forms.
   */
  public function testImageSettingsForm() : void {
    $assert_session = $this->assertSession();
    $this->drupalGet('admin/config/content/formats/manage/test_format');
    // The image resize and upload plugin settings forms should be present.
    $assert_session->elementExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-imageresize"]');
    $assert_session->elementExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-image"]');
    // Removing the drupalImageInsert button from the toolbar must remove the
    // plugin settings forms too.
    $this->triggerKeyUp('.ckeditor5-toolbar-item-drupalInsertImage', 'ArrowUp');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-imageresize"]');
    $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-image"]');
    // Re-adding the drupalImageInsert button to the toolbar must re-add the
    // plugin settings forms too.
    $this->triggerKeyUp('.ckeditor5-toolbar-item-drupalInsertImage', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->elementExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-imageresize"]');
    $assert_session->elementExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-image"]');
  }
  
  /**
   * Tests that it's possible to upload SVG image, with the test module enabled.
   */
  public function testCanUploadSvg() : void {
    $this->container
      ->get('module_installer')
      ->install([
      'ckeditor5_test_module_allowed_image',
    ]);
    $page = $this->getSession()
      ->getPage();
    $src = 'core/modules/ckeditor5/tests/fixtures/test-svg-upload.svg';
    $this->drupalGet($this->host
      ->toUrl('edit-form'));
    $this->waitForEditor();
    $this->assertNotEmpty($image_upload_field = $page->find('css', '.ck-file-dialog-button input[type="file"]'));
    $image_upload_field->attachFile($this->container
      ->get('file_system')
      ->realpath($src));
    // Wait for the image to be uploaded and rendered by CKEditor 5.
    $this->assertNotEmpty($this->assertSession()
      ->waitForElementVisible('css', '.ck-widget.image-inline > img[src$="test-svg-upload.svg"]'));
  }

}

Classes

Title Deprecated Summary
ImageTest @coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image[[api-linebreak]] @group ckeditor5 @group #slow @internal

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