X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Foutside_in%2Ftests%2Fsrc%2FFunctionalJavascript%2FOutsideInJavascriptTestBase.php;fp=web%2Fcore%2Fmodules%2Foutside_in%2Ftests%2Fsrc%2FFunctionalJavascript%2FOutsideInJavascriptTestBase.php;h=2dcc40fb44b4e7c9bc8d6ecf96bddce4a8a8ac09;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php b/web/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php new file mode 100644 index 000000000..2dcc40fb4 --- /dev/null +++ b/web/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php @@ -0,0 +1,143 @@ +assertSession()->assertWaitOnAjaxRequest(); + + return $return; + } + + /** + * Enables a theme. + * + * @param string $theme + * The theme. + */ + public function enableTheme($theme) { + // Enable the theme. + \Drupal::service('theme_installer')->install([$theme]); + $theme_config = \Drupal::configFactory()->getEditable('system.theme'); + $theme_config->set('default', $theme); + $theme_config->save(); + } + + /** + * Waits for off-canvas dialog to open. + */ + protected function waitForOffCanvasToOpen() { + $web_assert = $this->assertSession(); + $web_assert->assertWaitOnAjaxRequest(); + $web_assert->waitForElementVisible('css', '#drupal-off-canvas'); + } + + /** + * Waits for off-canvas dialog to close. + */ + protected function waitForOffCanvasToClose() { + $this->waitForNoElement('#drupal-off-canvas'); + } + + /** + * Gets the off-canvas dialog element. + * + * @return \Behat\Mink\Element\NodeElement|null + */ + protected function getTray() { + $tray = $this->getSession()->getPage()->find('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]'); + $this->assertEquals(FALSE, empty($tray), 'The tray was found.'); + return $tray; + } + + /** + * Waits for an element to be removed from the page. + * + * @param string $selector + * CSS selector. + * @param int $timeout + * (optional) Timeout in milliseconds, defaults to 10000. + */ + protected function waitForNoElement($selector, $timeout = 10000) { + $condition = "(jQuery('$selector').length == 0)"; + $this->assertJsCondition($condition, $timeout); + } + + /** + * Clicks a contextual link. + * + * @todo Remove this function when related trait added in + * https://www.drupal.org/node/2821724. + * + * @param string $selector + * The selector for the element that contains the contextual link. + * @param string $link_locator + * The link id, title, or text. + * @param bool $force_visible + * If true then the button will be forced to visible so it can be clicked. + */ + protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) { + if ($force_visible) { + $this->toggleContextualTriggerVisibility($selector); + } + + $element = $this->getSession()->getPage()->find('css', $selector); + $element->find('css', '.contextual button')->press(); + $element->findLink($link_locator)->click(); + + if ($force_visible) { + $this->toggleContextualTriggerVisibility($selector); + } + } + + /** + * Toggles the visibility of a contextual trigger. + * + * @todo Remove this function when related trait added in + * https://www.drupal.org/node/2821724. + * + * @param string $selector + * The selector for the element that contains the contextual link. + */ + protected function toggleContextualTriggerVisibility($selector) { + // Hovering over the element itself with should be enough, but does not + // work. Manually remove the visually-hidden class. + $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');"); + } + + /** + * Waits for Toolbar to load. + */ + protected function waitForToolbarToLoad() { + $web_assert = $this->assertSession(); + // Waiting for Toolbar module. + // @todo Remove the hack after https://www.drupal.org/node/2542050. + $web_assert->waitForElementVisible('css', '.toolbar-fixed'); + // Waiting for Toolbar animation. + $web_assert->assertWaitOnAjaxRequest(); + } + + /** + * Get themes to test. + * + * @return string[] + * Theme names to test. + */ + protected function getTestThemes() { + return ['bartik', 'stark', 'classy', 'stable']; + } + +}