3 namespace Drupal\Tests\system\FunctionalJavascript;
6 * Tests the off-canvas dialog functionality.
10 class OffCanvasTest extends OffCanvasTestBase {
15 public static $modules = [
20 * Tests that non-contextual links will work with the off-canvas dialog.
22 public function testOffCanvasLinks() {
23 // Test the same functionality on multiple themes.
24 foreach ($this->getTestThemes() as $theme) {
25 $this->enableTheme($theme);
26 $this->drupalGet('/off-canvas-test-links');
28 $page = $this->getSession()->getPage();
29 $web_assert = $this->assertSession();
31 // Make sure off-canvas dialog is on page when first loaded.
32 $web_assert->elementNotExists('css', '#drupal-off-canvas');
34 // Check opening and closing with two separate links.
35 // Make sure tray updates to new content.
36 // Check the first link again to make sure the empty title class is
38 foreach (['1', '2', '1'] as $link_index) {
39 // Click the first test like that should open the page.
40 $page->clickLink("Click Me $link_index!");
41 $this->waitForOffCanvasToOpen();
43 // Check that the canvas is not on the page.
44 $web_assert->elementExists('css', '#drupal-off-canvas');
45 // Check that response text is on page.
46 $web_assert->pageTextContains("Thing $link_index says hello");
47 $off_canvas_tray = $this->getOffCanvasDialog();
49 // Check that tray is visible.
50 $this->assertEquals(TRUE, $off_canvas_tray->isVisible());
51 $header_text = $off_canvas_tray->find('css', '.ui-dialog-title')->getText();
53 $tray_text = $off_canvas_tray->findById('drupal-off-canvas')->getText();
54 $this->assertEquals("Thing $link_index says hello", $tray_text);
56 if ($link_index == '2') {
57 // Check no title behavior.
58 $web_assert->elementExists('css', '.ui-dialog-empty-title');
59 $this->assertEquals("\xc2\xa0", $header_text);
61 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
62 $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
63 $page->clickLink("Click Me 1!");
64 $this->waitForOffCanvasToOpen();
65 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
66 $this->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.');
69 // Check that header is correct.
70 $this->assertEquals("Thing $link_index", $header_text);
71 $web_assert->elementNotExists('css', '.ui-dialog-empty-title');
78 * Tests the body displacement behaves differently at a narrow width.
80 public function testNarrowWidth() {
81 $narrow_width_breakpoint = 768;
84 $page = $this->getSession()->getPage();
85 $web_assert = $this->assertSession();
87 // Test the same functionality on multiple themes.
88 foreach ($this->getTestThemes() as $theme) {
89 $this->enableTheme($theme);
90 // Testing at the wider width.
91 $this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height);
92 $this->drupalGet('/off-canvas-test-links');
93 $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
94 $page->clickLink("Click Me 1!");
95 $this->waitForOffCanvasToOpen();
96 // Check that the main canvas is padded when page is not narrow width and
98 $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'style', 'padding-right');
100 // Testing at the narrower width.
101 $this->getSession()->resizeWindow($narrow_width_breakpoint - $offset, $height);
102 $this->drupalGet('/off-canvas-test-links');
103 $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.');
104 $page->clickLink("Click Me 1!");
105 $this->waitForOffCanvasToOpen();
106 $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.');