Created
August 21, 2013 14:29
-
-
Save eliza411/6295203 to your computer and use it in GitHub Desktop.
Enter text in a Drupal TinyMCE WYSIWYG field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suggest to disable Tiny while testing - you shouldn't test tiny, it's already good tested ;)