From eddd9d45a698fe4244e95d0d579c54a43e7f9a7b Mon Sep 17 00:00:00 2001 From: Stephan Robotta Date: Tue, 18 Apr 2023 15:31:16 +0200 Subject: [PATCH] Remove unnecessary function from test class and rename method to be collision free in testing environment --- tests/behat/behat_editor_tiny_fontcolor.php | 42 +++---------------- .../textcolortextbackgroundcolor.feature | 4 +- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/tests/behat/behat_editor_tiny_fontcolor.php b/tests/behat/behat_editor_tiny_fontcolor.php index b2bd8d4..b9573b1 100644 --- a/tests/behat/behat_editor_tiny_fontcolor.php +++ b/tests/behat/behat_editor_tiny_fontcolor.php @@ -40,24 +40,23 @@ class behat_editor_tiny_fontcolor extends behat_editor_tiny { * Click on a button for the specified TinyMCE editor. * * phpcs:disable - * @When /^I click on the "(?P(?:[^"]|\\")*)" submenu item for the "(?P(?:[^"]|\\")*)" TinyMCE editor$/ + * @When /^I click on the color menu item "(?P(?:[^"]|\\")*)" and choose "(?P(?:[^"]|\\")*)" for the "(?P(?:[^"]|\\")*)" TinyMCE editor$/ * phpcs:enable * - * @param string $menuitem The label of the menu item + * @param string $label The label of the menu item + * @param string $color The color to choose from the menu item * @param string $locator The locator for the editor */ - public function i_click_on_submenuitem_in_menu(string $menuitem, string $locator): void { + public function i_click_on_colormenuitem_in_menu(string $label, string $color, string $locator): void { $this->require_tiny_tags(); $container = $this->get_editor_container_for_locator($locator); $menubar = $container->find('css', '[role="menubar"]'); - $menus = array_map(function(string $value): string { - return trim($value); - }, explode('>', $menuitem)); + $menus = [trim($label), trim($color)]; // Open the menu bar. - $mainmenu = array_shift($menus); + $mainmenu = 'Format'; $this->execute('behat_general::i_click_on_in_the', [$mainmenu, 'button', $menubar, 'NodeElement']); foreach ($menus as $menuitem) { @@ -77,33 +76,4 @@ public function i_click_on_submenuitem_in_menu(string $menuitem, string $locator $this->execute('behat_general::i_click_on', [$link, 'NodeElement']); } } - - /** - * Select the first child of an element type/index for the specified TinyMCE editor. - * Note that this works only if the content is plain text without formatting. Otherwise, the first child - * selects the part until the next sibling that would be a formatting node such as bold, italics etc. Also, - * a linebreak (
) intercepts the selection. - * - * phpcs:disable - * @When /^I select the inner "(?P(?:[^"]|\\")*)" element in position "(?P(?:[^"]|\\")*)" of the "(?P(?:[^"]|\\")*)" TinyMCE editor$/ - * phpcs:enable - * - * @param string $textlocator The type of element to select (for example `p` or `span`) - * @param int $position The zero-indexed position - * @param string $locator The editor to select within - */ - public function select_text_inner(string $textlocator, int $position, string $locator): void { - $this->require_tiny_tags(); - - $editor = $this->get_textarea_for_locator($locator); - $editorid = $editor->getAttribute('id'); - - // Ensure that a name is set on the iframe relating to the editorid. - $js = <<execute_javascript_for_editor($editorid, $js); - } } diff --git a/tests/behat/textcolortextbackgroundcolor.feature b/tests/behat/textcolortextbackgroundcolor.feature index 22216c7..0ceadfb 100644 --- a/tests/behat/textcolortextbackgroundcolor.feature +++ b/tests/behat/textcolortextbackgroundcolor.feature @@ -12,7 +12,7 @@ Feature: Tiny editor text color/text background color And I wait until the page is ready And I set the field "Description" to "

Some plain text

Some more text

" And I select the "p" element in position "1" of the "Description" TinyMCE editor - And I click on the "Format > Text foreground colour > Gray dark" submenu item for the "Description" TinyMCE editor + And I click on the color menu item "Text foreground colour" and choose "Gray dark" for the "Description" TinyMCE editor And I press "Update profile" Then I should see "Some plain text" And "//span[@style='color:rgb(10,44,46);']" "xpath_element" should exist @@ -27,7 +27,7 @@ Feature: Tiny editor text color/text background color And I wait until the page is ready And I set the field "Description" to "

Some plain text

Some more text

" And I select the "p" element in position "1" of the "Description" TinyMCE editor - And I click on the "Format > Text background colour > Yellow" submenu item for the "Description" TinyMCE editor + And I click on the color menu item "Text background colour" and choose "Yellow" for the "Description" TinyMCE editor And I press "Update profile" Then I should see "Some plain text" And "//span[@style='background-color:rgb(226,176,7);']" "xpath_element" should exist