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@17
|
13 * Stores to the class that should be on the last dialog.
|
Chris@17
|
14 *
|
Chris@17
|
15 * @var string
|
Chris@17
|
16 *
|
Chris@17
|
17 * @see \Drupal\off_canvas_test\Controller\TestController::linksDisplay.
|
Chris@17
|
18 */
|
Chris@17
|
19 protected $lastDialogClass;
|
Chris@17
|
20
|
Chris@17
|
21 /**
|
Chris@14
|
22 * {@inheritdoc}
|
Chris@14
|
23 */
|
Chris@14
|
24 public static $modules = [
|
Chris@14
|
25 'off_canvas_test',
|
Chris@14
|
26 ];
|
Chris@14
|
27
|
Chris@14
|
28 /**
|
Chris@14
|
29 * Tests that non-contextual links will work with the off-canvas dialog.
|
Chris@17
|
30 *
|
Chris@17
|
31 * @dataProvider themeDataProvider
|
Chris@14
|
32 */
|
Chris@17
|
33 public function testOffCanvasLinks($theme) {
|
Chris@17
|
34 $this->enableTheme($theme);
|
Chris@17
|
35 $this->drupalGet('/off-canvas-test-links');
|
Chris@14
|
36
|
Chris@17
|
37 $page = $this->getSession()->getPage();
|
Chris@17
|
38 $web_assert = $this->assertSession();
|
Chris@14
|
39
|
Chris@17
|
40 // Make sure off-canvas dialog is on page when first loaded.
|
Chris@17
|
41 $web_assert->elementNotExists('css', '#drupal-off-canvas');
|
Chris@14
|
42
|
Chris@17
|
43 // Check opening and closing with two separate links.
|
Chris@17
|
44 // Make sure tray updates to new content.
|
Chris@17
|
45 // Check the first link again to make sure the empty title class is
|
Chris@17
|
46 // removed.
|
Chris@17
|
47 foreach (['1', '2', '1'] as $link_index) {
|
Chris@17
|
48 $this->assertOffCanvasDialog($link_index, 'side');
|
Chris@17
|
49 $header_text = $this->getOffCanvasDialog()->find('css', '.ui-dialog-title')->getText();
|
Chris@17
|
50 if ($link_index == '2') {
|
Chris@17
|
51 // Check no title behavior.
|
Chris@17
|
52 $web_assert->elementExists('css', '.ui-dialog-empty-title');
|
Chris@17
|
53 $this->assertEquals(' ', $header_text);
|
Chris@17
|
54
|
Chris@17
|
55 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
|
Chris@17
|
56 $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
|
Chris@17
|
57 $page->clickLink("Open side panel 1");
|
Chris@14
|
58 $this->waitForOffCanvasToOpen();
|
Chris@17
|
59 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
|
Chris@17
|
60 $this->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.');
|
Chris@17
|
61 }
|
Chris@17
|
62 else {
|
Chris@17
|
63 // Check that header is correct.
|
Chris@17
|
64 $this->assertEquals("Thing $link_index", $header_text);
|
Chris@17
|
65 $web_assert->elementNotExists('css', '.ui-dialog-empty-title');
|
Chris@14
|
66 }
|
Chris@14
|
67 }
|
Chris@17
|
68
|
Chris@17
|
69 // Test the off_canvas_top tray.
|
Chris@17
|
70 foreach ([1, 2] as $link_index) {
|
Chris@17
|
71 $this->assertOffCanvasDialog($link_index, 'top');
|
Chris@17
|
72
|
Chris@17
|
73 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
|
Chris@17
|
74 if ($link_index === 1) {
|
Chris@17
|
75 $this->assertTrue((bool) strstr($style, 'height: auto;'));
|
Chris@17
|
76 }
|
Chris@17
|
77 else {
|
Chris@17
|
78 $this->assertTrue((bool) strstr($style, 'height: 421px;'));
|
Chris@17
|
79 }
|
Chris@17
|
80 }
|
Chris@17
|
81
|
Chris@17
|
82 // Ensure an off-canvas link opened from inside the off-canvas dialog will
|
Chris@17
|
83 // work.
|
Chris@17
|
84 $this->drupalGet('/off-canvas-test-links');
|
Chris@17
|
85 $page->clickLink('Display more links!');
|
Chris@17
|
86 $this->waitForOffCanvasToOpen();
|
Chris@17
|
87 $web_assert->linkExists('Off_canvas link!');
|
Chris@17
|
88 // Click off-canvas link inside off-canvas dialog
|
Chris@17
|
89 $page->clickLink('Off_canvas link!');
|
Chris@17
|
90 /* @var \Behat\Mink\Element\NodeElement $dialog */
|
Chris@17
|
91 $this->waitForOffCanvasToOpen();
|
Chris@17
|
92 $web_assert->elementTextContains('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]', 'Thing 2 says hello');
|
Chris@17
|
93
|
Chris@17
|
94 // Ensure an off-canvas link opened from inside the off-canvas dialog will
|
Chris@17
|
95 // work after another dialog has been opened.
|
Chris@17
|
96 $this->drupalGet('/off-canvas-test-links');
|
Chris@17
|
97 $page->clickLink("Open side panel 1");
|
Chris@17
|
98 $this->waitForOffCanvasToOpen();
|
Chris@17
|
99 $page->clickLink('Display more links!');
|
Chris@17
|
100 $this->waitForOffCanvasToOpen();
|
Chris@17
|
101 $web_assert->linkExists('Off_canvas link!');
|
Chris@17
|
102 // Click off-canvas link inside off-canvas dialog
|
Chris@17
|
103 $page->clickLink('Off_canvas link!');
|
Chris@17
|
104 /* @var \Behat\Mink\Element\NodeElement $dialog */
|
Chris@17
|
105 $this->waitForOffCanvasToOpen();
|
Chris@17
|
106 $web_assert->elementTextContains('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]', 'Thing 2 says hello');
|
Chris@14
|
107 }
|
Chris@14
|
108
|
Chris@14
|
109 /**
|
Chris@14
|
110 * Tests the body displacement behaves differently at a narrow width.
|
Chris@14
|
111 */
|
Chris@14
|
112 public function testNarrowWidth() {
|
Chris@14
|
113 $narrow_width_breakpoint = 768;
|
Chris@14
|
114 $offset = 20;
|
Chris@14
|
115 $height = 800;
|
Chris@14
|
116 $page = $this->getSession()->getPage();
|
Chris@14
|
117 $web_assert = $this->assertSession();
|
Chris@14
|
118
|
Chris@14
|
119 // Test the same functionality on multiple themes.
|
Chris@14
|
120 foreach ($this->getTestThemes() as $theme) {
|
Chris@14
|
121 $this->enableTheme($theme);
|
Chris@14
|
122 // Testing at the wider width.
|
Chris@14
|
123 $this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height);
|
Chris@14
|
124 $this->drupalGet('/off-canvas-test-links');
|
Chris@14
|
125 $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
|
Chris@17
|
126 $page->clickLink("Open side panel 1");
|
Chris@14
|
127 $this->waitForOffCanvasToOpen();
|
Chris@14
|
128 // Check that the main canvas is padded when page is not narrow width and
|
Chris@14
|
129 // tray is open.
|
Chris@17
|
130 $page->waitFor(10, function ($page) {
|
Chris@17
|
131 return $page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style');
|
Chris@17
|
132 });
|
Chris@14
|
133 $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'style', 'padding-right');
|
Chris@14
|
134
|
Chris@14
|
135 // Testing at the narrower width.
|
Chris@14
|
136 $this->getSession()->resizeWindow($narrow_width_breakpoint - $offset, $height);
|
Chris@14
|
137 $this->drupalGet('/off-canvas-test-links');
|
Chris@14
|
138 $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.');
|
Chris@17
|
139 $page->clickLink("Open side panel 1");
|
Chris@14
|
140 $this->waitForOffCanvasToOpen();
|
Chris@14
|
141 $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.');
|
Chris@14
|
142 }
|
Chris@14
|
143 }
|
Chris@14
|
144
|
Chris@17
|
145 /**
|
Chris@17
|
146 * @param int $link_index
|
Chris@17
|
147 * The index of the link to test.
|
Chris@17
|
148 * @param string $position
|
Chris@17
|
149 * The position of the dialog to test.
|
Chris@17
|
150 */
|
Chris@17
|
151 protected function assertOffCanvasDialog($link_index, $position) {
|
Chris@17
|
152 $page = $this->getSession()->getPage();
|
Chris@17
|
153 $web_assert = $this->assertSession();
|
Chris@17
|
154 $link_text = "Open $position panel $link_index";
|
Chris@17
|
155
|
Chris@17
|
156 // Click the first test like that should open the page.
|
Chris@17
|
157 $page->clickLink($link_text);
|
Chris@17
|
158 if ($this->lastDialogClass) {
|
Chris@17
|
159 $this->waitForNoElement('.' . $this->lastDialogClass);
|
Chris@17
|
160 }
|
Chris@17
|
161 $this->waitForOffCanvasToOpen($position);
|
Chris@17
|
162 $this->lastDialogClass = "$position-$link_index";
|
Chris@17
|
163
|
Chris@17
|
164 // Check that response text is on page.
|
Chris@17
|
165 $web_assert->pageTextContains("Thing $link_index says hello");
|
Chris@17
|
166 $off_canvas_tray = $this->getOffCanvasDialog();
|
Chris@17
|
167
|
Chris@17
|
168 // Check that tray is visible.
|
Chris@17
|
169 $this->assertEquals(TRUE, $off_canvas_tray->isVisible());
|
Chris@17
|
170
|
Chris@17
|
171 $tray_text = $off_canvas_tray->findById('drupal-off-canvas')->getText();
|
Chris@17
|
172 $this->assertEquals("Thing $link_index says hello", $tray_text);
|
Chris@17
|
173 }
|
Chris@17
|
174
|
Chris@14
|
175 }
|