You are here

public function InsertFileWidgetTest::testDescriptionField in Insert 8

File

tests/src/FunctionalJavaScript/InsertFileWidgetTest.php, line 205

Class

InsertFileWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testDescriptionField() {
  $field_name = strtolower($this
    ->randomMachineName());
  $this
    ->createFileField($field_name, 'article', [], [
    'description_field' => '1',
  ]);
  $files = $this
    ->drupalGetTestFiles('text');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $field_name . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($field_name . '[0][fids]');
  $page
    ->findField($field_name . '[0][description]')
    ->setValue('test-description');
  $page
    ->findButton('Insert')
    ->click();
  $body_value = $page
    ->find('css', '#edit-body-0-value')
    ->getValue();
  $this
    ->assertEquals(1, preg_match('!<a[^>]+ title="test-description"[^>]+>test-description</a>!', $body_value), 'Verified using description: "' . $body_value . '"');
}