Chris@14: enableTheme($theme); Chris@17: $this->drupalGet('/off-canvas-test-links'); Chris@14: Chris@17: $page = $this->getSession()->getPage(); Chris@17: $web_assert = $this->assertSession(); Chris@14: Chris@17: // Make sure off-canvas dialog is on page when first loaded. Chris@17: $web_assert->elementNotExists('css', '#drupal-off-canvas'); Chris@14: Chris@17: // Check opening and closing with two separate links. Chris@17: // Make sure tray updates to new content. Chris@17: // Check the first link again to make sure the empty title class is Chris@17: // removed. Chris@17: foreach (['1', '2', '1'] as $link_index) { Chris@17: $this->assertOffCanvasDialog($link_index, 'side'); Chris@17: $header_text = $this->getOffCanvasDialog()->find('css', '.ui-dialog-title')->getText(); Chris@17: if ($link_index == '2') { Chris@17: // Check no title behavior. Chris@17: $web_assert->elementExists('css', '.ui-dialog-empty-title'); Chris@17: $this->assertEquals(' ', $header_text); Chris@17: Chris@17: $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style'); Chris@17: $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.'); Chris@17: $page->clickLink("Open side panel 1"); Chris@14: $this->waitForOffCanvasToOpen(); Chris@17: $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style'); Chris@17: $this->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.'); Chris@17: } Chris@17: else { Chris@17: // Check that header is correct. Chris@17: $this->assertEquals("Thing $link_index", $header_text); Chris@17: $web_assert->elementNotExists('css', '.ui-dialog-empty-title'); Chris@14: } Chris@14: } Chris@17: Chris@17: // Test the off_canvas_top tray. Chris@17: foreach ([1, 2] as $link_index) { Chris@17: $this->assertOffCanvasDialog($link_index, 'top'); Chris@17: Chris@17: $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style'); Chris@17: if ($link_index === 1) { Chris@17: $this->assertTrue((bool) strstr($style, 'height: auto;')); Chris@17: } Chris@17: else { Chris@17: $this->assertTrue((bool) strstr($style, 'height: 421px;')); Chris@17: } Chris@17: } Chris@17: Chris@17: // Ensure an off-canvas link opened from inside the off-canvas dialog will Chris@17: // work. Chris@17: $this->drupalGet('/off-canvas-test-links'); Chris@17: $page->clickLink('Display more links!'); Chris@17: $this->waitForOffCanvasToOpen(); Chris@17: $web_assert->linkExists('Off_canvas link!'); Chris@17: // Click off-canvas link inside off-canvas dialog Chris@17: $page->clickLink('Off_canvas link!'); Chris@17: /* @var \Behat\Mink\Element\NodeElement $dialog */ Chris@17: $this->waitForOffCanvasToOpen(); Chris@17: $web_assert->elementTextContains('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]', 'Thing 2 says hello'); Chris@17: Chris@17: // Ensure an off-canvas link opened from inside the off-canvas dialog will Chris@17: // work after another dialog has been opened. Chris@17: $this->drupalGet('/off-canvas-test-links'); Chris@17: $page->clickLink("Open side panel 1"); Chris@17: $this->waitForOffCanvasToOpen(); Chris@17: $page->clickLink('Display more links!'); Chris@17: $this->waitForOffCanvasToOpen(); Chris@17: $web_assert->linkExists('Off_canvas link!'); Chris@17: // Click off-canvas link inside off-canvas dialog Chris@17: $page->clickLink('Off_canvas link!'); Chris@17: /* @var \Behat\Mink\Element\NodeElement $dialog */ Chris@17: $this->waitForOffCanvasToOpen(); Chris@17: $web_assert->elementTextContains('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]', 'Thing 2 says hello'); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Tests the body displacement behaves differently at a narrow width. Chris@14: */ Chris@14: public function testNarrowWidth() { Chris@14: $narrow_width_breakpoint = 768; Chris@14: $offset = 20; Chris@14: $height = 800; Chris@14: $page = $this->getSession()->getPage(); Chris@14: $web_assert = $this->assertSession(); Chris@14: Chris@14: // Test the same functionality on multiple themes. Chris@14: foreach ($this->getTestThemes() as $theme) { Chris@14: $this->enableTheme($theme); Chris@14: // Testing at the wider width. Chris@14: $this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height); Chris@14: $this->drupalGet('/off-canvas-test-links'); Chris@14: $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.'); Chris@17: $page->clickLink("Open side panel 1"); Chris@14: $this->waitForOffCanvasToOpen(); Chris@14: // Check that the main canvas is padded when page is not narrow width and Chris@14: // tray is open. Chris@17: $page->waitFor(10, function ($page) { Chris@17: return $page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'); Chris@17: }); Chris@14: $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'style', 'padding-right'); Chris@14: Chris@14: // Testing at the narrower width. Chris@14: $this->getSession()->resizeWindow($narrow_width_breakpoint - $offset, $height); Chris@14: $this->drupalGet('/off-canvas-test-links'); Chris@14: $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.'); Chris@17: $page->clickLink("Open side panel 1"); Chris@14: $this->waitForOffCanvasToOpen(); Chris@14: $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.'); Chris@14: } Chris@14: } Chris@14: Chris@17: /** Chris@17: * @param int $link_index Chris@17: * The index of the link to test. Chris@17: * @param string $position Chris@17: * The position of the dialog to test. Chris@17: */ Chris@17: protected function assertOffCanvasDialog($link_index, $position) { Chris@17: $page = $this->getSession()->getPage(); Chris@17: $web_assert = $this->assertSession(); Chris@17: $link_text = "Open $position panel $link_index"; Chris@17: Chris@17: // Click the first test like that should open the page. Chris@17: $page->clickLink($link_text); Chris@17: if ($this->lastDialogClass) { Chris@17: $this->waitForNoElement('.' . $this->lastDialogClass); Chris@17: } Chris@17: $this->waitForOffCanvasToOpen($position); Chris@17: $this->lastDialogClass = "$position-$link_index"; Chris@17: Chris@17: // Check that response text is on page. Chris@17: $web_assert->pageTextContains("Thing $link_index says hello"); Chris@17: $off_canvas_tray = $this->getOffCanvasDialog(); Chris@17: Chris@17: // Check that tray is visible. Chris@17: $this->assertEquals(TRUE, $off_canvas_tray->isVisible()); Chris@17: Chris@17: $tray_text = $off_canvas_tray->findById('drupal-off-canvas')->getText(); Chris@17: $this->assertEquals("Thing $link_index says hello", $tray_text); Chris@17: } Chris@17: Chris@14: }