You are here

public function WysiwygSubContext::iSelectTheTextInTheWysiwygEditor in Panopoly 8.2

Selects text in the WYSIWYG editor.

@When I select the text in the :instanceId WYSIWYG editor

File

modules/panopoly/panopoly_test/behat/steps/panopoly_test_wysiwyg.behat.inc, line 139
Provide Behat step-definitions for WYSIWYG editor.

Class

WysiwygSubContext
Behat subcontext for testing WYSIWYG.

Code

public function iSelectTheTextInTheWysiwygEditor($instanceId) {
  $editorType = $this
    ->getEditorType($instanceId);
  $instance = $this
    ->getWysiwygInstance($instanceId);

  // Necessary for some WYSIWYG editors (namely, markitup) to be focussed
  // before instance.insert() will do anything.
  $this
    ->getSession()
    ->executeScript("jQuery('#{$instanceId}').focus();");
  if ($editorType === 'ckeditor') {
    $javascript = <<<JS
const sel = {<span class="php-variable">$instance</span>}.getSelection();
sel.selectElement(sel.getStartElement());
JS;
    $this
      ->getSession()
      ->executeScript($javascript);
  }
  else {
    throw new \RuntimeException("The editor '{$editorType}' is not supported for this step.");
  }
}