Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various changes to support TinyMCE moving #300

Draft
wants to merge 2 commits into
base: 6
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Context/BasicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\BeforeStepScope;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Element\ElementInterface;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Session;
Expand Down Expand Up @@ -375,18 +376,19 @@ public function stepIWaitFor($secs)
* @param string $title
* @return NodeElement|null
*/
protected function findNamedButton($title)
public function findNamedButton($title, ?ElementInterface $parent = null)
{
$page = $this->getSession()->getPage();
if ($parent === null) {
$parent = $this->getSession()->getPage();
}
// See https://mathiasbynens.be/notes/css-escapes
$escapedTitle = addcslashes($title ?? '', '!"#$%&\'()*+,-./:;<=>?@[\]^`{|}~');
$matchedEl = null;
$searches = [
['named', ['link_or_button', "'{$title}'"]],
['css', "button[data-text-alternate='{$escapedTitle}']"],
];
foreach ($searches as list($type, $arg)) {
$buttons = $page->findAll($type, $arg);
$buttons = $parent->findAll($type, $arg);
Comment on lines -378 to +391
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** @var NodeElement $button */
foreach ($buttons as $button) {
if ($button->isVisible()) {
Expand Down
16 changes: 2 additions & 14 deletions src/Context/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,20 +989,8 @@ protected function selectInTheHtmlField(string $select, string $field)
$inputField->getParent()->find('css', 'iframe')->click();
$inputFieldId = $inputField->getAttribute('id');
$js = <<<JS
var editor = jQuery('#$inputFieldId').entwine('ss').getEditor(),
doc = editor.getInstance().getDoc(),
sel = doc.getSelection(),
rng = new Range(),
matched = false;

jQuery(doc).find("$select").each(function() {
if(!matched) {
rng.selectNode(this);
sel.removeAllRanges();
sel.addRange(rng);
matched = true;
}
});
const editor = jQuery('#$inputFieldId').entwine('ss').getEditor();
editor.selectByCssSelector("$select");
Comment on lines -992 to +993
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TinyMCE-specific logic here was moved into the tinymce module. The selectByCssSelector() function is in admin, and ultimately ends up calling editor-specific functionality.

JS;
$this->getMainContext()->getSession()->executeScript($js);
}
Expand Down