function ImageTestBase::testWidth

Same name and namespace in other branches
  1. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTestBase::testWidth()
  2. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php \Drupal\Tests\ckeditor5\FunctionalJavascript\ImageTestBase::testWidth()

Ensures that width attribute upcasts and downcasts correctly.

@dataProvider providerWidth

Parameters

string $width: The width input for the image.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php, line 537

Class

ImageTestBase
@coversDefaultClass <a href="/api/drupal/core%21modules%21ckeditor5%21src%21Plugin%21CKEditor5Plugin%21Image.php/class/Image/9" title="CKEditor 5 Image plugin." class="local">\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image</a> @group ckeditor5 @internal

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testWidth(string $width) : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    // Add image to the host body.
    $this->host->body->value = sprintf('<img data-foo="bar" alt="drupalimage test image" ' . $this->imageAttributesAsString() . ' width="%s" />', $width);
    $this->host
        ->save();
    $this->drupalGet($this->host
        ->toUrl('edit-form'));
    $this->waitForEditor();
    // Ensure that the image is upcast as expected. In the editing view, the
    // width attribute should downcast to an inline style on the container
    // element.
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.image[style] img'));
    // Ensure that the width attribute is retained on downcast.
    $editor_data = $this->getEditorDataAsDom();
    $width_from_editor = $editor_data->getElementsByTagName('img')
        ->item(0)
        ->getAttribute('width');
    $this->assertSame($width, $width_from_editor);
    // Save the node and ensure that the width attribute is retained.
    $page->pressButton('Save');
    $this->assertNotEmpty($assert_session->waitForElement('css', "img[width='{$width}']"));
}

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