.../QuickEditIntegrationTest.php | 76 +++++++++++++++------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php b/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php index e1dda2b..b9deebf 100644 --- a/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php +++ b/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php @@ -175,21 +175,7 @@ public function testArticleNode() { ]); // Append something to the title. - // @todo Clean this up once PhantomJS is fixed, see http://sticksnglue.com/wordpress/phantomjs-1-9-and-keyboardevent/. - $text_to_type = $node->label() . ' Llamas are awesome!'; - $js_simulate_user_typing = << span'); - el.textContent = '$text_to_type'; - el.dispatchEvent(window.KeyboardEvent('keyup')); -}() -JS; - $this->getSession()->evaluateScript($js_simulate_user_typing); + $this->typeInPlainTextEditor('h1.js-quickedit-page-title > span', $node->label() . ' Llamas are awesome!'); $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/title/en/full' => 'changed', 'node/1/uid/en/full' => 'candidate', @@ -247,15 +233,7 @@ function () { ]); // Enter an additional tag. - $input = $this->cssSelect('.quickedit-form-container > .quickedit-form[role="dialog"] form.quickedit-field-form input[name="field_tags[target_id]"]')[0]; - $input->setValue($input->getValue() . ', bar'); - $js_simulate_user_typing = << .quickedit-form[role="dialog"] form.quickedit-field-form input[name="field_tags[target_id]"]'); - window.jQuery(el).trigger('formUpdated'); -}() -JS; - $this->getSession()->evaluateScript($js_simulate_user_typing); + $this->typeInFormEditorTextInputField('field_tags[target_id]', 'foo, bar'); $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', @@ -495,4 +473,54 @@ function () { } } + /** + * Simulates typing in a 'plain_text' in-place editor. + * + * @param string $css_selector + * The CSS selector to find the DOM element (with the 'contenteditable=true' + * attribute set), to type in. + * @param $text + * The text to type. + * + * @see \Drupal\quickedit\Plugin\InPlaceEditor\PlainTextEditor + */ + protected function typeInPlainTextEditor($css_selector, $text) { + // @todo Clean this up once PhantomJS is fixed, see http://sticksnglue.com/wordpress/phantomjs-1-9-and-keyboardevent/. + $js_simulate_user_typing = <<getSession()->evaluateScript($js_simulate_user_typing); + } + + /** + * Simulates typing in an input[type=text] inside a 'form' in-place editor. + * + * @param string $input_name + * The "name" attribute of the input[type=text] to type in. + * @param $text + * The text to type. + * + * @see \Drupal\quickedit\Plugin\InPlaceEditor\FormEditor + */ + protected function typeInFormEditorTextInputField($input_name, $text) { + $input = $this->cssSelect('.quickedit-form-container > .quickedit-form[role="dialog"] form.quickedit-field-form input[type=text][name="' . $input_name . '"]')[0]; + $input->setValue($text); + $js_simulate_user_typing = << .quickedit-form[role="dialog"] form.quickedit-field-form input[name="$input_name"]'); + window.jQuery(el).trigger('formUpdated'); +}() +JS; + $this->getSession()->evaluateScript($js_simulate_user_typing); + } + }