comparison core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children c2387f117808
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 namespace Drupal\Tests\system\FunctionalJavascript;
4
5 /**
6 * Tests the off-canvas dialog functionality.
7 *
8 * @group settings_tray
9 */
10 class OffCanvasTest extends OffCanvasTestBase {
11
12 /**
13 * {@inheritdoc}
14 */
15 public static $modules = [
16 'off_canvas_test',
17 ];
18
19 /**
20 * Tests that non-contextual links will work with the off-canvas dialog.
21 */
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');
27
28 $page = $this->getSession()->getPage();
29 $web_assert = $this->assertSession();
30
31 // Make sure off-canvas dialog is on page when first loaded.
32 $web_assert->elementNotExists('css', '#drupal-off-canvas');
33
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
37 // removed.
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();
42
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();
48
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 }
74 }
75 }
76
77 /**
78 * Tests the body displacement behaves differently at a narrow width.
79 */
80 public function testNarrowWidth() {
81 $narrow_width_breakpoint = 768;
82 $offset = 20;
83 $height = 800;
84 $page = $this->getSession()->getPage();
85 $web_assert = $this->assertSession();
86
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
97 // tray is open.
98 $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'style', 'padding-right');
99
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.');
107 }
108 }
109
110 }