X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fsettings_tray%2Ftests%2Fsrc%2FFunctionalJavascript%2FSettingsTrayJavascriptTestBase.php;fp=web%2Fcore%2Fmodules%2Fsettings_tray%2Ftests%2Fsrc%2FFunctionalJavascript%2FSettingsTrayJavascriptTestBase.php;h=6dd026c5ca085ea41249dc6c60f1e06105e2f651;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayJavascriptTestBase.php b/web/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayJavascriptTestBase.php new file mode 100644 index 000000000..6dd026c5c --- /dev/null +++ b/web/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayJavascriptTestBase.php @@ -0,0 +1,126 @@ +assertPageLoadComplete(); + return $return; + } + + /** + * Assert the page is completely loaded. + * + * Ajax requests may happen after page loads. Also for users who have access + * to contextual links the contextual link placeholders will be filled after + * the page is received. + */ + protected function assertPageLoadComplete() { + $this->assertSession()->assertWaitOnAjaxRequest(); + if ($this->loggedInUser && $this->loggedInUser->hasPermission('access contextual links')) { + $this->assertAllContextualLinksLoaded(); + } + } + + /** + * Assert all contextual link areas have be loaded. + * + * Contextual link placeholders will be filled after + * the page is received. + * + * @todo Move this function to https://www.drupal.org/node/2821724. + */ + protected function assertAllContextualLinksLoaded() { + $this->waitForNoElement('[data-contextual-id]:empty'); + } + + /** + * Enables a theme. + * + * @param string $theme + * The theme. + */ + protected 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(); + $this->assertElementVisibleAfterWait('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 = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)"; + $this->assertJsCondition($condition, $timeout); + } + + /** + * Get themes to test. + * + * @return string[] + * Theme names to test. + */ + protected function getTestThemes() { + return ['bartik', 'stark', 'classy', 'stable']; + } + + /** + * Asserts the specified selector is visible after a wait. + * + * @param string $selector + * The selector engine name. See ElementInterface::findAll() for the + * supported selectors. + * @param string|array $locator + * The selector locator. + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. + */ + protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) { + $this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout)); + } + +}