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