You are here

public function InsertResponsiveImageTest::testInsertingPictureTag in Insert 8.2

File

modules/insert_responsive_image/tests/src/FunctionalJavaScript/InsertResponsiveImageTest.php, line 15

Class

InsertResponsiveImageTest
Tests Insert module's insert_responsive_image sub-module.

Namespace

Drupal\Tests\insert_responsive_image\FunctionalJavascript

Code

public function testInsertingPictureTag() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($fieldName, [
    'alt_field' => '0',
  ]);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'responsive_image__wide' => 'responsive_image__wide',
    ],
    'default' => 'responsive_image__wide',
  ]);
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $images = $this
    ->drupalGetTestFiles('image');
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($images[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $body = $page
    ->findField('body[0][value]');
  $this
    ->assertEquals(1, preg_match('!srcset="[^"]+"!', $body
    ->getValue()), 'Applied srcset attribute: ' . $body
    ->getValue());
  $this
    ->assertEquals(1, preg_match('!sizes="[^"]+"!', $body
    ->getValue()), 'Applied sizes attribute: ' . $body
    ->getValue());
}