Same name in this branch
- 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTest
- 10 core/tests/Drupal/KernelTests/Core/Theme/ImageTest.php \Drupal\KernelTests\Core\Theme\ImageTest
- 10 core/tests/Drupal/Tests/Component/Utility/ImageTest.php \Drupal\Tests\Component\Utility\ImageTest
- 10 core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest
Same name and namespace in other branches
- 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTest
@coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image @group ckeditor5 @group #slow @internal
Hierarchy
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5TestBase
- class \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTestBase uses CKEditor5TestTrait, TestFileCreationTrait
- class \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTest
- class \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTestBase uses CKEditor5TestTrait, TestFileCreationTrait
- class \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5TestBase
Expanded class hierarchy of ImageTest
File
- core/
modules/ ckeditor5/ tests/ src/ FunctionalJavascript/ ImageTest.php, line 21
Namespace
Drupal\Tests\ckeditor5\FunctionalJavascriptView source
class ImageTest extends ImageTestBase {
/**
* The sample image File entity to embed.
*
* @var \Drupal\file\FileInterface
*/
protected $file;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
FilterFormat::create([
'format' => 'test_format',
'name' => 'Test format',
'filters' => [
'filter_html' => [
'status' => TRUE,
'settings' => [
'allowed_html' => '<p> <br> <em> <a href> <img src alt data-entity-uuid data-entity-type height width data-caption data-align>',
],
],
'filter_align' => [
'status' => TRUE,
],
'filter_caption' => [
'status' => TRUE,
],
],
])
->save();
Editor::create([
'editor' => 'ckeditor5',
'format' => 'test_format',
'settings' => [
'toolbar' => [
'items' => [
'drupalInsertImage',
'sourceEditing',
'link',
'italic',
],
],
'plugins' => [
'ckeditor5_sourceEditing' => [
'allowed_tags' => [],
],
'ckeditor5_imageResize' => [
'allow_resize' => TRUE,
],
],
],
'image_upload' => [
'status' => TRUE,
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '1M',
'max_dimensions' => [
'width' => 100,
'height' => 100,
],
],
])
->save();
$this
->assertSame([], array_map(function (ConstraintViolation $v) {
return (string) $v
->getMessage();
}, iterator_to_array(CKEditor5::validatePair(Editor::load('test_format'), FilterFormat::load('test_format')))));
$this->adminUser = $this
->drupalCreateUser([
'use text format test_format',
'bypass node access',
'administer filters',
]);
// Create a sample host entity to embed images in.
$this->file = File::create([
'uri' => $this
->getTestFiles('image')[0]->uri,
]);
$this->file
->save();
$this->host = $this
->createNode([
'type' => 'page',
'title' => 'Animals with strange names',
'body' => [
'value' => '<p>The pirate is irate.</p>',
'format' => 'test_format',
],
]);
$this->host
->save();
$this
->drupalLogin($this->adminUser);
}
/**
* Provides the relevant image attributes.
*
* @return string[]
*/
protected function imageAttributes() {
return [
'data-entity-type' => 'file',
'data-entity-uuid' => $this->file
->uuid(),
'src' => $this->file
->createFileUrl(),
'width' => '40',
'height' => '20',
];
}
protected function addImage() {
$page = $this
->getSession()
->getPage();
$this
->assertNotEmpty($image_upload_field = $page
->find('css', '.ck-file-dialog-button input[type="file"]'));
$image = $this
->getTestFiles('image')[0];
$image_upload_field
->attachFile($this->container
->get('file_system')
->realpath($image->uri));
// Wait for the image to be uploaded and rendered by CKEditor 5.
$this
->assertNotEmpty($this
->assertSession()
->waitForElementVisible('css', '.ck-widget.image > img[src*="' . $image->filename . '"]'));
}
/**
* Tests the ckeditor5_imageResize and ckeditor5_imageUpload settings forms.
*/
public function testImageSettingsForm() {
$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"]'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CKEditor5TestBase:: |
public | function | Add and save a new text format using CKEditor 5. | |
CKEditor5TestBase:: |
protected | function | Decorates ::fieldValueEquals() to force DrupalCI to provide useful errors. | |
CKEditor5TestBase:: |
protected | function | Checks that no real-time validation errors are present. | |
CKEditor5TestBase:: |
public | function | Create a new text format using CKEditor 5. | |
CKEditor5TestBase:: |
public | function | Save the new text format. | |
CKEditor5TestBase:: |
protected | function | Trigger a keyup event on the selected element. | |
CKEditor5TestTrait:: |
protected | function | Asserts a CKEditor button is disabled. | |
CKEditor5TestTrait:: |
protected | function | Asserts a CKEditor button is enabled. | |
CKEditor5TestTrait:: |
protected | function | Asserts a particular balloon is visible. | |
CKEditor5TestTrait:: |
protected | function | Gets a button from the currently visible balloon. | |
CKEditor5TestTrait:: |
protected | function | Waits for a CKEditor button and returns it when available and visible. | |
CKEditor5TestTrait:: |
protected | function | Gets CKEditor 5 instance data as a PHP DOMDocument. | |
CKEditor5TestTrait:: |
protected | function | Gets CKEditor 5 instance data as a HTML string. | |
CKEditor5TestTrait:: |
protected | function | Clicks a CKEditor button. | |
CKEditor5TestTrait:: |
protected | function | Selects text inside an element. | |
CKEditor5TestTrait:: |
protected | function | Waits for CKEditor to initialize. | |
ImageTest:: |
protected | property | The sample image File entity to embed. | |
ImageTest:: |
protected | function |
Add an image to the CKEditor 5 editable zone. Overrides ImageTestBase:: |
|
ImageTest:: |
protected | function |
Provides the relevant image attributes. Overrides ImageTestBase:: |
|
ImageTest:: |
protected | function |
Overrides CKEditor5TestBase:: |
|
ImageTest:: |
public | function | Tests that it's possible to upload SVG image, with the test module enabled. | |
ImageTest:: |
public | function | Tests the ckeditor5_imageResize and ckeditor5_imageUpload settings forms. | |
ImageTestBase:: |
protected | property | The user to use during testing. | |
ImageTestBase:: |
protected | property |
Overrides CKEditor5TestBase:: |
|
ImageTestBase:: |
protected | property | A host entity with a body field to embed images in. | |
ImageTestBase:: |
protected static | property |
Overrides CKEditor5TestBase:: |
|
ImageTestBase:: |
protected | function | Helper to format attributes. | |
ImageTestBase:: |
public static | function | ||
ImageTestBase:: |
public static | function | ||
ImageTestBase:: |
public static | function | ||
ImageTestBase:: |
public static | function | Data provider for ::testResize(). | |
ImageTestBase:: |
public static | function | Data provider for ::testWidth(). | |
ImageTestBase:: |
public | function | Tests alignment integration. | |
ImageTestBase:: |
public | function | Tests that alt text is required for images. | |
ImageTestBase:: |
public | function | Ensures that attributes are retained on conversion. | |
ImageTestBase:: |
public | function | Tests that arbitrary attributes are allowed via GHS. | |
ImageTestBase:: |
public | function | Ensures that images can have caption set. | |
ImageTestBase:: |
public | function | Tests linkability of the image CKEditor widget. | |
ImageTestBase:: |
public | function | Tests the image resize plugin. | |
ImageTestBase:: |
public | function | Ensures that width attribute upcasts and downcasts correctly. | |
TestFileCreationTrait:: |
protected | property | Whether the files were copied to the test files directory. | |
TestFileCreationTrait:: |
protected | function | Compares two files based on size and file name. | |
TestFileCreationTrait:: |
public static | function | Generates a test file. | |
TestFileCreationTrait:: |
protected | function | Gets a list of files that can be used in tests. | |
WebDriverTestBase:: |
protected | property | Disables CSS animations in tests for more reliable testing. | |
WebDriverTestBase:: |
protected | property | Determines if a test should fail on JavaScript console errors. | 2 |
WebDriverTestBase:: |
protected | property | ||
WebDriverTestBase:: |
protected | function | Waits for the given time or until the given JS condition becomes TRUE. | |
WebDriverTestBase:: |
public | function | ||
WebDriverTestBase:: |
protected | function | Creates a screenshot. | |
WebDriverTestBase:: |
protected | function | Triggers a test failure if a JavaScript error was encountered. | |
WebDriverTestBase:: |
protected | function | Gets the current Drupal javascript settings and parses into an array. | |
WebDriverTestBase:: |
protected | function | ||
WebDriverTestBase:: |
protected | function | 1 | |
WebDriverTestBase:: |
protected | function | ||
WebDriverTestBase:: |
protected | function | ||
WebDriverTestBase:: |
protected | function | 1 | |
WebDriverTestBase:: |
protected | function | 1 |