3 namespace Drupal\Tests\outside_in\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
8 * Base class contains common test functionality for the Settings Tray module.
10 abstract class OutsideInJavascriptTestBase extends JavascriptTestBase {
15 protected function drupalGet($path, array $options = [], array $headers = []) {
16 $return = parent::drupalGet($path, $options, $headers);
18 // After the page loaded we need to additionally wait until the settings
19 // tray Ajax activity is done.
20 $this->assertSession()->assertWaitOnAjaxRequest();
28 * @param string $theme
31 public function enableTheme($theme) {
33 \Drupal::service('theme_installer')->install([$theme]);
34 $theme_config = \Drupal::configFactory()->getEditable('system.theme');
35 $theme_config->set('default', $theme);
36 $theme_config->save();
40 * Waits for off-canvas dialog to open.
42 protected function waitForOffCanvasToOpen() {
43 $web_assert = $this->assertSession();
44 $web_assert->assertWaitOnAjaxRequest();
45 $this->assertElementVisibleAfterWait('css', '#drupal-off-canvas');
49 * Waits for off-canvas dialog to close.
51 protected function waitForOffCanvasToClose() {
52 $this->waitForNoElement('#drupal-off-canvas');
56 * Gets the off-canvas dialog element.
58 * @return \Behat\Mink\Element\NodeElement|null
60 protected function getTray() {
61 $tray = $this->getSession()->getPage()->find('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]');
62 $this->assertEquals(FALSE, empty($tray), 'The tray was found.');
67 * Waits for an element to be removed from the page.
69 * @param string $selector
72 * (optional) Timeout in milliseconds, defaults to 10000.
74 protected function waitForNoElement($selector, $timeout = 10000) {
75 $condition = "(jQuery('$selector').length == 0)";
76 $this->assertJsCondition($condition, $timeout);
80 * Clicks a contextual link.
82 * @todo Remove this function when related trait added in
83 * https://www.drupal.org/node/2821724.
85 * @param string $selector
86 * The selector for the element that contains the contextual link.
87 * @param string $link_locator
88 * The link id, title, or text.
89 * @param bool $force_visible
90 * If true then the button will be forced to visible so it can be clicked.
92 protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {
94 $this->toggleContextualTriggerVisibility($selector);
97 $element = $this->getSession()->getPage()->find('css', $selector);
98 $element->find('css', '.contextual button')->press();
99 $element->findLink($link_locator)->click();
101 if ($force_visible) {
102 $this->toggleContextualTriggerVisibility($selector);
107 * Toggles the visibility of a contextual trigger.
109 * @todo Remove this function when related trait added in
110 * https://www.drupal.org/node/2821724.
112 * @param string $selector
113 * The selector for the element that contains the contextual link.
115 protected function toggleContextualTriggerVisibility($selector) {
116 // Hovering over the element itself with should be enough, but does not
117 // work. Manually remove the visually-hidden class.
118 $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
122 * Waits for Toolbar to load.
124 protected function waitForToolbarToLoad() {
125 $web_assert = $this->assertSession();
126 // Waiting for Toolbar module.
127 // @todo Remove the hack after https://www.drupal.org/node/2542050.
128 $this->assertElementVisibleAfterWait('css', '.toolbar-fixed');
129 // Waiting for Toolbar animation.
130 $web_assert->assertWaitOnAjaxRequest();
134 * Get themes to test.
137 * Theme names to test.
139 protected function getTestThemes() {
140 return ['bartik', 'stark', 'classy', 'stable'];
144 * Asserts the specified selector is visible after a wait.
146 * @param string $selector
147 * The selector engine name. See ElementInterface::findAll() for the
148 * supported selectors.
149 * @param string|array $locator
150 * The selector locator.
151 * @param int $timeout
152 * (Optional) Timeout in milliseconds, defaults to 10000.
154 protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) {
155 $this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout));