Core and composer updates
This commit is contained in:
parent
a82634bb98
commit
62cac30480
1118 changed files with 21770 additions and 6306 deletions
|
|
@ -0,0 +1,29 @@
|
|||
off_canvas_test.links:
|
||||
path: '/off-canvas-test-links'
|
||||
defaults:
|
||||
_controller: '\Drupal\off_canvas_test\Controller\TestController::linksDisplay'
|
||||
_title: 'Links'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
off_canvas_test.thing1:
|
||||
path: '/off-canvas-thing1'
|
||||
defaults:
|
||||
_controller: '\Drupal\off_canvas_test\Controller\TestController::thing1'
|
||||
_title: 'Thing 1'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
off_canvas_test.thing2:
|
||||
path: '/off-canvas-thing2'
|
||||
defaults:
|
||||
_controller: '\Drupal\off_canvas_test\Controller\TestController::thing2'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
off_canvas_test.dialog_links:
|
||||
path: '/off-canvas-dialog-links'
|
||||
defaults:
|
||||
_controller: '\Drupal\off_canvas_test\Controller\TestController::otherDialogLinks'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\offcanvas_test\Controller;
|
||||
namespace Drupal\off_canvas_test\Controller;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Url;
|
||||
|
|
@ -37,21 +37,21 @@ class TestController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Displays test links that will open in offcanvas tray.
|
||||
* Displays test links that will open in off-canvas dialog.
|
||||
*
|
||||
* @return array
|
||||
* Render array with links.
|
||||
*/
|
||||
public function linksDisplay() {
|
||||
return [
|
||||
'offcanvas_link_1' => [
|
||||
'off_canvas_link_1' => [
|
||||
'#title' => 'Click Me 1!',
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.thing1'),
|
||||
'#url' => Url::fromRoute('off_canvas_test.thing1'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
'data-dialog-renderer' => 'off_canvas',
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
|
|
@ -59,14 +59,14 @@ class TestController {
|
|||
],
|
||||
],
|
||||
],
|
||||
'offcanvas_link_2' => [
|
||||
'off_canvas_link_2' => [
|
||||
'#title' => 'Click Me 2!',
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'#url' => Url::fromRoute('off_canvas_test.thing2'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
'data-dialog-renderer' => 'off_canvas',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 555,
|
||||
]),
|
||||
|
|
@ -80,11 +80,11 @@ class TestController {
|
|||
'other_dialog_links' => [
|
||||
'#title' => 'Display more links!',
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.dialog_links'),
|
||||
'#url' => Url::fromRoute('off_canvas_test.dialog_links'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
'data-dialog-renderer' => 'off_canvas',
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
|
|
@ -96,12 +96,12 @@ class TestController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Displays dialogs links to be displayed inside the offcanvas tray.
|
||||
* Displays dialogs links to be displayed inside the off-canvas dialog.
|
||||
*
|
||||
* This links are used to test opening a modal and another offcanvas link from
|
||||
* inside the offcanvas tray.
|
||||
* This links are used to test opening a modal and another off_canvas link from
|
||||
* inside the off-canvas dialog.
|
||||
*
|
||||
* @todo Update tests to check these links work in the offcanvas tray.
|
||||
* @todo Update tests to check these links work in the off-canvas dialog.
|
||||
* https://www.drupal.org/node/2790073
|
||||
*
|
||||
* @return array
|
||||
|
|
@ -113,19 +113,19 @@ class TestController {
|
|||
'#links' => [
|
||||
'modal_link' => [
|
||||
'title' => 'Open modal!',
|
||||
'url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'url' => Url::fromRoute('off_canvas_test.thing2'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
],
|
||||
],
|
||||
'offcanvas_link' => [
|
||||
'title' => 'Offcanvas link!',
|
||||
'url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'off_canvas_link' => [
|
||||
'title' => 'Off_canvas link!',
|
||||
'url' => Url::fromRoute('off_canvas_test.thing2'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
'data-dialog-renderer' => 'off_canvas',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
offcanvas_test.links:
|
||||
path: '/offcanvas-test-links'
|
||||
defaults:
|
||||
_controller: '\Drupal\offcanvas_test\Controller\TestController::linksDisplay'
|
||||
_title: 'Links'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
offcanvas_test.thing1:
|
||||
path: '/offcanvas-thing1'
|
||||
defaults:
|
||||
_controller: '\Drupal\offcanvas_test\Controller\TestController::thing1'
|
||||
_title: 'Thing 1'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
offcanvas_test.thing2:
|
||||
path: '/offcanvas-thing2'
|
||||
defaults:
|
||||
_controller: '\Drupal\offcanvas_test\Controller\TestController::thing2'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
offcanvas_test.dialog_links:
|
||||
path: '/offcanvas-dialog-links'
|
||||
defaults:
|
||||
_controller: '\Drupal\offcanvas_test\Controller\TestController::otherDialogLinks'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\outside_in\FunctionalJavascript;
|
||||
|
||||
/**
|
||||
* Tests the off-canvas tray functionality.
|
||||
* Tests the off-canvas dialog functionality.
|
||||
*
|
||||
* @group outside_in
|
||||
*/
|
||||
|
|
@ -12,23 +12,28 @@ class OffCanvasTest extends OutsideInJavascriptTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block', 'system', 'toolbar', 'outside_in', 'offcanvas_test'];
|
||||
public static $modules = [
|
||||
'block',
|
||||
'system',
|
||||
'toolbar',
|
||||
'outside_in',
|
||||
'off_canvas_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests that regular non-contextual links will work with the off-canvas tray.
|
||||
* Tests that non-contextual links will work with the off-canvas dialog.
|
||||
*/
|
||||
public function testOffCanvasLinks() {
|
||||
$themes = ['bartik', 'stark'];
|
||||
// Test the same functionality on multiple themes.
|
||||
foreach ($themes as $theme) {
|
||||
foreach ($this->getTestThemes() as $theme) {
|
||||
$this->enableTheme($theme);
|
||||
$this->drupalGet('/offcanvas-test-links');
|
||||
$this->drupalGet('/off-canvas-test-links');
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
$web_assert = $this->assertSession();
|
||||
|
||||
// Make sure off-canvas tray is on page when first loaded.
|
||||
$web_assert->elementNotExists('css', '#drupal-offcanvas');
|
||||
// Make sure off-canvas dialog is on page when first loaded.
|
||||
$web_assert->elementNotExists('css', '#drupal-off-canvas');
|
||||
|
||||
// Check opening and closing with two separate links.
|
||||
// Make sure tray updates to new content.
|
||||
|
|
@ -40,16 +45,16 @@ class OffCanvasTest extends OutsideInJavascriptTestBase {
|
|||
$this->waitForOffCanvasToOpen();
|
||||
|
||||
// Check that the canvas is not on the page.
|
||||
$web_assert->elementExists('css', '#drupal-offcanvas');
|
||||
$web_assert->elementExists('css', '#drupal-off-canvas');
|
||||
// Check that response text is on page.
|
||||
$web_assert->pageTextContains("Thing $link_index says hello");
|
||||
$offcanvas_tray = $this->getTray();
|
||||
$off_canvas_tray = $this->getTray();
|
||||
|
||||
// Check that tray is visible.
|
||||
$this->assertEquals(TRUE, $offcanvas_tray->isVisible());
|
||||
$header_text = $offcanvas_tray->find('css', '.ui-dialog-title')->getText();
|
||||
$this->assertEquals(TRUE, $off_canvas_tray->isVisible());
|
||||
$header_text = $off_canvas_tray->find('css', '.ui-dialog-title')->getText();
|
||||
|
||||
$tray_text = $offcanvas_tray->findById('drupal-offcanvas')->getText();
|
||||
$tray_text = $off_canvas_tray->findById('drupal-off-canvas')->getText();
|
||||
$this->assertEquals("Thing $link_index says hello", $tray_text);
|
||||
|
||||
if ($link_index == '2') {
|
||||
|
|
@ -57,7 +62,7 @@ class OffCanvasTest extends OutsideInJavascriptTestBase {
|
|||
$web_assert->elementExists('css', '.ui-dialog-empty-title');
|
||||
$this->assertEquals('', $header_text);
|
||||
|
||||
$style = $page->find('css', '.ui-dialog-offcanvas')->getAttribute('style');
|
||||
$style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
|
||||
self::assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
|
||||
}
|
||||
else {
|
||||
|
|
@ -73,7 +78,6 @@ class OffCanvasTest extends OutsideInJavascriptTestBase {
|
|||
* Tests the body displacement behaves differently at a narrow width.
|
||||
*/
|
||||
public function testNarrowWidth() {
|
||||
$themes = ['stark', 'bartik'];
|
||||
$narrow_width_breakpoint = 768;
|
||||
$offset = 20;
|
||||
$height = 800;
|
||||
|
|
@ -81,26 +85,35 @@ class OffCanvasTest extends OutsideInJavascriptTestBase {
|
|||
$web_assert = $this->assertSession();
|
||||
|
||||
// Test the same functionality on multiple themes.
|
||||
foreach ($themes as $theme) {
|
||||
foreach ($this->getTestThemes() as $theme) {
|
||||
$this->enableTheme($theme);
|
||||
// Testing at the wider width.
|
||||
$this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height);
|
||||
$this->drupalGet('/offcanvas-test-links');
|
||||
$this->assertFalse($page->find('css', '.dialog-offcanvas__main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
|
||||
$this->drupalGet('/off-canvas-test-links');
|
||||
$this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
|
||||
$page->clickLink("Click Me 1!");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
// Check that the main canvas is padded when page is not narrow width and
|
||||
// tray is open.
|
||||
$web_assert->elementAttributeContains('css', '.dialog-offcanvas__main-canvas', 'style', 'padding-right');
|
||||
$web_assert->elementAttributeContains('css', '.dialog-off-canvas__main-canvas', 'style', 'padding-right');
|
||||
|
||||
// Testing at the narrower width.
|
||||
$this->getSession()->resizeWindow($narrow_width_breakpoint - $offset, $height);
|
||||
$this->drupalGet('/offcanvas-test-links');
|
||||
$this->assertFalse($page->find('css', '.dialog-offcanvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.');
|
||||
$this->drupalGet('/off-canvas-test-links');
|
||||
$this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.');
|
||||
$page->clickLink("Click Me 1!");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
$this->assertFalse($page->find('css', '.dialog-offcanvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.');
|
||||
$this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTestThemes() {
|
||||
// Add 'seven' theme. Setting Tray "Edit Mode" will not work with 'seven'
|
||||
// because it removes all contextual links the off-canvas dialog should.
|
||||
return array_merge(parent::getTestThemes(), ['seven']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
namespace Drupal\Tests\outside_in\FunctionalJavascript;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Testing opening and saving block forms in the off-canvas tray.
|
||||
* Testing opening and saving block forms in the off-canvas dialog.
|
||||
*
|
||||
* @group outside_in
|
||||
*/
|
||||
|
|
@ -26,6 +29,7 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
'outside_in',
|
||||
'quickedit',
|
||||
'search',
|
||||
'block_content',
|
||||
// Add test module to override CSS pointer-events properties because they
|
||||
// cause test failures.
|
||||
'outside_in_test_css',
|
||||
|
|
@ -36,9 +40,9 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// @todo Ensure that this test class works against bartik and stark:
|
||||
// https://www.drupal.org/node/2784881.
|
||||
$this->enableTheme('bartik');
|
||||
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
$block_content = $this->createBlockContent('Custom Block', 'basic', TRUE);
|
||||
$user = $this->createUser([
|
||||
'administer blocks',
|
||||
'access contextual links',
|
||||
|
|
@ -48,87 +52,91 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
'search content',
|
||||
]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$this->placeBlock('system_powered_by_block', ['id' => 'powered']);
|
||||
$this->placeBlock('system_branding_block', ['id' => 'branding']);
|
||||
$this->placeBlock('search_form_block', ['id' => 'search']);
|
||||
$this->placeBlock('block_content:' . $block_content->uuid(), ['id' => 'custom']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests opening Offcanvas tray by click blocks and elements in the blocks.
|
||||
* Tests opening off-canvas dialog by click blocks and elements in the blocks.
|
||||
*
|
||||
* @dataProvider providerTestBlocks
|
||||
*/
|
||||
public function testBlocks($block_id, $new_page_text, $element_selector, $label_selector, $button_text, $toolbar_item) {
|
||||
public function testBlocks($block_plugin, $new_page_text, $element_selector, $label_selector, $button_text, $toolbar_item) {
|
||||
$web_assert = $this->assertSession();
|
||||
$page = $this->getSession()->getPage();
|
||||
$block_selector = '#' . $block_id;
|
||||
$this->drupalGet('user');
|
||||
if (isset($toolbar_item)) {
|
||||
// Check that you can open a toolbar tray and it will be closed after
|
||||
// entering edit mode.
|
||||
if ($element = $page->find('css', "#toolbar-administration a.is-active")) {
|
||||
// If a tray was open from page load close it.
|
||||
$element->click();
|
||||
$this->waitForNoElement("#toolbar-administration a.is-active");
|
||||
foreach ($this->getTestThemes() as $theme) {
|
||||
$this->enableTheme($theme);
|
||||
$block = $this->placeBlock($block_plugin);
|
||||
$block_selector = str_replace('_', '-', $this->getBlockSelector($block));
|
||||
$block_id = $block->id();
|
||||
$this->drupalGet('user');
|
||||
|
||||
$link = $page->find('css', "$block_selector .contextual-links li a");
|
||||
$this->assertEquals('Quick edit', $link->getText(), "'Quick edit' is the first contextual link for the block.");
|
||||
$this->assertContains("/admin/structure/block/manage/$block_id/off-canvas?destination=user/2", $link->getAttribute('href'));
|
||||
|
||||
if (isset($toolbar_item)) {
|
||||
// Check that you can open a toolbar tray and it will be closed after
|
||||
// entering edit mode.
|
||||
if ($element = $page->find('css', "#toolbar-administration a.is-active")) {
|
||||
// If a tray was open from page load close it.
|
||||
$element->click();
|
||||
$this->waitForNoElement("#toolbar-administration a.is-active");
|
||||
}
|
||||
$page->find('css', $toolbar_item)->click();
|
||||
$web_assert->waitForElementVisible('css', "{$toolbar_item}.is-active");
|
||||
}
|
||||
$page->find('css', $toolbar_item)->click();
|
||||
$web_assert->waitForElementVisible('css', "{$toolbar_item}.is-active");
|
||||
$this->enableEditMode();
|
||||
if (isset($toolbar_item)) {
|
||||
$this->waitForNoElement("{$toolbar_item}.is-active");
|
||||
}
|
||||
$this->openBlockForm($block_selector);
|
||||
switch ($block_plugin) {
|
||||
case 'system_powered_by_block':
|
||||
// Fill out form, save the form.
|
||||
$page->fillField('settings[label]', $new_page_text);
|
||||
$page->checkField('settings[label_display]');
|
||||
break;
|
||||
|
||||
case 'system_branding_block':
|
||||
// Fill out form, save the form.
|
||||
$page->fillField('settings[site_information][site_name]', $new_page_text);
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($new_page_text)) {
|
||||
$page->pressButton($button_text);
|
||||
// Make sure the changes are present.
|
||||
// @todo Use a wait method that will take into account the form submitting
|
||||
// and all JavaScript activity. https://www.drupal.org/node/2837676
|
||||
// The use \Behat\Mink\WebAssert::pageTextContains to check text.
|
||||
$this->assertJsCondition('jQuery("' . $block_selector . ' ' . $label_selector . '").html() == "' . $new_page_text . '"');
|
||||
}
|
||||
|
||||
$this->openBlockForm($block_selector);
|
||||
|
||||
$this->disableEditMode();
|
||||
// Canvas should close when editing module is closed.
|
||||
$this->waitForOffCanvasToClose();
|
||||
|
||||
$this->enableEditMode();
|
||||
|
||||
// Open block form by clicking a element inside the block.
|
||||
// This confirms that default action for links and form elements is
|
||||
// suppressed.
|
||||
$this->openBlockForm("$block_selector {$element_selector}");
|
||||
$web_assert->elementTextContains('css', '.contextual-toolbar-tab button', 'Editing');
|
||||
$web_assert->elementAttributeContains('css', '.dialog-off-canvas__main-canvas', 'class', 'js-outside-in-edit-mode');
|
||||
// Simulate press the Escape key.
|
||||
$this->getSession()->executeScript('jQuery("body").trigger(jQuery.Event("keyup", { keyCode: 27 }));');
|
||||
$this->waitForOffCanvasToClose();
|
||||
$this->getSession()->wait(100);
|
||||
$this->assertEditModeDisabled();
|
||||
$web_assert->elementTextContains('css', '#drupal-live-announce', 'Exited edit mode.');
|
||||
$web_assert->elementTextNotContains('css', '.contextual-toolbar-tab button', 'Editing');
|
||||
$web_assert->elementAttributeNotContains('css', '.dialog-off-canvas__main-canvas', 'class', 'js-outside-in-edit-mode');
|
||||
// Delete the block that was placed for the current theme.
|
||||
$block->delete();
|
||||
}
|
||||
$this->enableEditMode();
|
||||
if (isset($toolbar_item)) {
|
||||
$this->waitForNoElement("{$toolbar_item}.is-active");
|
||||
}
|
||||
|
||||
$this->openBlockForm($block_selector);
|
||||
|
||||
switch ($block_id) {
|
||||
case 'block-powered':
|
||||
// Fill out form, save the form.
|
||||
$page->fillField('settings[label]', $new_page_text);
|
||||
$page->checkField('settings[label_display]');
|
||||
break;
|
||||
|
||||
case 'block-branding':
|
||||
// Fill out form, save the form.
|
||||
$page->fillField('settings[site_information][site_name]', $new_page_text);
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($new_page_text)) {
|
||||
$page->pressButton($button_text);
|
||||
// Make sure the changes are present.
|
||||
// @todo Use a wait method that will take into account the form submitting
|
||||
// and all JavaScript activity. https://www.drupal.org/node/2837676
|
||||
// The use \Behat\Mink\WebAssert::pageTextContains to check text.
|
||||
$this->assertJsCondition('jQuery("' . $block_selector . ' ' . $label_selector . '").html() == "' . $new_page_text . '"');
|
||||
}
|
||||
|
||||
$this->openBlockForm($block_selector);
|
||||
|
||||
$this->disableEditMode();
|
||||
// Canvas should close when editing module is closed.
|
||||
$this->waitForOffCanvasToClose();
|
||||
|
||||
$this->enableEditMode();
|
||||
|
||||
$element_selector = "$block_selector {$element_selector}";
|
||||
// Open block form by clicking a element inside the block.
|
||||
// This confirms that default action for links and form elements is
|
||||
// suppressed.
|
||||
$this->openBlockForm($element_selector);
|
||||
|
||||
// Exit edit mode using ESC.
|
||||
$web_assert->elementTextContains('css', '.contextual-toolbar-tab button', 'Editing');
|
||||
$web_assert->elementAttributeContains('css', '.dialog-offcanvas__main-canvas', 'class', 'js-outside-in-edit-mode');
|
||||
// Simulate press the Escape key.
|
||||
$this->getSession()->executeScript('jQuery("body").trigger(jQuery.Event("keyup", { keyCode: 27 }));');
|
||||
$this->waitForOffCanvasToClose();
|
||||
$this->getSession()->wait(100);
|
||||
$this->assertEditModeDisabled();
|
||||
$web_assert->elementTextContains('css', '#drupal-live-announce', 'Exited edit mode.');
|
||||
$web_assert->elementTextNotContains('css', '.contextual-toolbar-tab button', 'Editing');
|
||||
$web_assert->elementAttributeNotContains('css', '.dialog-offcanvas__main-canvas', 'class', 'js-outside-in-edit-mode');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -137,23 +145,23 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
public function providerTestBlocks() {
|
||||
$blocks = [
|
||||
'block-powered' => [
|
||||
'id' => 'block-powered',
|
||||
'block_plugin' => 'system_powered_by_block',
|
||||
'new_page_text' => 'Can you imagine anyone showing the label on this block?',
|
||||
'element_selector' => '.content a',
|
||||
'element_selector' => 'span a',
|
||||
'label_selector' => 'h2',
|
||||
'button_text' => 'Save Powered by Drupal',
|
||||
'toolbar_item' => '#toolbar-item-user',
|
||||
],
|
||||
'block-branding' => [
|
||||
'id' => 'block-branding',
|
||||
'block_plugin' => 'system_branding_block',
|
||||
'new_page_text' => 'The site that will live a very short life.',
|
||||
'element_selector' => 'a[rel="home"]:nth-child(2)',
|
||||
'label_selector' => '.site-branding__name a',
|
||||
'element_selector' => "a[rel='home']:last-child",
|
||||
'label_selector' => "a[rel='home']:last-child",
|
||||
'button_text' => 'Save Site branding',
|
||||
'toolbar_item' => '#toolbar-item-administration',
|
||||
],
|
||||
'block-search' => [
|
||||
'id' => 'block-search',
|
||||
'block_plugin' => 'search_form_block',
|
||||
'new_page_text' => NULL,
|
||||
'element_selector' => '#edit-submit',
|
||||
'label_selector' => 'h2',
|
||||
|
|
@ -169,6 +177,7 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
*/
|
||||
protected function enableEditMode() {
|
||||
$this->pressToolbarEditButton();
|
||||
$this->waitForToolbarToLoad();
|
||||
$this->assertEditModeEnabled();
|
||||
}
|
||||
|
||||
|
|
@ -177,6 +186,7 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
*/
|
||||
protected function disableEditMode() {
|
||||
$this->pressToolbarEditButton();
|
||||
$this->waitForToolbarToLoad();
|
||||
$this->assertEditModeDisabled();
|
||||
}
|
||||
|
||||
|
|
@ -200,6 +210,7 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
* A css selector selects the block or an element within it.
|
||||
*/
|
||||
protected function openBlockForm($block_selector) {
|
||||
$this->waitForToolbarToLoad();
|
||||
$this->click($block_selector);
|
||||
$this->waitForOffCanvasToOpen();
|
||||
$this->assertOffCanvasBlockFormIsValid();
|
||||
|
|
@ -210,8 +221,8 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
*/
|
||||
public function testQuickEditLinks() {
|
||||
$quick_edit_selector = '#quickedit-entity-toolbar';
|
||||
$body_selector = '.field--name-body p';
|
||||
$block_selector = '#block-powered';
|
||||
$node_selector = '[data-quickedit-entity-id="node/1"]';
|
||||
$body_selector = '[data-quickedit-field-id="node/1/body/en/full"]';
|
||||
$web_assert = $this->assertSession();
|
||||
// Create a Content type and two test nodes.
|
||||
$this->createContentType(['type' => 'page']);
|
||||
|
|
@ -233,87 +244,99 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
]
|
||||
);
|
||||
$page = $this->getSession()->getPage();
|
||||
// Load the same page twice.
|
||||
foreach ([1, 2] as $page_load_times) {
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
// Waiting for Toolbar module.
|
||||
// @todo Remove the hack after https://www.drupal.org/node/2542050.
|
||||
$web_assert->waitForElementVisible('css', '.toolbar-fixed');
|
||||
// Waiting for Toolbar animation.
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
// The 2nd page load we should already be in edit mode.
|
||||
if ($page_load_times == 1) {
|
||||
$block_plugin = 'system_powered_by_block';
|
||||
|
||||
foreach ($this->getTestThemes() as $theme) {
|
||||
|
||||
$this->enableTheme($theme);
|
||||
|
||||
$block = $this->placeBlock($block_plugin);
|
||||
$block_selector = str_replace('_', '-', $this->getBlockSelector($block));
|
||||
// Load the same page twice.
|
||||
foreach ([1, 2] as $page_load_times) {
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
// Waiting for Toolbar module.
|
||||
// @todo Remove the hack after https://www.drupal.org/node/2542050.
|
||||
$web_assert->waitForElementVisible('css', '.toolbar-fixed');
|
||||
// Waiting for Toolbar animation.
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
// The 2nd page load we should already be in edit mode.
|
||||
if ($page_load_times == 1) {
|
||||
$this->enableEditMode();
|
||||
}
|
||||
// In Edit mode clicking field should open QuickEdit toolbar.
|
||||
$page->find('css', $body_selector)->click();
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
|
||||
$this->disableEditMode();
|
||||
// Exiting Edit mode should close QuickEdit toolbar.
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
// When not in Edit mode QuickEdit toolbar should not open.
|
||||
$page->find('css', $body_selector)->click();
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
$this->enableEditMode();
|
||||
$this->openBlockForm($block_selector);
|
||||
$page->find('css', $body_selector)->click();
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
// Off-canvas dialog should be closed when opening QuickEdit toolbar.
|
||||
$this->waitForOffCanvasToClose();
|
||||
|
||||
$this->openBlockForm($block_selector);
|
||||
// QuickEdit toolbar should be closed when opening Off-canvas dialog.
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
}
|
||||
// In Edit mode clicking field should open QuickEdit toolbar.
|
||||
$page->find('css', $body_selector)->click();
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
|
||||
// Check using contextual links to invoke QuickEdit and open the tray.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
$this->disableEditMode();
|
||||
// Exiting Edit mode should close QuickEdit toolbar.
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
// When not in Edit mode QuickEdit toolbar should not open.
|
||||
$page->find('css', $body_selector)->click();
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
|
||||
$this->enableEditMode();
|
||||
$this->openBlockForm($block_selector);
|
||||
$page->find('css', $body_selector)->click();
|
||||
// Open QuickEdit toolbar before going into Edit mode.
|
||||
$this->clickContextualLink($node_selector, "Quick edit");
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
// Offcanvas should be closed when opening QuickEdit toolbar.
|
||||
$this->waitForOffCanvasToClose();
|
||||
|
||||
$this->openBlockForm($block_selector);
|
||||
// QuickEdit toolbar should be closed when opening Offcanvas.
|
||||
// Open off-canvas and enter Edit mode via contextual link.
|
||||
$this->clickContextualLink($block_selector, "Quick edit");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
// QuickEdit toolbar should be closed when opening off-canvas dialog.
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
// Open QuickEdit toolbar via contextual link while in Edit mode.
|
||||
$this->clickContextualLink($node_selector, "Quick edit", FALSE);
|
||||
$this->waitForOffCanvasToClose();
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
$this->disableEditMode();
|
||||
}
|
||||
|
||||
// Check using contextual links to invoke QuickEdit and open the tray.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
$this->disableEditMode();
|
||||
// Open QuickEdit toolbar before going into Edit mode.
|
||||
$this->clickContextualLink('.node', "Quick edit");
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
// Open off-canvas and enter Edit mode via contextual link.
|
||||
$this->clickContextualLink($block_selector, "Quick edit");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
// QuickEdit toolbar should be closed when opening Offcanvas.
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
// Open QuickEdit toolbar via contextual link while in Edit mode.
|
||||
$this->clickContextualLink('.node', "Quick edit", FALSE);
|
||||
$this->waitForOffCanvasToClose();
|
||||
$web_assert->waitForElementVisible('css', $quick_edit_selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests enabling and disabling Edit Mode.
|
||||
*/
|
||||
public function testEditModeEnableDisable() {
|
||||
foreach (['contextual_link', 'toolbar_link'] as $enable_option) {
|
||||
$this->drupalGet('user');
|
||||
$this->assertEditModeDisabled();
|
||||
switch ($enable_option) {
|
||||
// Enable Edit mode.
|
||||
case 'contextual_link':
|
||||
$this->clickContextualLink('#block-powered', "Quick edit");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
$this->assertEditModeEnabled();
|
||||
break;
|
||||
foreach ($this->getTestThemes() as $theme) {
|
||||
$this->enableTheme($theme);
|
||||
$block = $this->placeBlock('system_powered_by_block');
|
||||
foreach (['contextual_link', 'toolbar_link'] as $enable_option) {
|
||||
$this->drupalGet('user');
|
||||
$this->assertEditModeDisabled();
|
||||
switch ($enable_option) {
|
||||
// Enable Edit mode.
|
||||
case 'contextual_link':
|
||||
$this->clickContextualLink($this->getBlockSelector($block), "Quick edit");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
$this->assertEditModeEnabled();
|
||||
break;
|
||||
|
||||
case 'toolbar_link':
|
||||
$this->enableEditMode();
|
||||
break;
|
||||
case 'toolbar_link':
|
||||
$this->enableEditMode();
|
||||
break;
|
||||
}
|
||||
$this->disableEditMode();
|
||||
|
||||
// Make another page request to ensure Edit mode is still disabled.
|
||||
$this->drupalGet('user');
|
||||
$this->assertEditModeDisabled();
|
||||
// Make sure on this page request it also re-enables and disables
|
||||
// correctly.
|
||||
$this->enableEditMode();
|
||||
$this->disableEditMode();
|
||||
}
|
||||
$this->disableEditMode();
|
||||
|
||||
// Make another page request to ensure Edit mode is still disabled.
|
||||
$this->drupalGet('user');
|
||||
$this->assertEditModeDisabled();
|
||||
// Make sure on this page request it also re-enables and disables
|
||||
// correctly.
|
||||
$this->enableEditMode();
|
||||
$this->disableEditMode();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -327,7 +350,7 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
// The toolbar edit button should read "Editing".
|
||||
$web_assert->elementContains('css', static::TOOLBAR_EDIT_LINK_SELECTOR, 'Editing');
|
||||
// The main canvas element should have the "js-outside-in-edit-mode" class.
|
||||
$web_assert->elementExists('css', '.dialog-offcanvas__main-canvas.js-outside-in-edit-mode');
|
||||
$web_assert->elementExists('css', '.dialog-off-canvas__main-canvas.js-outside-in-edit-mode');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -343,25 +366,107 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
|||
$web_assert->elementContains('css', static::TOOLBAR_EDIT_LINK_SELECTOR, 'Edit');
|
||||
// The main canvas element should NOT have the "js-outside-in-edit-mode"
|
||||
// class.
|
||||
$web_assert->elementNotExists('css', '.dialog-offcanvas__main-canvas.js-outside-in-edit-mode');
|
||||
$web_assert->elementNotExists('css', '.dialog-off-canvas__main-canvas.js-outside-in-edit-mode');
|
||||
}
|
||||
|
||||
/**
|
||||
* Press the toolbar Edit button provided by the contextual module.
|
||||
*/
|
||||
protected function pressToolbarEditButton() {
|
||||
$this->assertSession()
|
||||
->waitForElementVisible('css', 'div[data-contextual-id="block:block=powered:langcode=en|outside_in::langcode=en"] .contextual-links a', 10000);
|
||||
// Waiting for QuickEdit icon animation.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
|
||||
$this->assertSession()->waitForElement('css', '[data-contextual-id] .contextual-links a');
|
||||
$edit_button = $this->getSession()
|
||||
->getPage()
|
||||
->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR);
|
||||
|
||||
$edit_button->press();
|
||||
// Waiting for Toolbar animation.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block.
|
||||
*
|
||||
* @param bool|string $title
|
||||
* (optional) Title of block. When no value is given uses a random name.
|
||||
* Defaults to FALSE.
|
||||
* @param string $bundle
|
||||
* (optional) Bundle name. Defaults to 'basic'.
|
||||
* @param bool $save
|
||||
* (optional) Whether to save the block. Defaults to TRUE.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
|
||||
$title = $title ?: $this->randomName();
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en',
|
||||
'body' => [
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
]);
|
||||
if ($block_content && $save === TRUE) {
|
||||
$block_content->save();
|
||||
}
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block type (bundle).
|
||||
*
|
||||
* @param string $label
|
||||
* The block type label.
|
||||
* @param bool $create_body
|
||||
* Whether or not to create the body field.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContentType
|
||||
* Created custom block type.
|
||||
*/
|
||||
protected function createBlockContentType($label, $create_body = FALSE) {
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $label,
|
||||
'label' => $label,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
if ($create_body) {
|
||||
block_content_add_body_field($bundle->id());
|
||||
}
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that contextual links in custom blocks are changed.
|
||||
*
|
||||
* "Quick edit" is quickedit.module link.
|
||||
* "Quick edit settings" is outside_in.module link.
|
||||
*/
|
||||
public function testCustomBlockLinks() {
|
||||
$this->drupalGet('user');
|
||||
$page = $this->getSession()->getPage();
|
||||
$links = $page->findAll('css', "#block-custom .contextual-links li a");
|
||||
$link_labels = [];
|
||||
/** @var \Behat\Mink\Element\NodeElement $link */
|
||||
foreach ($links as $link) {
|
||||
$link_labels[$link->getAttribute('href')] = $link->getText();
|
||||
}
|
||||
$href = array_search('Quick edit', $link_labels);
|
||||
$this->assertEquals('', $href);
|
||||
$href = array_search('Quick edit settings', $link_labels);
|
||||
$this->assertTrue(strstr($href, '/admin/structure/block/manage/custom/off-canvas?destination=user/2') !== FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block CSS selector.
|
||||
*
|
||||
* @param \Drupal\block\Entity\Block $block
|
||||
* The block.
|
||||
*
|
||||
* @return string
|
||||
* The CSS selector.
|
||||
*/
|
||||
public function getBlockSelector(Block $block) {
|
||||
return '#block-' . $block->id();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,28 +37,28 @@ abstract class OutsideInJavascriptTestBase extends JavascriptTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Waits for Off-canvas tray to open.
|
||||
* Waits for off-canvas dialog to open.
|
||||
*/
|
||||
protected function waitForOffCanvasToOpen() {
|
||||
$web_assert = $this->assertSession();
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
$web_assert->waitForElementVisible('css', '#drupal-offcanvas');
|
||||
$web_assert->waitForElementVisible('css', '#drupal-off-canvas');
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for Off-canvas tray to close.
|
||||
* Waits for off-canvas dialog to close.
|
||||
*/
|
||||
protected function waitForOffCanvasToClose() {
|
||||
$this->waitForNoElement('#drupal-offcanvas');
|
||||
$this->waitForNoElement('#drupal-off-canvas');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Off-Canvas tray element.
|
||||
* Gets the off-canvas dialog element.
|
||||
*
|
||||
* @return \Behat\Mink\Element\NodeElement|null
|
||||
*/
|
||||
protected function getTray() {
|
||||
$tray = $this->getSession()->getPage()->find('css', '.ui-dialog[aria-describedby="drupal-offcanvas"]');
|
||||
$tray = $this->getSession()->getPage()->find('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]');
|
||||
$this->assertEquals(FALSE, empty($tray), 'The tray was found.');
|
||||
return $tray;
|
||||
}
|
||||
|
|
@ -118,4 +118,26 @@ abstract class OutsideInJavascriptTestBase extends JavascriptTestBase {
|
|||
$this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for Toolbar to load.
|
||||
*/
|
||||
protected function waitForToolbarToLoad() {
|
||||
$web_assert = $this->assertSession();
|
||||
// Waiting for Toolbar module.
|
||||
// @todo Remove the hack after https://www.drupal.org/node/2542050.
|
||||
$web_assert->waitForElementVisible('css', '.toolbar-fixed');
|
||||
// Waiting for Toolbar animation.
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get themes to test.
|
||||
*
|
||||
* @return string[]
|
||||
* Theme names to test.
|
||||
*/
|
||||
protected function getTestThemes() {
|
||||
return ['bartik', 'stark', 'classy', 'stable'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class OpenOffCanvasDialogCommandTest extends UnitTestCase {
|
|||
|
||||
$expected = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-offcanvas',
|
||||
'selector' => '#drupal-off-canvas',
|
||||
'settings' => NULL,
|
||||
'data' => '<p>Text!</p>',
|
||||
'dialogOptions' => [
|
||||
|
|
|
|||
Reference in a new issue