EntityEmbedTestBase.php in Entity Embed 8
File
tests/src/FunctionalJavascript/EntityEmbedTestBase.php
View source
<?php
namespace Drupal\Tests\entity_embed\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
abstract class EntityEmbedTestBase extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'entity_embed',
'entity_embed_test',
'node',
'ckeditor',
];
protected function assignNameToCkeditorIframe() {
$javascript = <<<JS
(function(){
document.getElementsByClassName('cke_wysiwyg_frame')[0].id = 'ckeditor';
})()
JS;
$this
->getSession()
->evaluateScript($javascript);
}
protected function pressEditorButton($name) {
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->waitForElementVisible('css', 'a.cke_button__' . $name)
->click();
}
protected function waitForEditor($instance_id = 'edit-body-0-value', $timeout = 10000) {
$condition = <<<JS
(function() {
return (
typeof CKEDITOR !== 'undefined'
&& typeof CKEDITOR.instances["{<span class="php-variable">$instance_id</span>}"] !== 'undefined'
&& CKEDITOR.instances["{<span class="php-variable">$instance_id</span>}"].instanceReady
);
}());
JS;
$this
->getSession()
->wait($timeout, $condition);
}
protected function reopenDialog() {
$this
->getSession()
->switchToIFrame();
$select_and_edit_embed = <<<JS
var editor = CKEDITOR.instances['edit-body-0-value'];
var entityEmbed = editor.widgets.getByElement(editor.editable().findOne('div'));
entityEmbed.focus();
editor.execCommand('editdrupalentity');
JS;
$this
->getSession()
->executeScript($select_and_edit_embed);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->waitForElementVisible('css', 'form.entity-embed-dialog-step--embed');
}
protected function showHiddenFields() {
$script = <<<JS
var hidden_fields = document.querySelectorAll(".visually-hidden");
[].forEach.call(hidden_fields, function(el) {
el.classList.remove("visually-hidden");
});
JS;
$this
->getSession()
->executeScript($script);
}
}