View source
<?php
namespace Drupal\Tests\tinymce\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\editor\Entity\Editor;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
class TinyMCEIntegrationTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected $account;
protected $filterFormat;
protected static $modules = [
'node',
'tinymce',
'filter',
];
protected function setUp() : void {
parent::setUp();
$this->filterFormat = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
]);
$this->filterFormat
->save();
Editor::create([
'format' => 'filtered_html',
'editor' => 'tinymce',
])
->save();
NodeType::create([
'type' => 'page',
'name' => 'page',
])
->save();
$field_storage = FieldStorageConfig::loadByName('node', 'body');
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'label' => 'Body',
'settings' => [
'display_summary' => TRUE,
],
'required' => TRUE,
])
->save();
EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'page',
'mode' => 'default',
'status' => TRUE,
])
->setComponent('body', [
'type' => 'text_textarea_with_summary',
])
->save();
$this->account = $this
->drupalCreateUser([
'administer nodes',
'create page content',
'use text format filtered_html',
]);
$this
->drupalLogin($this->account);
}
public function testFragmentLink() {
$session = $this
->getSession();
$web_assert = $this
->assertSession();
$tinymce_id = '.tox-tinymce';
$before_url = $session
->getCurrentUrl();
$this
->drupalGet('node/add/page');
$session
->getPage();
$session
->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 +'px';");
$this
->assertSession()
->waitForElementVisible('css', $tinymce_id);
$web_assert
->assertNotVisibleInViewport('css', $tinymce_id, 'topLeft', 'TinyMCE-enabled body field is visible.');
$session
->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = '0px';");
$web_assert
->assertVisibleInViewport('css', $tinymce_id, 'topLeft', 'TinyMCE-enabled body field is not visible.');
$session
->executeScript("history.back();");
$after_url = $session
->getCurrentUrl();
self::assertEquals($before_url, $after_url, 'History back works.');
}
public function testImageDialog() {
$session = $this
->getSession();
$web_assert = $this
->assertSession();
$this
->drupalGet('node/add/page');
$session
->getPage();
$web_assert
->elementExists('css', '.tox-tinymce .tox-tbtn[title="Insert/edit image"]');
$this
->click('.tox-notification__dismiss');
$this
->click('.tox-tbtn[title="More..."]');
$this
->assertNotEmpty($web_assert
->waitForElement('css', '.tox-tbtn[title="Insert/edit image"]'));
$this
->click('.tox-tbtn[title="Insert/edit image"]');
$this
->assertNotEmpty($web_assert
->waitForElement('css', '.tox-dialog'));
$web_assert
->elementContains('css', '.tox-dialog .tox-dialog__title', 'Insert/Edit Image');
}
}