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