public function InsertImageWidgetTest::testImageUrlOutput in Insert 8
File
- tests/
src/ FunctionalJavaScript/ InsertImageWidgetTest.php, line 304
Class
- InsertImageWidgetTest
- @group insert
Namespace
Drupal\Tests\insert\FunctionalJavascriptCode
public function testImageUrlOutput() {
$field_name = strtolower($this
->randomMachineName());
$this
->createImageField($field_name, 'article', [], [
'alt_field' => '0',
], [
'insert_default' => 'image',
'insert_styles' => [
'image' => 'image',
'thumbnail' => 'thumbnail',
],
]);
$images = $this
->drupalGetTestFiles('image');
$this
->drupalGet('admin/config/content/formats/manage/plain_text');
$page = $this
->getSession()
->getPage();
$page
->findField('filters[filter_html_escape][status]')
->uncheck();
$page
->findField('filters[editor_file_reference][status]')
->check();
$page
->findButton('Save configuration')
->click();
$this
->drupalGet('node/add/article');
$page = $this
->getSession()
->getPage();
$page
->attachFileToField('files[' . $field_name . '_0]', \Drupal::service('file_system')
->realpath($images[0]->uri));
$this
->assertSession()
->waitForField($field_name . '[0][fids]');
$page
->findButton('Insert')
->click();
$page
->find('css', '.insert select.insert-style')
->selectOption('thumbnail');
$page
->findButton('Insert')
->click();
$page
->findField('title[0][value]')
->setValue('title');
$page
->findButton('Save')
->click();
$page = $this
->getSession()
->getPage();
$count = preg_match_all('!(src="[^"]+")!', $page
->find('css', '.field--name-body')
->getHtml(), $matches);
$this
->assertEquals(2, $count, 'Verified two image being inserted in body.');
$this
->assertFalse(strpos($matches[0][0], 'thumbnail'), 'First image refers to original URL.');
$this
->assertTrue(strpos($matches[0][1], 'thumbnail') !== FALSE, 'Second image refers to style URL.');
}