Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -59,7 +59,7 @@ class Tour extends ConfigEntityBase implements TourInterface {
*
* @var array
*/
protected $routes = array();
protected $routes = [];
/**
* The routes on which this tour should be displayed, keyed by route id.
@ -80,7 +80,7 @@ class Tour extends ConfigEntityBase implements TourInterface {
*
* @var array
*/
protected $tips = array();
protected $tips = [];
/**
* {@inheritdoc}
@ -109,7 +109,7 @@ class Tour extends ConfigEntityBase implements TourInterface {
* {@inheritdoc}
*/
public function getTips() {
$tips = array();
$tips = [];
foreach ($this->tips as $id => $tip) {
$tips[] = $this->getTip($id);
}
@ -136,9 +136,9 @@ class Tour extends ConfigEntityBase implements TourInterface {
*/
public function hasMatchingRoute($route_name, $route_params) {
if (!isset($this->keyedRoutes)) {
$this->keyedRoutes = array();
$this->keyedRoutes = [];
foreach ($this->getRoutes() as $route) {
$this->keyedRoutes[$route['route_name']] = isset($route['route_params']) ? $route['route_params'] : array();
$this->keyedRoutes[$route['route_name']] = isset($route['route_params']) ? $route['route_params'] : [];
}
}
if (!isset($this->keyedRoutes[$route_name])) {

View file

@ -116,7 +116,7 @@ class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInter
public function getOutput() {
$output = '<h2 class="tour-tip-label" id="tour-tip-' . $this->getAriaId() . '-label">' . Html::escape($this->getLabel()) . '</h2>';
$output .= '<p class="tour-tip-body" id="tour-tip-' . $this->getAriaId() . '-contents">' . $this->token->replace($this->getBody()) . '</p>';
return array('#markup' => $output);
return ['#markup' => $output];
}
}

View file

@ -25,7 +25,7 @@ class TourTest extends TourTestBasic {
* @var array
* A list of permissions.
*/
protected $permissions = array('access tour', 'administer languages');
protected $permissions = ['access tour', 'administer languages'];
/**
* Tour tip attributes to be tested. Keyed by the path.
@ -33,9 +33,9 @@ class TourTest extends TourTestBasic {
* @var array
* An array of tip attributes, keyed by path.
*/
protected $tips = array(
'tour-test-1' => array(),
);
protected $tips = [
'tour-test-1' => [],
];
/**
* {@inheritdoc}
@ -57,18 +57,18 @@ class TourTest extends TourTestBasic {
$this->drupalGet('tour-test-1');
// Test the TourTestBase class assertTourTips() method.
$tips = array();
$tips[] = array('data-id' => 'tour-test-1');
$tips[] = array('data-class' => 'tour-test-5');
$tips = [];
$tips[] = ['data-id' => 'tour-test-1'];
$tips[] = ['data-class' => 'tour-test-5'];
$this->assertTourTips($tips);
$this->assertTourTips();
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', array(
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', [
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
':data_id' => 'tour-test-1',
':href' => \Drupal::url('<front>', [], ['absolute' => TRUE]),
':text' => 'Drupal',
));
]);
$this->assertEqual(count($elements), 1, 'Found Token replacement.');
$elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')");
@ -104,43 +104,43 @@ class TourTest extends TourTestBasic {
$this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.');
// Programmatically create a tour for use through the remainder of the test.
$tour = Tour::create(array(
$tour = Tour::create([
'id' => 'tour-entity-create-test-en',
'label' => 'Tour test english',
'langcode' => 'en',
'module' => 'system',
'routes' => array(
array('route_name' => 'tour_test.1'),
),
'tips' => array(
'tour-test-1' => array(
'routes' => [
['route_name' => 'tour_test.1'],
],
'tips' => [
'tour-test-1' => [
'id' => 'tour-code-test-1',
'plugin' => 'text',
'label' => 'The rain in spain',
'body' => 'Falls mostly on the plain.',
'weight' => '100',
'attributes' => array(
'attributes' => [
'data-id' => 'tour-code-test-1',
),
),
'tour-code-test-2' => array(
],
],
'tour-code-test-2' => [
'id' => 'tour-code-test-2',
'plugin' => 'image',
'label' => 'The awesome image',
'url' => 'http://local/image.png',
'weight' => 1,
'attributes' => array(
'attributes' => [
'data-id' => 'tour-code-test-2'
),
),
),
));
],
],
],
]);
$tour->save();
// Ensure that a tour entity has the expected dependencies based on plugin
// providers and the module named in the configuration entity.
$dependencies = $tour->calculateDependencies()->getDependencies();
$this->assertEqual($dependencies['module'], array('system', 'tour_test'));
$this->assertEqual($dependencies['module'], ['system', 'tour_test']);
$this->drupalGet('tour-test-1');
@ -167,21 +167,21 @@ class TourTest extends TourTestBasic {
// Navigate to tour-test-3 and verify the tour_test_1 tip is found with
// appropriate classes.
$this->drupalGet('tour-test-3/foo');
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', array(
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
':data_id' => 'tour-test-1',
':text' => 'The first tip',
));
]);
$this->assertEqual(count($elements), 1, 'Found English variant of tip 1.');
// Navigate to tour-test-3 and verify the tour_test_1 tip is not found with
// appropriate classes.
$this->drupalGet('tour-test-3/bar');
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', array(
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
':data_id' => 'tour-test-1',
':text' => 'The first tip',
));
]);
$this->assertEqual(count($elements), 0, 'Did not find English variant of tip 1.');
}

View file

@ -29,7 +29,7 @@ abstract class TourTestBase extends WebTestBase {
* $this->assertTourTips($tips);
* @endcode
*/
public function assertTourTips($tips = array()) {
public function assertTourTips($tips = []) {
// Get the rendered tips and their data-id and data-class attributes.
if (empty($tips)) {
// Tips are rendered as <li> elements inside <ol id="tour">.
@ -51,11 +51,11 @@ abstract class TourTestBase extends WebTestBase {
foreach ($tips as $tip) {
if (!empty($tip['data-id'])) {
$elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $this->content, TRUE);
$this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', array('%data-id' => $tip['data-id'])));
$this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']]));
}
elseif (!empty($tip['data-class'])) {
$elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $this->content, TRUE);
$this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', array('%data-class' => $tip['data-class'])));
$this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']]));
}
else {
// It's a modal.
@ -63,7 +63,7 @@ abstract class TourTestBase extends WebTestBase {
}
$total++;
}
$this->pass(format_string('Total %total Tips tested of which %modals modal(s).', array('%total' => $total, '%modals' => $modals)));
$this->pass(format_string('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals]));
}
}

View file

@ -22,7 +22,7 @@ abstract class TourTestBasic extends TourTestBase {
* );
* @endcode
*/
protected $tips = array();
protected $tips = [];
/**
* An admin user with administrative permissions for tour.
@ -37,14 +37,14 @@ abstract class TourTestBasic extends TourTestBase {
* @var array
* A list of permissions.
*/
protected $permissions = array('access tour');
protected $permissions = ['access tour'];
protected function setUp() {
parent::setUp();
// Make sure we are using distinct default and administrative themes for
// the duration of these tests.
$this->container->get('theme_handler')->install(array('bartik', 'seven'));
$this->container->get('theme_handler')->install(['bartik', 'seven']);
$this->config('system.theme')
->set('default', 'bartik')
->set('admin', 'seven')

View file

@ -13,35 +13,35 @@ class TourViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
/** @var \Drupal\tour\TourInterface[] $entities */
$build = array();
$build = [];
foreach ($entities as $entity_id => $entity) {
$tips = $entity->getTips();
$count = count($tips);
$list_items = array();
$list_items = [];
foreach ($tips as $index => $tip) {
if ($output = $tip->getOutput()) {
$attributes = array(
'class' => array(
$attributes = [
'class' => [
'tip-module-' . Html::cleanCssIdentifier($entity->getModule()),
'tip-type-' . Html::cleanCssIdentifier($tip->getPluginId()),
'tip-' . Html::cleanCssIdentifier($tip->id()),
),
);
$list_items[] = array(
],
];
$list_items[] = [
'output' => $output,
'counter' => array(
'counter' => [
'#type' => 'container',
'#attributes' => array(
'class' => array(
'#attributes' => [
'class' => [
'tour-progress',
),
),
'#children' => t('@tour_item of @total', array('@tour_item' => $index + 1, '@total' => $count)),
),
],
],
'#children' => t('@tour_item of @total', ['@tour_item' => $index + 1, '@total' => $count]),
],
'#wrapper_attributes' => $tip->getAttributes() + $attributes,
);
];
}
}
// If there is at least one tour item, build the tour.
@ -49,20 +49,20 @@ class TourViewBuilder extends EntityViewBuilder {
end($list_items);
$key = key($list_items);
$list_items[$key]['#wrapper_attributes']['data-text'] = t('End tour');
$build[$entity_id] = array(
$build[$entity_id] = [
'#theme' => 'item_list',
'#items' => $list_items,
'#list_type' => 'ol',
'#attributes' => array(
'#attributes' => [
'id' => 'tour',
'class' => array(
'class' => [
'hidden',
),
),
],
],
'#cache' => [
'tags' => $entity->getCacheTags(),
],
);
];
}
}
// If at least one tour was built, attach the tour library.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\tour\Tests;
namespace Drupal\Tests\tour\Functional;
use Drupal\Core\Url;
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
@ -18,7 +18,7 @@ class TourCacheTagsTest extends PageCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('tour', 'tour_test');
public static $modules = ['tour', 'tour_test'];
/**
* {@inheritdoc}
@ -48,6 +48,7 @@ class TourCacheTagsTest extends PageCacheTagsTestBase {
$expected_tags = [
'config:tour.tour.tour-test',
'config:user.role.anonymous',
'http_response',
'rendered',
];
$this->verifyPageCache($url, 'HIT', $expected_tags);
@ -68,6 +69,7 @@ class TourCacheTagsTest extends PageCacheTagsTestBase {
// Verify a cache hit.
$expected_tags = [
'config:user.role.anonymous',
'http_response',
'rendered',
];
$this->verifyPageCache($url, 'HIT', $expected_tags);

View file

@ -16,7 +16,7 @@ class TourPluginTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('tour');
public static $modules = ['tour'];
/**
* Stores the tour plugin manager.
@ -28,7 +28,7 @@ class TourPluginTest extends KernelTestBase {
protected function setUp() {
parent::setUp();
$this->installConfig(array('tour'));
$this->installConfig(['tour']);
$this->pluginManager = $this->container->get('plugin.manager.tour.tip');
}

View file

@ -29,7 +29,7 @@ class TourTest extends UnitTestCase {
public function testHasMatchingRoute($routes, $route_name, $route_params, $result) {
$tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour')
->disableOriginalConstructor()
->setMethods(array('getRoutes'))
->setMethods(['getRoutes'])
->getMock();
$tour->expects($this->any())
@ -45,94 +45,94 @@ class TourTest extends UnitTestCase {
* Provides sample routes for testing.
*/
public function routeProvider() {
return array(
return [
// Simple match.
array(
array(
array('route_name' => 'some.route'),
),
[
[
['route_name' => 'some.route'],
],
'some.route',
array(),
[],
TRUE,
),
],
// Simple non-match.
array(
array(
array('route_name' => 'another.route'),
),
[
[
['route_name' => 'another.route'],
],
'some.route',
array(),
[],
FALSE,
),
],
// Empty params.
array(
array(
array(
[
[
[
'route_name' => 'some.route',
'route_params' => array('foo' => 'bar'),
),
),
'route_params' => ['foo' => 'bar'],
],
],
'some.route',
array(),
[],
FALSE,
),
],
// Match on params.
array(
array(
array(
[
[
[
'route_name' => 'some.route',
'route_params' => array('foo' => 'bar'),
),
),
'route_params' => ['foo' => 'bar'],
],
],
'some.route',
array('foo' => 'bar'),
['foo' => 'bar'],
TRUE,
),
],
// Non-matching params.
array(
array(
array(
[
[
[
'route_name' => 'some.route',
'route_params' => array('foo' => 'bar'),
),
),
'route_params' => ['foo' => 'bar'],
],
],
'some.route',
array('bar' => 'foo'),
['bar' => 'foo'],
FALSE,
),
],
// One matching, one not.
array(
array(
array(
[
[
[
'route_name' => 'some.route',
'route_params' => array('foo' => 'bar'),
),
array(
'route_params' => ['foo' => 'bar'],
],
[
'route_name' => 'some.route',
'route_params' => array('bar' => 'foo'),
),
),
'route_params' => ['bar' => 'foo'],
],
],
'some.route',
array('bar' => 'foo'),
['bar' => 'foo'],
TRUE,
),
],
// One matching, one not.
array(
array(
array(
[
[
[
'route_name' => 'some.route',
'route_params' => array('foo' => 'bar'),
),
array(
'route_params' => ['foo' => 'bar'],
],
[
'route_name' => 'some.route',
'route_params' => array('foo' => 'baz'),
),
),
'route_params' => ['foo' => 'baz'],
],
],
'some.route',
array('foo' => 'baz'),
['foo' => 'baz'],
TRUE,
),
);
],
];
}
}

View file

@ -18,56 +18,56 @@ class TourTestController {
* Array of markup.
*/
public function tourTest1($locale = 'foo') {
return array(
'tip-1' => array(
return [
'tip-1' => [
'#type' => 'container',
'#attributes' => array(
'#attributes' => [
'id' => 'tour-test-1',
),
],
'#children' => t('Where does the rain in Spain fail?'),
),
'tip-3' => array(
],
'tip-3' => [
'#type' => 'container',
'#attributes' => array(
'#attributes' => [
'id' => 'tour-test-3',
),
],
'#children' => t('Tip created now?'),
),
'tip-4' => array(
],
'tip-4' => [
'#type' => 'container',
'#attributes' => array(
'#attributes' => [
'id' => 'tour-test-4',
),
],
'#children' => t('Tip created later?'),
),
'tip-5' => array(
],
'tip-5' => [
'#type' => 'container',
'#attributes' => array(
'class' => array('tour-test-5'),
),
'#attributes' => [
'class' => ['tour-test-5'],
],
'#children' => t('Tip created later?'),
),
'code-tip-1' => array(
],
'code-tip-1' => [
'#type' => 'container',
'#attributes' => array(
'#attributes' => [
'id' => 'tour-code-test-1',
),
],
'#children' => t('Tip created now?'),
),
);
],
];
}
/**
* Outputs some content for testing tours.
*/
public function tourTest2() {
return array(
return [
'#type' => 'container',
'#attributes' => array(
'#attributes' => [
'id' => 'tour-test-2',
),
],
'#children' => t('Pangram example'),
);
];
}

View file

@ -16,13 +16,13 @@ function tour_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.tour':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t("The Tour module provides users with guided tours of the site interface. Each tour consists of several tips that highlight elements of the user interface, guide the user through a workflow, or explain key concepts of the website. For more information, see the <a href=':tour'>online documentation for the Tour module</a>.", array(':tour' => 'https://www.drupal.org/documentation/modules/tour')) . '</p>';
$output .= '<p>' . t("The Tour module provides users with guided tours of the site interface. Each tour consists of several tips that highlight elements of the user interface, guide the user through a workflow, or explain key concepts of the website. For more information, see the <a href=':tour'>online documentation for the Tour module</a>.", [':tour' => 'https://www.drupal.org/documentation/modules/tour']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Viewing tours') . '</dt>';
$output .= '<dd>' . t("If a tour is available on a page, a <em>Tour</em> button will be visible in the toolbar. If you click this button the first tip of the tour will appear. The tour continues after clicking the <em>Next</em> button in the tip. To see a tour users must have the permission <em>Access tour</em> and JavaScript must be enabled in the browser") . '</dd>';
$output .= '<dt>' . t('Creating tours') . '</dt>';
$output .= '<dd>' . t("Tours can be written as YAML-documents with a text editor, or using the contributed <a href=':tour_ui'>Tour UI</a> module. For more information, see <a href=':doc_url'>the online documentation for writing tours</a>.", array(':doc_url' => 'https://www.drupal.org/developing/api/tour', ':tour_ui' => 'https://www.drupal.org/project/tour_ui')) . '</dd>';
$output .= '<dd>' . t("Tours can be written as YAML-documents with a text editor, or using the contributed <a href=':tour_ui'>Tour UI</a> module. For more information, see <a href=':doc_url'>the online documentation for writing tours</a>.", [':doc_url' => 'https://www.drupal.org/developing/api/tour', ':tour_ui' => 'https://www.drupal.org/project/tour_ui']) . '</dd>';
$output .= '</dl>';
return $output;
}
@ -45,27 +45,27 @@ function tour_toolbar() {
return $items;
}
$items['tour'] += array(
$items['tour'] += [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => t('Tour'),
'#attributes' => array(
'class' => array('toolbar-icon', 'toolbar-icon-help'),
'#attributes' => [
'class' => ['toolbar-icon', 'toolbar-icon-help'],
'aria-pressed' => 'false',
),
),
'#wrapper_attributes' => array(
'class' => array('tour-toolbar-tab', 'hidden'),
],
],
'#wrapper_attributes' => [
'class' => ['tour-toolbar-tab', 'hidden'],
'id' => 'toolbar-tab-tour',
),
'#attached' => array(
'library' => array(
],
'#attached' => [
'library' => [
'tour/tour',
),
),
);
],
],
];
return $items;
}