public function InsertImageTest::testCaption in Insert 8.2
File
- tests/
src/ FunctionalJavaScript/ InsertImageTest.php, line 594
Class
- InsertImageTest
- Tests Insert module's image insert capability.
Namespace
Drupal\Tests\insert\FunctionalJavascriptCode
public function testCaption() {
$fieldName = strtolower($this
->randomMachineName());
$this
->createImageField($fieldName, [
'alt_field' => '0',
'title_field' => '1',
]);
$this
->updateInsertSettings($fieldName, [
'styles' => [
'image' => 'image',
],
'default' => 'image',
'caption' => TRUE,
]);
$images = $this
->drupalGetTestFiles('image');
$this
->drupalGet('node/add/article');
$page = $this
->getSession()
->getPage();
$page
->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
->realpath($images[0]->uri));
$this
->assertSession()
->waitForField($fieldName . '[0][fids]');
$body = $page
->findField('body[0][value]');
$titleField = $page
->findField($fieldName . '[0][title]');
$titleField
->setValue('some title');
$page
->findButton('Insert')
->click();
$this
->assertEquals(1, preg_match('!data-caption="some title"[^>]*>$!', $body
->getValue()), 'Verified caption being inserted: ' . $body
->getValue());
$titleField
->setValue('');
$this
->assertEquals(0, preg_match('!data-caption="some title"[^>]*>$!', $body
->getValue()), 'Verified caption being removed when erasing title field: ' . $body
->getValue());
$body
->setValue('');
$page
->findButton('Insert')
->click();
$this
->assertEquals(0, preg_match('!data-caption="some title"[^>]*>$!', $body
->getValue()), 'Verified no caption being inserted when title is empty: ' . $body
->getValue());
$titleField
->setValue('some title');
$this
->assertEquals(1, preg_match('!data-caption="some title"[^>]*>$!', $body
->getValue()), 'Verified caption being inserted on images already placed: ' . $body
->getValue());
}