public function InsertFileWidgetTest::testAbsoluteUrlSetting in Insert 8
File
- tests/
src/ FunctionalJavaScript/ InsertFileWidgetTest.php, line 166
Class
- InsertFileWidgetTest
- @group insert
Namespace
Drupal\Tests\insert\FunctionalJavascriptCode
public function testAbsoluteUrlSetting() {
$field_names = [
strtolower($this
->randomMachineName()),
strtolower($this
->randomMachineName()),
];
$this
->createFileField($field_names[0], 'article');
$this
->createFileField($field_names[1], 'article', [], [], [
'insert_absolute' => '1',
]);
$files = $this
->drupalGetTestFiles('text');
$this
->drupalGet('node/add/article');
$page = $this
->getSession()
->getPage();
$page
->attachFileToField('files[' . $field_names[0] . '_0]', \Drupal::service('file_system')
->realpath($files[0]->uri));
$page
->attachFileToField('files[' . $field_names[1] . '_0]', \Drupal::service('file_system')
->realpath($files[0]->uri));
$this
->assertSession()
->waitForField($field_names[0] . '[0][fids]');
$this
->assertSession()
->waitForField($field_names[1] . '[0][fids]');
$page
->find('css', '#edit-' . $field_names[0] . '-wrapper')
->findButton('Insert')
->click();
$body_value = $page
->find('css', '#edit-body-0-value')
->getValue();
$this
->assertEquals(1, preg_match('!^<a href="/!', $body_value), 'Inserted relative URL: ' . $body_value);
$page
->find('css', '#edit-body-0-value')
->setValue('');
$page
->find('css', '#edit-' . $field_names[1] . '-wrapper')
->findButton('Insert')
->click();
$body_value = $page
->find('css', '#edit-body-0-value')
->getValue();
$this
->assertEquals(1, preg_match('!^<a href="http://!', $body_value), 'Inserted absolute URL: ' . $body_value);
}