You are here

public function InsertFileTest::testInsertImagePerFileField in Insert 8.2

File

tests/src/FunctionalJavaScript/InsertFileTest.php, line 442

Class

InsertFileTest
Tests Insert module's generic file insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testInsertImagePerFileField() {
  $page = $this
    ->gotoInsertConfig();
  $page
    ->checkField('file_field_images_enabled');
  $this
    ->saveInsertConfig($page);
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createFileField($fieldName, [
    'file_extensions' => 'txt, png',
  ]);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'thumbnail' => 'thumbnail',
    ],
    'default' => 'thumbnail',
  ]);
  $files = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $body = $page
    ->findField('body[0][value]');
  $this
    ->assertTrue(strpos($body
    ->getValue(), '<img') !== FALSE, 'Placed image using img tag via generic file field: ' . $body
    ->getValue());
}