Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -0,0 +1,69 @@
<?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);
// Check no title behavior.
if ($link_index == '2') {
$web_assert->elementExists('css', '.ui-dialog-empty-title');
$this->assertEquals('', $header_text);
}
else {
// Check that header is correct.
$this->assertEquals("Thing $link_index", $header_text);
$web_assert->elementNotExists('css', '.ui-dialog-empty-title');
}
}
}
}
}

View file

@ -0,0 +1,158 @@
<?php
namespace Drupal\Tests\outside_in\FunctionalJavascript;
/**
* 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',
];
/**
* {@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.
*/
public function testBlocks() {
$blocks = [
[
'id' => 'block-powered',
'new_page_text' => 'Can you imagine anyone showing the label on this block?',
'element_selector' => '.content a',
'button_text' => 'Save Powered by Drupal',
],
[
'id' => 'block-branding',
'new_page_text' => 'The site that will live a very short life.',
'element_selector' => 'a[rel="home"]:nth-child(2)',
'button_text' => 'Save Site branding',
],
[
'id' => 'block-search',
'element_selector' => '#edit-submit',
'button_text' => 'Save Search form',
],
];
$page = $this->getSession()->getPage();
foreach ($blocks as $block) {
$block_selector = '#' . $block['id'];
$this->drupalGet('user');
$this->toggleEditingMode();
$this->openBlockForm($block_selector);
switch ($block['id']) {
case 'block-powered':
// Fill out form, save the form.
$page->fillField('settings[label]', $block['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]', $block['new_page_text']);
break;
}
if (isset($block['new_page_text'])) {
$page->pressButton($block['button_text']);
// Make sure the changes are present.
$this->getSession()->wait(500);
$web_assert = $this->assertSession();
$web_assert->pageTextContains($block['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 {$block['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.
$this->toggleEditingMode();
}
}
/**
* 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');
$this->waitForElement('#toolbar-bar', 3000);
$edit_button = $this->getSession()->getPage()->find('css', '#toolbar-bar div.contextual-toolbar-tab button');
$edit_button->press();
}
/**
* 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();
}
}

View file

@ -0,0 +1,67 @@
<?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 {
/**
* 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() {
$condition = "(jQuery('#drupal-offcanvas').length == 0)";
$this->assertJsCondition($condition);
}
/**
* Waits for an element to appear on the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 1000.
*/
protected function waitForElement($selector, $timeout = 1000) {
$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;
}
}

View file

@ -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());
}
}

View file

@ -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;
}
}