updated core to 8.6.1 via composer
This commit is contained in:
+189
-180
@@ -3,7 +3,7 @@
|
||||
* Attaches behaviors for the Tour module's toolbar tab.
|
||||
*/
|
||||
|
||||
(function ($, Backbone, Drupal, document) {
|
||||
(function($, Backbone, Drupal, document) {
|
||||
const queryString = decodeURI(window.location.search);
|
||||
|
||||
/**
|
||||
@@ -25,27 +25,31 @@
|
||||
*/
|
||||
Drupal.behaviors.tour = {
|
||||
attach(context) {
|
||||
$('body').once('tour').each(() => {
|
||||
const model = new Drupal.tour.models.StateModel();
|
||||
new Drupal.tour.views.ToggleTourView({
|
||||
el: $(context).find('#toolbar-tab-tour'),
|
||||
model,
|
||||
$('body')
|
||||
.once('tour')
|
||||
.each(() => {
|
||||
const model = new Drupal.tour.models.StateModel();
|
||||
new Drupal.tour.views.ToggleTourView({
|
||||
el: $(context).find('#toolbar-tab-tour'),
|
||||
model,
|
||||
});
|
||||
|
||||
model
|
||||
// Allow other scripts to respond to tour events.
|
||||
.on('change:isActive', (model, isActive) => {
|
||||
$(document).trigger(
|
||||
isActive ? 'drupalTourStarted' : 'drupalTourStopped',
|
||||
);
|
||||
})
|
||||
// Initialization: check whether a tour is available on the current
|
||||
// page.
|
||||
.set('tour', $(context).find('ol#tour'));
|
||||
|
||||
// Start the tour immediately if toggled via query string.
|
||||
if (/tour=?/i.test(queryString)) {
|
||||
model.set('isActive', true);
|
||||
}
|
||||
});
|
||||
|
||||
model
|
||||
// Allow other scripts to respond to tour events.
|
||||
.on('change:isActive', (model, isActive) => {
|
||||
$(document).trigger((isActive) ? 'drupalTourStarted' : 'drupalTourStopped');
|
||||
})
|
||||
// Initialization: check whether a tour is available on the current
|
||||
// page.
|
||||
.set('tour', $(context).find('ol#tour'));
|
||||
|
||||
// Start the tour immediately if toggled via query string.
|
||||
if (/tour=?/i.test(queryString)) {
|
||||
model.set('isActive', true);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -53,7 +57,6 @@
|
||||
* @namespace
|
||||
*/
|
||||
Drupal.tour = Drupal.tour || {
|
||||
|
||||
/**
|
||||
* @namespace Drupal.tour.models
|
||||
*/
|
||||
@@ -72,159 +75,158 @@
|
||||
*
|
||||
* @augments Backbone.Model
|
||||
*/
|
||||
Drupal.tour.models.StateModel = Backbone.Model.extend(/** @lends Drupal.tour.models.StateModel# */{
|
||||
Drupal.tour.models.StateModel = Backbone.Model.extend(
|
||||
/** @lends Drupal.tour.models.StateModel# */ {
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
defaults: /** @lends Drupal.tour.models.StateModel# */ {
|
||||
/**
|
||||
* Indicates whether the Drupal root window has a tour.
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
tour: [],
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
defaults: /** @lends Drupal.tour.models.StateModel# */{
|
||||
/**
|
||||
* Indicates whether the tour is currently running.
|
||||
*
|
||||
* @type {bool}
|
||||
*/
|
||||
isActive: false,
|
||||
|
||||
/**
|
||||
* Indicates which tour is the active one (necessary to cleanly stop).
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
activeTour: [],
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Drupal.tour.views.ToggleTourView = Backbone.View.extend(
|
||||
/** @lends Drupal.tour.views.ToggleTourView# */ {
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
events: { click: 'onClick' },
|
||||
|
||||
/**
|
||||
* Indicates whether the Drupal root window has a tour.
|
||||
* Handles edit mode toggle interactions.
|
||||
*
|
||||
* @type {Array}
|
||||
* @constructs
|
||||
*
|
||||
* @augments Backbone.View
|
||||
*/
|
||||
tour: [],
|
||||
initialize() {
|
||||
this.listenTo(this.model, 'change:tour change:isActive', this.render);
|
||||
this.listenTo(this.model, 'change:isActive', this.toggleTour);
|
||||
},
|
||||
|
||||
/**
|
||||
* Indicates whether the tour is currently running.
|
||||
* @inheritdoc
|
||||
*
|
||||
* @type {bool}
|
||||
* @return {Drupal.tour.views.ToggleTourView}
|
||||
* The `ToggleTourView` view.
|
||||
*/
|
||||
isActive: false,
|
||||
render() {
|
||||
// Render the visibility.
|
||||
this.$el.toggleClass('hidden', this._getTour().length === 0);
|
||||
// Render the state.
|
||||
const isActive = this.model.get('isActive');
|
||||
this.$el
|
||||
.find('button')
|
||||
.toggleClass('is-active', isActive)
|
||||
.prop('aria-pressed', isActive);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Indicates which tour is the active one (necessary to cleanly stop).
|
||||
*
|
||||
* @type {Array}
|
||||
* Model change handler; starts or stops the tour.
|
||||
*/
|
||||
activeTour: [],
|
||||
},
|
||||
});
|
||||
|
||||
Drupal.tour.views.ToggleTourView = Backbone.View.extend(/** @lends Drupal.tour.views.ToggleTourView# */{
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
events: { click: 'onClick' },
|
||||
|
||||
/**
|
||||
* Handles edit mode toggle interactions.
|
||||
*
|
||||
* @constructs
|
||||
*
|
||||
* @augments Backbone.View
|
||||
*/
|
||||
initialize() {
|
||||
this.listenTo(this.model, 'change:tour change:isActive', this.render);
|
||||
this.listenTo(this.model, 'change:isActive', this.toggleTour);
|
||||
},
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @return {Drupal.tour.views.ToggleTourView}
|
||||
* The `ToggleTourView` view.
|
||||
*/
|
||||
render() {
|
||||
// Render the visibility.
|
||||
this.$el.toggleClass('hidden', this._getTour().length === 0);
|
||||
// Render the state.
|
||||
const isActive = this.model.get('isActive');
|
||||
this.$el.find('button')
|
||||
.toggleClass('is-active', isActive)
|
||||
.prop('aria-pressed', isActive);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Model change handler; starts or stops the tour.
|
||||
*/
|
||||
toggleTour() {
|
||||
if (this.model.get('isActive')) {
|
||||
const $tour = this._getTour();
|
||||
this._removeIrrelevantTourItems($tour, this._getDocument());
|
||||
const that = this;
|
||||
const close = Drupal.t('Close');
|
||||
if ($tour.find('li').length) {
|
||||
$tour.joyride({
|
||||
autoStart: true,
|
||||
postRideCallback() {
|
||||
that.model.set('isActive', false);
|
||||
},
|
||||
// HTML segments for tip layout.
|
||||
template: {
|
||||
link: `<a href="#close" class="joyride-close-tip" aria-label="${close}">×</a>`,
|
||||
button: '<a href="#" class="button button--primary joyride-next-tip"></a>',
|
||||
},
|
||||
});
|
||||
this.model.set({ isActive: true, activeTour: $tour });
|
||||
toggleTour() {
|
||||
if (this.model.get('isActive')) {
|
||||
const $tour = this._getTour();
|
||||
this._removeIrrelevantTourItems($tour, this._getDocument());
|
||||
const that = this;
|
||||
const close = Drupal.t('Close');
|
||||
if ($tour.find('li').length) {
|
||||
$tour.joyride({
|
||||
autoStart: true,
|
||||
postRideCallback() {
|
||||
that.model.set('isActive', false);
|
||||
},
|
||||
// HTML segments for tip layout.
|
||||
template: {
|
||||
link: `<a href="#close" class="joyride-close-tip" aria-label="${close}">×</a>`,
|
||||
button:
|
||||
'<a href="#" class="button button--primary joyride-next-tip"></a>',
|
||||
},
|
||||
});
|
||||
this.model.set({ isActive: true, activeTour: $tour });
|
||||
}
|
||||
} else {
|
||||
this.model.get('activeTour').joyride('destroy');
|
||||
this.model.set({ isActive: false, activeTour: [] });
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.model.get('activeTour').joyride('destroy');
|
||||
this.model.set({ isActive: false, activeTour: [] });
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Toolbar tab click event handler; toggles isActive.
|
||||
*
|
||||
* @param {jQuery.Event} event
|
||||
* The click event.
|
||||
*/
|
||||
onClick(event) {
|
||||
this.model.set('isActive', !this.model.get('isActive'));
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
},
|
||||
/**
|
||||
* Toolbar tab click event handler; toggles isActive.
|
||||
*
|
||||
* @param {jQuery.Event} event
|
||||
* The click event.
|
||||
*/
|
||||
onClick(event) {
|
||||
this.model.set('isActive', !this.model.get('isActive'));
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the tour.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* A jQuery element pointing to a `<ol>` containing tour items.
|
||||
*/
|
||||
_getTour() {
|
||||
return this.model.get('tour');
|
||||
},
|
||||
/**
|
||||
* Gets the tour.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* A jQuery element pointing to a `<ol>` containing tour items.
|
||||
*/
|
||||
_getTour() {
|
||||
return this.model.get('tour');
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the relevant document as a jQuery element.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* A jQuery element pointing to the document within which a tour would be
|
||||
* started given the current state.
|
||||
*/
|
||||
_getDocument() {
|
||||
return $(document);
|
||||
},
|
||||
/**
|
||||
* Gets the relevant document as a jQuery element.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* A jQuery element pointing to the document within which a tour would be
|
||||
* started given the current state.
|
||||
*/
|
||||
_getDocument() {
|
||||
return $(document);
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes tour items for elements that don't have matching page elements.
|
||||
*
|
||||
* Or that are explicitly filtered out via the 'tips' query string.
|
||||
*
|
||||
* @example
|
||||
* <caption>This will filter out tips that do not have a matching
|
||||
* page element or don't have the "bar" class.</caption>
|
||||
* http://example.com/foo?tips=bar
|
||||
*
|
||||
* @param {jQuery} $tour
|
||||
* A jQuery element pointing to a `<ol>` containing tour items.
|
||||
* @param {jQuery} $document
|
||||
* A jQuery element pointing to the document within which the elements
|
||||
* should be sought.
|
||||
*
|
||||
* @see Drupal.tour.views.ToggleTourView#_getDocument
|
||||
*/
|
||||
_removeIrrelevantTourItems($tour, $document) {
|
||||
let removals = false;
|
||||
const tips = /tips=([^&]+)/.exec(queryString);
|
||||
$tour
|
||||
.find('li')
|
||||
.each(function () {
|
||||
/**
|
||||
* Removes tour items for elements that don't have matching page elements.
|
||||
*
|
||||
* Or that are explicitly filtered out via the 'tips' query string.
|
||||
*
|
||||
* @example
|
||||
* <caption>This will filter out tips that do not have a matching
|
||||
* page element or don't have the "bar" class.</caption>
|
||||
* http://example.com/foo?tips=bar
|
||||
*
|
||||
* @param {jQuery} $tour
|
||||
* A jQuery element pointing to a `<ol>` containing tour items.
|
||||
* @param {jQuery} $document
|
||||
* A jQuery element pointing to the document within which the elements
|
||||
* should be sought.
|
||||
*
|
||||
* @see Drupal.tour.views.ToggleTourView#_getDocument
|
||||
*/
|
||||
_removeIrrelevantTourItems($tour, $document) {
|
||||
let removals = false;
|
||||
const tips = /tips=([^&]+)/.exec(queryString);
|
||||
$tour.find('li').each(function() {
|
||||
const $this = $(this);
|
||||
const itemId = $this.attr('data-id');
|
||||
const itemClass = $this.attr('data-class');
|
||||
@@ -236,34 +238,41 @@
|
||||
return;
|
||||
}
|
||||
// Remove tip from the DOM if there is no corresponding page element.
|
||||
if ((!itemId && !itemClass) ||
|
||||
if (
|
||||
(!itemId && !itemClass) ||
|
||||
(itemId && $document.find(`#${itemId}`).length) ||
|
||||
(itemClass && $document.find(`.${itemClass}`).length)) {
|
||||
(itemClass && $document.find(`.${itemClass}`).length)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
removals = true;
|
||||
$this.remove();
|
||||
});
|
||||
|
||||
// If there were removals, we'll have to do some clean-up.
|
||||
if (removals) {
|
||||
const total = $tour.find('li').length;
|
||||
if (!total) {
|
||||
this.model.set({ tour: [] });
|
||||
// If there were removals, we'll have to do some clean-up.
|
||||
if (removals) {
|
||||
const total = $tour.find('li').length;
|
||||
if (!total) {
|
||||
this.model.set({ tour: [] });
|
||||
}
|
||||
|
||||
$tour
|
||||
.find('li')
|
||||
// Rebuild the progress data.
|
||||
.each(function(index) {
|
||||
const progress = Drupal.t('!tour_item of !total', {
|
||||
'!tour_item': index + 1,
|
||||
'!total': total,
|
||||
});
|
||||
$(this)
|
||||
.find('.tour-progress')
|
||||
.text(progress);
|
||||
})
|
||||
// Update the last item to have "End tour" as the button.
|
||||
.eq(-1)
|
||||
.attr('data-text', Drupal.t('End tour'));
|
||||
}
|
||||
|
||||
$tour
|
||||
.find('li')
|
||||
// Rebuild the progress data.
|
||||
.each(function (index) {
|
||||
const progress = Drupal.t('!tour_item of !total', { '!tour_item': index + 1, '!total': total });
|
||||
$(this).find('.tour-progress').text(progress);
|
||||
})
|
||||
// Update the last item to have "End tour" as the button.
|
||||
.eq(-1)
|
||||
.attr('data-text', Drupal.t('End tour'));
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
});
|
||||
}(jQuery, Backbone, Drupal, document));
|
||||
);
|
||||
})(jQuery, Backbone, Drupal, document);
|
||||
|
||||
@@ -122,7 +122,10 @@
|
||||
}
|
||||
|
||||
$tour.find('li').each(function (index) {
|
||||
var progress = Drupal.t('!tour_item of !total', { '!tour_item': index + 1, '!total': total });
|
||||
var progress = Drupal.t('!tour_item of !total', {
|
||||
'!tour_item': index + 1,
|
||||
'!total': total
|
||||
});
|
||||
$(this).find('.tour-progress').text(progress);
|
||||
}).eq(-1).attr('data-text', Drupal.t('End tour'));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,13 @@ use Drupal\tour\TourInterface;
|
||||
* @ConfigEntityType(
|
||||
* id = "tour",
|
||||
* label = @Translation("Tour"),
|
||||
* label_collection = @Translation("Tours"),
|
||||
* label_singular = @Translation("tour"),
|
||||
* label_plural = @Translation("tours"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count tour",
|
||||
* plural = "@count tours",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\tour\TourViewBuilder",
|
||||
* "access" = "Drupal\tour\TourAccessControlHandler",
|
||||
|
||||
@@ -39,6 +39,13 @@ class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInter
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/**
|
||||
* Unique aria-id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ariaId;
|
||||
|
||||
/**
|
||||
* Constructs a \Drupal\tour\Plugin\tour\tip\TipPluginText object.
|
||||
*
|
||||
@@ -70,11 +77,10 @@ class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInter
|
||||
* A unique id to be used to generate aria attributes.
|
||||
*/
|
||||
public function getAriaId() {
|
||||
static $id;
|
||||
if (!isset($id)) {
|
||||
$id = Html::getUniqueId($this->get('id'));
|
||||
if (!$this->ariaId) {
|
||||
$this->ariaId = Html::getUniqueId($this->get('id'));
|
||||
}
|
||||
return $id;
|
||||
return $this->ariaId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\tour\Tests;
|
||||
|
||||
/**
|
||||
* A legacy test for \Drupal\tour\Tests\TourTestBase.
|
||||
*
|
||||
* @group tour
|
||||
*/
|
||||
class TourTest extends TourTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'tour', 'locale', 'language', 'tour_test'];
|
||||
|
||||
/**
|
||||
* Tour tip attributes to be tested. Keyed by the path.
|
||||
*
|
||||
* @var array
|
||||
* An array of tip attributes, keyed by path.
|
||||
*/
|
||||
protected $tips = [
|
||||
'tour-test-1' => [
|
||||
'data-id' => 'tour-test-1',
|
||||
'data-class' => 'tour-test-1',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* An admin user with administrative permissions for tour.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* The permissions required for a logged in user to test tour tips.
|
||||
*
|
||||
* @var array
|
||||
* A list of permissions.
|
||||
*/
|
||||
protected $permissions = ['access tour'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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(['bartik', 'seven']);
|
||||
$this->config('system.theme')
|
||||
->set('default', 'bartik')
|
||||
->set('admin', 'seven')
|
||||
->save();
|
||||
|
||||
$this->permissions[] = 'view the administration theme';
|
||||
|
||||
// Create an admin user to view tour tips.
|
||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->drupalPlaceBlock('local_actions_block', [
|
||||
'theme' => 'seven',
|
||||
'region' => 'content'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple tip test.
|
||||
*/
|
||||
public function testTips() {
|
||||
foreach ($this->tips as $path => $attributes) {
|
||||
$this->drupalGet($path);
|
||||
$this->assertTourTips($attributes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\tour\Functional\Rest\TourResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class TourHalJsonAnonTest extends TourResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\tour\Functional\Rest\TourResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class TourHalJsonBasicAuthTest extends TourResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\tour\Functional\Rest\TourResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class TourHalJsonCookieTest extends TourResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class TourJsonAnonTest extends TourResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class TourJsonBasicAuthTest extends TourResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class TourJsonCookieTest extends TourResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
use Drupal\tour\Entity\Tour;
|
||||
|
||||
abstract class TourResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['tour'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'tour';
|
||||
|
||||
/**
|
||||
* @var \Drupal\tour\TourInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['access tour']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$tour = Tour::create([
|
||||
'id' => 'tour-llama',
|
||||
'label' => 'Llama tour',
|
||||
'langcode' => 'en',
|
||||
'module' => 'tour',
|
||||
'routes' => [
|
||||
[
|
||||
'route_name' => '<front>',
|
||||
],
|
||||
],
|
||||
'tips' => [
|
||||
'tour-llama-1' => [
|
||||
'id' => 'tour-llama-1',
|
||||
'plugin' => 'text',
|
||||
'label' => 'Llama',
|
||||
'body' => 'Who handle the awesomeness of llamas?',
|
||||
'weight' => 100,
|
||||
'attributes' => [
|
||||
'data-id' => 'tour-llama-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$tour->save();
|
||||
|
||||
return $tour;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'dependencies' => [],
|
||||
'id' => 'tour-llama',
|
||||
'label' => 'Llama tour',
|
||||
'langcode' => 'en',
|
||||
'module' => 'tour',
|
||||
'routes' => [
|
||||
[
|
||||
'route_name' => '<front>',
|
||||
],
|
||||
],
|
||||
'status' => TRUE,
|
||||
'tips' => [
|
||||
'tour-llama-1' => [
|
||||
'id' => 'tour-llama-1',
|
||||
'plugin' => 'text',
|
||||
'label' => 'Llama',
|
||||
'body' => 'Who handle the awesomeness of llamas?',
|
||||
'weight' => 100,
|
||||
'attributes' => [
|
||||
'data-id' => 'tour-llama-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
'uuid' => $this->entity->uuid(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return [
|
||||
'user.permissions',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
return "The following permissions are required: 'access tour' OR 'administer site configuration'.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class TourXmlAnonTest extends TourResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class TourXmlBasicAuthTest extends TourResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class TourXmlCookieTest extends TourResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class TourTest extends TourTestBasic {
|
||||
|
||||
$this->drupalPlaceBlock('local_actions_block', [
|
||||
'theme' => 'seven',
|
||||
'region' => 'content'
|
||||
'region' => 'content',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ class TourTest extends TourTestBasic {
|
||||
'url' => 'http://local/image.png',
|
||||
'weight' => 1,
|
||||
'attributes' => [
|
||||
'data-id' => 'tour-code-test-2'
|
||||
'data-id' => 'tour-code-test-2',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\tour\Unit\Plugin\tour\tip;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\tour\Plugin\tour\tip\TipPluginText;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\tour\Plugin\tour\tip\TipPluginText
|
||||
* @group tour
|
||||
*/
|
||||
class TipPluginTextTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that getAriaId returns unique id per plugin instance.
|
||||
*
|
||||
* @see \Drupal\tour\Plugin\tour\tip\TipPluginText::getAriaId()
|
||||
* @runTestsInSeparateProcesses
|
||||
* This test calls \Drupal\Component\Utility\Html::getUniqueId() which uses a
|
||||
* static list. Run this test in a separate process to prevent side effects.
|
||||
*/
|
||||
public function testGetAriaId() {
|
||||
$id_instance_one = 'one';
|
||||
$id_instance_two = 'two';
|
||||
$config_instance_one = [
|
||||
'id' => $id_instance_one,
|
||||
];
|
||||
$config_instance_two = [
|
||||
'id' => $id_instance_two,
|
||||
];
|
||||
$definition = [];
|
||||
$plugin_id = 'text';
|
||||
$token = $this->createMock('\Drupal\Core\Utility\Token');
|
||||
$instance_one = new TipPluginText($config_instance_one, $plugin_id, $definition, $token);
|
||||
$instance_two = new TipPluginText($config_instance_two, $plugin_id, $definition, $token);
|
||||
$instance_three = new TipPluginText($config_instance_one, $plugin_id, $definition, $token);
|
||||
|
||||
$this->assertEquals($id_instance_one, $instance_one->getAriaId());
|
||||
$this->assertEquals($id_instance_two, $instance_two->getAriaId());
|
||||
$this->assertNotEquals($instance_one->getAriaId(), $instance_two->getAriaId());
|
||||
$this->assertNotEquals($instance_one->getAriaId(), $instance_three->getAriaId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- tour
|
||||
- drupal:tour
|
||||
|
||||
@@ -28,4 +28,3 @@ tour_test.3:
|
||||
_controller: '\Drupal\tour_test\Controller\TourTestController::tourTest1'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user