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