public function InsertFileTest::testFocus in Insert 8.2
File
- tests/
src/ FunctionalJavaScript/ InsertFileTest.php, line 269
Class
- InsertFileTest
- Tests Insert module's generic file insert capability.
Namespace
Drupal\Tests\insert\FunctionalJavascriptCode
public function testFocus() {
$longText_field_name = strtolower($this
->randomMachineName());
$this
->createTextField($longText_field_name, $this->contentTypeName);
$fieldName = strtolower($this
->randomMachineName());
$this
->createFileField($fieldName);
$this
->updateInsertSettings($fieldName, [
'styles' => [
'link' => 1,
'icon_link' => 1,
],
'default' => 'link',
]);
$files = $this
->drupalGetTestFiles('text');
$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
->find('css', '#edit-' . $longText_field_name . '-0-value')
->focus();
$page
->findButton('Insert')
->click();
$body = $page
->findField('body[0][value]');
$long_text_value = $page
->find('css', '#edit-' . $longText_field_name . '-0-value')
->getValue();
$this
->assertEquals('', $body
->getValue(), 'Body is empty');
$this
->assertEquals(1, preg_match('!^<a [^>]+>text-0.txt</a>$!', $long_text_value), 'Inserted HTML into focused text area');
$page
->find('css', '#edit-body-0-value')
->focus();
$page
->findButton('Insert')
->click();
$long_text_value = $page
->find('css', '#edit-' . $longText_field_name . '-0-value')
->getValue();
$this
->assertEquals(1, preg_match('!^<a [^>]+>text-0.txt</a>$!', $body
->getValue()), 'Inserted HTML into body after refocusing: ' . $body
->getValue());
$this
->assertEquals(1, preg_match('!^<a [^>]+>text-0.txt</a>$!', $long_text_value), 'Still, second text area has HTML inserted once: ' . $body
->getValue());
}