Skip to content

Instantly share code, notes, and snippets.

@eliza411
Created August 21, 2013 14:29
Show Gist options
  • Save eliza411/6295203 to your computer and use it in GitHub Desktop.
Save eliza411/6295203 to your computer and use it in GitHub Desktop.
Enter text in a Drupal TinyMCE WYSIWYG field
/**
* Enter text in textareas - this does not text the wysiwg functionality
*
* @When /^I enter "([^"]*)" in the "([^"]*)" text field$/
*/
public function iEnterInTheEditor($text, $field) {
$page = $this->getMainContext()->getSession()->getPage();
// Define selectors because the body field is handled differently
if ($field == 'Body' ) {
$iframe_selector = '#edit-body-und-0-value_ifr';
} else {
$iframe_selector = '#edit-field-' . str_replace(' ', '_', strtolower($field)) . '-und-0-value_ifr';
}
// Allow the field to be filled in via Goutte, if the wysiwyg is disabled, or with TinyMCE enabled
$iframe = $page->find('css', $iframe_selector);
if(!$iframe) {
return new When("I fill in \"$field\" with \"$text\"");
} else {
$script = "jQuery('iframe$iframe_selector').contents().find('body#tinymce').append('<p>$text</p>')";
$this->getMainContext()->getSession()->executeScript($script);
}
}
@spolischook
Copy link

I suggest to disable Tiny while testing - you shouldn't test tiny, it's already good tested ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment