OffCanvasTestBase.php in Drupal 9
File
core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php
View source
<?php
namespace Drupal\Tests\system\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
abstract class OffCanvasTestBase extends WebDriverTestBase {
protected function drupalGet($path, array $options = [], array $headers = []) {
$return = parent::drupalGet($path, $options, $headers);
$this
->assertPageLoadComplete();
return $return;
}
protected function assertPageLoadComplete() {
$this
->assertSession()
->assertWaitOnAjaxRequest();
if ($this->loggedInUser && $this->loggedInUser
->hasPermission('access contextual links')) {
$this
->assertAllContextualLinksLoaded();
}
}
protected function assertAllContextualLinksLoaded() {
$this
->assertSession()
->assertNoElementAfterWait('css', '[data-contextual-id]:empty');
}
protected function enableTheme($theme) {
\Drupal::service('theme_installer')
->install([
$theme,
]);
$theme_config = \Drupal::configFactory()
->getEditable('system.theme');
$theme_config
->set('default', $theme);
$theme_config
->save();
}
protected function waitForOffCanvasToOpen($position = 'side') {
$web_assert = $this
->assertSession();
$this
->getSession()
->wait(800);
$web_assert
->assertWaitOnAjaxRequest();
$this
->assertElementVisibleAfterWait('css', '#drupal-off-canvas');
$web_assert
->elementExists('css', '.ui-dialog-position-' . $position);
}
protected function waitForOffCanvasToClose() {
$this
->assertSession()
->assertNoElementAfterWait('css', '#drupal-off-canvas');
}
protected function getOffCanvasDialog() {
$off_canvas_dialog = $this
->getSession()
->getPage()
->find('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]');
$this
->assertEquals(FALSE, empty($off_canvas_dialog), 'The off-canvas dialog was found.');
return $off_canvas_dialog;
}
protected function getTestThemes() {
return [
'bartik',
'stark',
'classy',
'stable',
'seven',
];
}
protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) {
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertNotEmpty($this
->assertSession()
->waitForElementVisible($selector, $locator, $timeout));
}
public function themeDataProvider() {
$themes = $this
->getTestThemes();
$data = [];
foreach ($themes as $theme) {
$data[$theme] = [
$theme,
];
}
return $data;
}
}
Classes
Name |
Description |
OffCanvasTestBase |
Base class contains common test functionality for the Off-canvas dialog. |