Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
name: 'Off-canvas tests'
|
||||
type: module
|
||||
description: 'Provides off-canvas test links.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- block
|
||||
- outside_in
|
|
@ -0,0 +1,29 @@
|
|||
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'
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\offcanvas_test\Controller;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Test controller for 2 different responses.
|
||||
*/
|
||||
class TestController {
|
||||
|
||||
/**
|
||||
* Thing1.
|
||||
*
|
||||
* @return string
|
||||
* Return Hello string.
|
||||
*/
|
||||
public function thing1() {
|
||||
return [
|
||||
'#type' => 'markup',
|
||||
'#markup' => 'Thing 1 says hello',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Thing2.
|
||||
*
|
||||
* @return string
|
||||
* Return Hello string.
|
||||
*/
|
||||
public function thing2() {
|
||||
return [
|
||||
'#type' => 'markup',
|
||||
'#markup' => 'Thing 2 says hello',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays test links that will open in offcanvas tray.
|
||||
*
|
||||
* @return array
|
||||
* Render array with links.
|
||||
*/
|
||||
public function linksDisplay() {
|
||||
return [
|
||||
'offcanvas_link_1' => [
|
||||
'#title' => 'Click Me 1!',
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.thing1'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'outside_in/drupal.outside_in',
|
||||
],
|
||||
],
|
||||
],
|
||||
'offcanvas_link_2' => [
|
||||
'#title' => 'Click Me 2!',
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 555,
|
||||
]),
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'outside_in/drupal.outside_in',
|
||||
],
|
||||
],
|
||||
],
|
||||
'other_dialog_links' => [
|
||||
'#title' => 'Display more links!',
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.dialog_links'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'outside_in/drupal.outside_in',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays dialogs links to be displayed inside the offcanvas tray.
|
||||
*
|
||||
* This links are used to test opening a modal and another offcanvas link from
|
||||
* inside the offcanvas tray.
|
||||
*
|
||||
* @todo Update tests to check these links work in the offcanvas tray.
|
||||
* https://www.drupal.org/node/2790073
|
||||
*
|
||||
* @return array
|
||||
* Render array with links.
|
||||
*/
|
||||
public function otherDialogLinks() {
|
||||
return [
|
||||
'#theme' => 'links',
|
||||
'#links' => [
|
||||
'modal_link' => [
|
||||
'title' => 'Open modal!',
|
||||
'url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
],
|
||||
],
|
||||
'offcanvas_link' => [
|
||||
'title' => 'Offcanvas link!',
|
||||
'url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-renderer' => 'offcanvas',
|
||||
],
|
||||
],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'outside_in/drupal.outside_in',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\offcanvas_test\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Provides an 'Off-canvas test block' block.
|
||||
*
|
||||
* @Block(
|
||||
* id = "offcanvas_links_block",
|
||||
* admin_label = @Translation("Off-canvas test block")
|
||||
* )
|
||||
*/
|
||||
class TestBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return [
|
||||
'offcanvas_link_1' => [
|
||||
'#title' => $this->t('Click Me 1!'),
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.thing1'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'offcanvas',
|
||||
],
|
||||
],
|
||||
'offcanvas_link_2' => [
|
||||
'#title' => $this->t('Click Me 2!'),
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute('offcanvas_test.thing2'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'offcanvas',
|
||||
],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'outside_in/drupal.off_canvas',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#main-canvas.js-outside-in-edit-mode a,
|
||||
#main-canvas.js-outside-in-edit-mode input {
|
||||
pointer-events: inherit !important;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
name: 'CSS Test fix'
|
||||
type: module
|
||||
description: 'Provides CSS fixes for tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- outside_in
|
|
@ -0,0 +1,5 @@
|
|||
drupal.css_fix:
|
||||
version: VERSION
|
||||
css:
|
||||
theme:
|
||||
css/css_fix.theme.css: {}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module for attaching CSS during tests.
|
||||
*
|
||||
* CSS pointer-events properties cause testing errors.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_page_attachments().
|
||||
*/
|
||||
function outside_in_test_css_page_attachments(array &$attachments) {
|
||||
// Unconditionally attach an asset to the page.
|
||||
$attachments['#attached']['library'][] = 'outside_in_test_css/drupal.css_fix';
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\outside_in\FunctionalJavascript;
|
||||
|
||||
/**
|
||||
* Tests the off-canvas tray functionality.
|
||||
*
|
||||
* @group outside_in
|
||||
*/
|
||||
class OffCanvasTest extends OutsideInJavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block', 'system', 'toolbar', 'outside_in', 'offcanvas_test'];
|
||||
|
||||
/**
|
||||
* Tests that regular non-contextual links will work with the off-canvas tray.
|
||||
*/
|
||||
public function testOffCanvasLinks() {
|
||||
$themes = ['bartik', 'stark'];
|
||||
// Test the same functionality on multiple themes.
|
||||
foreach ($themes as $theme) {
|
||||
$this->enableTheme($theme);
|
||||
$this->drupalGet('/offcanvas-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');
|
||||
|
||||
// Check opening and closing with two separate links.
|
||||
// Make sure tray updates to new content.
|
||||
// Check the first link again to make sure the empty title class is
|
||||
// removed.
|
||||
foreach (['1', '2', '1'] as $link_index) {
|
||||
// Click the first test like that should open the page.
|
||||
$page->clickLink("Click Me $link_index!");
|
||||
$this->waitForOffCanvasToOpen();
|
||||
|
||||
// Check that the canvas is not on the page.
|
||||
$web_assert->elementExists('css', '#drupal-offcanvas');
|
||||
// Check that response text is on page.
|
||||
$web_assert->pageTextContains("Thing $link_index says hello");
|
||||
$offcanvas_tray = $this->getTray();
|
||||
|
||||
// Check that tray is visible.
|
||||
$this->assertEquals(TRUE, $offcanvas_tray->isVisible());
|
||||
$header_text = $offcanvas_tray->find('css', '.ui-dialog-title')->getText();
|
||||
|
||||
$tray_text = $offcanvas_tray->findById('drupal-offcanvas')->getText();
|
||||
$this->assertEquals("Thing $link_index says hello", $tray_text);
|
||||
|
||||
if ($link_index == '2') {
|
||||
// Check no title behavior.
|
||||
$web_assert->elementExists('css', '.ui-dialog-empty-title');
|
||||
$this->assertEquals('', $header_text);
|
||||
|
||||
$style = $page->find('css', '.ui-dialog-offcanvas')->getAttribute('style');
|
||||
self::assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
|
||||
}
|
||||
else {
|
||||
// Check that header is correct.
|
||||
$this->assertEquals("Thing $link_index", $header_text);
|
||||
$web_assert->elementNotExists('css', '.ui-dialog-empty-title');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the body displacement behaves differently at a narrow width.
|
||||
*/
|
||||
public function testNarrowWidth() {
|
||||
$themes = ['stark', 'bartik'];
|
||||
$narrow_width_breakpoint = 768;
|
||||
$offset = 20;
|
||||
$height = 800;
|
||||
$page = $this->getSession()->getPage();
|
||||
$web_assert = $this->assertSession();
|
||||
|
||||
// Test the same functionality on multiple themes.
|
||||
foreach ($themes 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.');
|
||||
$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');
|
||||
|
||||
// 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.');
|
||||
$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.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,287 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\outside_in\FunctionalJavascript;
|
||||
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Testing opening and saving block forms in the off-canvas tray.
|
||||
*
|
||||
* @group outside_in
|
||||
*/
|
||||
class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'node',
|
||||
'block',
|
||||
'system',
|
||||
'breakpoint',
|
||||
'toolbar',
|
||||
'contextual',
|
||||
'outside_in',
|
||||
'quickedit',
|
||||
'search',
|
||||
// Add test module to override CSS pointer-events properties because they
|
||||
// cause test failures.
|
||||
'outside_in_test_css',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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');
|
||||
$user = $this->createUser([
|
||||
'administer blocks',
|
||||
'access contextual links',
|
||||
'access toolbar',
|
||||
'administer nodes',
|
||||
'access in-place editing',
|
||||
'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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests opening Offcanvas tray 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) {
|
||||
$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");
|
||||
}
|
||||
$page->find('css', $toolbar_item)->click();
|
||||
$this->waitForElement("{$toolbar_item}.is-active");
|
||||
}
|
||||
$this->toggleEditingMode();
|
||||
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->toggleEditingMode();
|
||||
// Canvas should close when editing module is closed.
|
||||
$this->waitForOffCanvasToClose();
|
||||
|
||||
// Go into Edit mode again.
|
||||
$this->toggleEditingMode();
|
||||
|
||||
$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);
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dataprovider for testBlocks().
|
||||
*/
|
||||
public function providerTestBlocks() {
|
||||
$blocks = [
|
||||
'block-powered' => [
|
||||
'id' => 'block-powered',
|
||||
'new_page_text' => 'Can you imagine anyone showing the label on this block?',
|
||||
'element_selector' => '.content a',
|
||||
'label_selector' => 'h2',
|
||||
'button_text' => 'Save Powered by Drupal',
|
||||
'toolbar_item' => '#toolbar-item-user',
|
||||
],
|
||||
'block-branding' => [
|
||||
'id' => 'block-branding',
|
||||
'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',
|
||||
'button_text' => 'Save Site branding',
|
||||
'toolbar_item' => '#toolbar-item-administration',
|
||||
],
|
||||
'block-search' => [
|
||||
'id' => 'block-search',
|
||||
'new_page_text' => NULL,
|
||||
'element_selector' => '#edit-submit',
|
||||
'label_selector' => 'h2',
|
||||
'button_text' => 'Save Search form',
|
||||
'toolbar_item' => NULL,
|
||||
],
|
||||
];
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables Editing mode by pressing "Edit" button in the toolbar.
|
||||
*/
|
||||
protected function toggleEditingMode() {
|
||||
$this->waitForElement('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();
|
||||
|
||||
$edit_button = $this->getSession()->getPage()->find('css', '#toolbar-bar div.contextual-toolbar-tab button');
|
||||
|
||||
$edit_button->press();
|
||||
// Waiting for Toolbar animation.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that Off-Canvas block form is valid.
|
||||
*/
|
||||
protected function assertOffCanvasBlockFormIsValid() {
|
||||
$web_assert = $this->assertSession();
|
||||
// Check that common block form elements exist.
|
||||
$web_assert->elementExists('css', 'input[data-drupal-selector="edit-settings-label"]');
|
||||
$web_assert->elementExists('css', 'input[data-drupal-selector="edit-settings-label-display"]');
|
||||
// Check that advanced block form elements do not exist.
|
||||
$web_assert->elementNotExists('css', 'input[data-drupal-selector="edit-visibility-request-path-pages"]');
|
||||
$web_assert->elementNotExists('css', 'select[data-drupal-selector="edit-region"]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Open block form by clicking the element found with a css selector.
|
||||
*
|
||||
* @param string $block_selector
|
||||
* A css selector selects the block or an element within it.
|
||||
*/
|
||||
protected function openBlockForm($block_selector) {
|
||||
$this->click($block_selector);
|
||||
$this->waitForOffCanvasToOpen();
|
||||
$this->assertOffCanvasBlockFormIsValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests QuickEdit links behavior.
|
||||
*/
|
||||
public function testQuickEditLinks() {
|
||||
$quick_edit_selector = '#quickedit-entity-toolbar';
|
||||
$body_selector = '.field--name-body p';
|
||||
$block_selector = '#block-powered';
|
||||
$web_assert = $this->assertSession();
|
||||
// Create a Content type and two test nodes.
|
||||
$this->createContentType(['type' => 'page']);
|
||||
$auth_role = Role::load(Role::AUTHENTICATED_ID);
|
||||
$this->grantPermissions($auth_role, [
|
||||
'edit any page content',
|
||||
'access content',
|
||||
]);
|
||||
$node = $this->createNode(
|
||||
[
|
||||
'title' => 'Page One',
|
||||
'type' => 'page',
|
||||
'body' => [
|
||||
[
|
||||
'value' => 'Regular NODE body for the test.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$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.
|
||||
$this->waitForElement('.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->toggleEditingMode();
|
||||
}
|
||||
// In Edit mode clicking field should open QuickEdit toolbar.
|
||||
$page->find('css', $body_selector)->click();
|
||||
$this->waitForElement($quick_edit_selector);
|
||||
// Exit Edit mode.
|
||||
$this->toggleEditingMode();
|
||||
// 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);
|
||||
|
||||
// Enter Edit mode.
|
||||
$this->toggleEditingMode();
|
||||
$this->openBlockForm($block_selector);
|
||||
$page->find('css', $body_selector)->click();
|
||||
$this->waitForElement($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.
|
||||
$web_assert->elementNotExists('css', $quick_edit_selector);
|
||||
}
|
||||
|
||||
// Check using contextual links to invoke QuickEdit and open the tray.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
$this->toggleEditingMode();
|
||||
// Open QuickEdit toolbar before going into Edit mode.
|
||||
$this->clickContextualLink('.node', "Quick edit");
|
||||
$this->waitForElement($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();
|
||||
$this->waitForElement($quick_edit_selector);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\outside_in\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
|
||||
/**
|
||||
* Base class contains common test functionality for the Settings Tray module.
|
||||
*/
|
||||
abstract class OutsideInJavascriptTestBase extends JavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function drupalGet($path, array $options = array(), array $headers = array()) {
|
||||
$return = parent::drupalGet($path, $options, $headers);
|
||||
|
||||
// After the page loaded we need to additionally wait until the settings
|
||||
// tray Ajax activity is done.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a theme.
|
||||
*
|
||||
* @param string $theme
|
||||
* The theme.
|
||||
*/
|
||||
public function enableTheme($theme) {
|
||||
// Enable the theme.
|
||||
\Drupal::service('theme_installer')->install([$theme]);
|
||||
$theme_config = \Drupal::configFactory()->getEditable('system.theme');
|
||||
$theme_config->set('default', $theme);
|
||||
$theme_config->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for Off-canvas tray to open.
|
||||
*/
|
||||
protected function waitForOffCanvasToOpen() {
|
||||
$web_assert = $this->assertSession();
|
||||
$web_assert->assertWaitOnAjaxRequest();
|
||||
$this->waitForElement('#drupal-offcanvas');
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for Off-canvas tray to close.
|
||||
*/
|
||||
protected function waitForOffCanvasToClose() {
|
||||
$this->waitForNoElement('#drupal-offcanvas');
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for an element to appear on the page.
|
||||
*
|
||||
* @param string $selector
|
||||
* CSS selector.
|
||||
* @param int $timeout
|
||||
* (optional) Timeout in milliseconds, defaults to 10000.
|
||||
*/
|
||||
protected function waitForElement($selector, $timeout = 10000) {
|
||||
$condition = "(jQuery('$selector').length > 0)";
|
||||
$this->assertJsCondition($condition, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Off-Canvas tray element.
|
||||
*
|
||||
* @return \Behat\Mink\Element\NodeElement|null
|
||||
*/
|
||||
protected function getTray() {
|
||||
$tray = $this->getSession()->getPage()->find('css', '.ui-dialog[aria-describedby="drupal-offcanvas"]');
|
||||
$this->assertEquals(FALSE, empty($tray), 'The tray was found.');
|
||||
return $tray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for an element to be removed from the page.
|
||||
*
|
||||
* @param string $selector
|
||||
* CSS selector.
|
||||
* @param int $timeout
|
||||
* (optional) Timeout in milliseconds, defaults to 10000.
|
||||
*/
|
||||
protected function waitForNoElement($selector, $timeout = 10000) {
|
||||
$condition = "(jQuery('$selector').length == 0)";
|
||||
$this->assertJsCondition($condition, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clicks a contextual link.
|
||||
*
|
||||
* @todo Remove this function when related trait added in
|
||||
* https://www.drupal.org/node/2821724.
|
||||
*
|
||||
* @param string $selector
|
||||
* The selector for the element that contains the contextual link.
|
||||
* @param string $link_locator
|
||||
* The link id, title, or text.
|
||||
* @param bool $force_visible
|
||||
* If true then the button will be forced to visible so it can be clicked.
|
||||
*/
|
||||
protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {
|
||||
if ($force_visible) {
|
||||
$this->toggleContextualTriggerVisibility($selector);
|
||||
}
|
||||
|
||||
$element = $this->getSession()->getPage()->find('css', $selector);
|
||||
$element->find('css', '.contextual button')->press();
|
||||
$element->findLink($link_locator)->click();
|
||||
|
||||
if ($force_visible) {
|
||||
$this->toggleContextualTriggerVisibility($selector);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the visibility of a contextual trigger.
|
||||
*
|
||||
* @todo Remove this function when related trait added in
|
||||
* https://www.drupal.org/node/2821724.
|
||||
*
|
||||
* @param string $selector
|
||||
* The selector for the element that contains the contextual link.
|
||||
*/
|
||||
protected function toggleContextualTriggerVisibility($selector) {
|
||||
// Hovering over the element itself with should be enough, but does not
|
||||
// work. Manually remove the visually-hidden class.
|
||||
$this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\outside_in\Unit\Ajax;
|
||||
|
||||
use Drupal\outside_in\Ajax\OpenOffCanvasDialogCommand;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\outside_in\Ajax\OpenOffCanvasDialogCommand
|
||||
* @group outside_in
|
||||
*/
|
||||
class OpenOffCanvasDialogCommandTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::render
|
||||
*/
|
||||
public function testRender() {
|
||||
$command = new OpenOffCanvasDialogCommand('Title', '<p>Text!</p>', ['url' => 'example']);
|
||||
|
||||
$expected = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-offcanvas',
|
||||
'settings' => NULL,
|
||||
'data' => '<p>Text!</p>',
|
||||
'dialogOptions' => [
|
||||
'url' => 'example',
|
||||
'title' => 'Title',
|
||||
'modal' => FALSE,
|
||||
'autoResize' => FALSE,
|
||||
'resizable' => 'w',
|
||||
'draggable' => FALSE,
|
||||
'drupalAutoButtons' => FALSE,
|
||||
'buttons' => [],
|
||||
],
|
||||
'effect' => 'fade',
|
||||
'speed' => 1000,
|
||||
];
|
||||
$this->assertEquals($expected, $command->render());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\outside_in\Unit;
|
||||
|
||||
use Drupal\Core\Routing\AdminContext;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\outside_in\OutsideInManager;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\outside_in\OutsideInManager
|
||||
* @group outside_in
|
||||
*/
|
||||
class OutsideInManagerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::isApplicable
|
||||
* @dataProvider providerTestIsApplicable
|
||||
*/
|
||||
public function testIsApplicable($is_admin_route, $route_name, $has_permission, $expected) {
|
||||
$admin_context = $this->prophesize(AdminContext::class);
|
||||
$admin_context->isAdminRoute()->willReturn($is_admin_route);
|
||||
|
||||
$route_match = $this->prophesize(RouteMatchInterface::class);
|
||||
$route_match->getRouteName()->willReturn($route_name);
|
||||
|
||||
$account = $this->prophesize(AccountInterface::class);
|
||||
$account->hasPermission('administer blocks')->willReturn($has_permission);
|
||||
|
||||
$outside_in_manager = new OutsideInManager($admin_context->reveal(), $route_match->reveal(), $account->reveal());
|
||||
|
||||
$this->assertSame($expected, $outside_in_manager->isApplicable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for ::testIsApplicable().
|
||||
*/
|
||||
public function providerTestIsApplicable() {
|
||||
$data = [];
|
||||
|
||||
// Passing combination.
|
||||
$data[] = [FALSE, 'the_route_name', TRUE, TRUE];
|
||||
|
||||
// Failing combinations.
|
||||
$data[] = [TRUE, 'the_route_name', TRUE, FALSE];
|
||||
$data[] = [TRUE, 'the_route_name', FALSE, FALSE];
|
||||
$data[] = [TRUE, 'block.admin_demo', TRUE, FALSE];
|
||||
$data[] = [TRUE, 'block.admin_demo', FALSE, FALSE];
|
||||
$data[] = [FALSE, 'the_route_name', FALSE, FALSE];
|
||||
$data[] = [FALSE, 'block.admin_demo', TRUE, FALSE];
|
||||
$data[] = [FALSE, 'block.admin_demo', FALSE, FALSE];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue