Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -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])) {
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\tour\Tests;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
|
||||
use Drupal\tour\Entity\Tour;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the Tour entity's cache tags.
|
||||
*
|
||||
* @group tour
|
||||
*/
|
||||
class TourCacheTagsTest extends PageCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('tour', 'tour_test');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Give anonymous users permission to view nodes, so that we can verify the
|
||||
// cache tags of cached versions of node pages.
|
||||
Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('access tour')
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cache tags presence and invalidation of the Tour entity.
|
||||
*
|
||||
* Tests the following cache tags:
|
||||
* - 'tour:<tour ID>'
|
||||
*/
|
||||
public function testRenderedTour() {
|
||||
$url = Url::fromRoute('tour_test.1');
|
||||
|
||||
// Prime the page cache.
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit, but also the presence of the correct cache tags.
|
||||
$expected_tags = [
|
||||
'config:tour.tour.tour-test',
|
||||
'config:user.role.anonymous',
|
||||
'rendered',
|
||||
];
|
||||
$this->verifyPageCache($url, 'HIT', $expected_tags);
|
||||
|
||||
// Verify that after modifying the tour, there is a cache miss.
|
||||
$this->pass('Test modification of tour.', 'Debug');
|
||||
Tour::load('tour-test')->save();
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyPageCache($url, 'HIT', $expected_tags);
|
||||
|
||||
// Verify that after deleting the tour, there is a cache miss.
|
||||
$this->pass('Test deletion of tour.', 'Debug');
|
||||
Tour::load('tour-test')->delete();
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$expected_tags = [
|
||||
'config:user.role.anonymous',
|
||||
'rendered',
|
||||
];
|
||||
$this->verifyPageCache($url, 'HIT', $expected_tags);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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.
|
||||
|
|
Reference in a new issue