Move all files to 2017/

This commit is contained in:
Oliver Davies 2025-09-29 22:25:17 +01:00
parent ac7370f67f
commit 2875863330
15717 changed files with 0 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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'.";
}
}

View file

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

View file

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

View file

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

View file

@ -0,0 +1,78 @@
<?php
namespace Drupal\Tests\tour\Functional;
use Drupal\Core\Url;
use Drupal\Tests\system\Functional\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 = ['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',
'http_response',
'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',
'http_response',
'rendered',
];
$this->verifyPageCache($url, 'HIT', $expected_tags);
}
}

View file

@ -0,0 +1,141 @@
<?php
namespace Drupal\Tests\tour\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Verifies help page display of tours.
*
* @group help
*/
class TourHelpPageTest extends BrowserTestBase {
/**
* Modules to enable, including some providing tours.
*
* @var array
*/
public static $modules = ['help', 'tour', 'locale', 'language'];
/**
* User that can access tours and help.
*
* @var \Drupal\user\UserInterface
*/
protected $tourUser;
/**
* A user who can access help but not tours.
*
* @var \Drupal\user\UserInterface
*/
protected $noTourUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create users. For the Tour user, include permissions for the language
// tours' parent pages, but not the translation tour's parent page. See
// self:getTourList().
$this->tourUser = $this->drupalCreateUser(['access administration pages', 'access tour', 'administer languages']);
$this->noTourUser = $this->drupalCreateUser(['access administration pages']);
}
/**
* Logs in users, tests help pages.
*/
public function testHelp() {
$this->drupalLogin($this->tourUser);
$this->verifyHelp();
$this->drupalLogin($this->noTourUser);
$this->verifyHelp(FALSE);
}
/**
* Verifies the logged in user has access to the help properly.
*
* @param bool $tours_ok
* (optional) TRUE (default) if the user should see tours, FALSE if not.
*/
protected function verifyHelp($tours_ok = TRUE) {
$this->drupalGet('admin/help');
// All users should be able to see the module section.
$this->assertText('Module overviews are provided by modules');
foreach ($this->getModuleList() as $name) {
$this->assertLink($name);
}
// Some users should be able to see the tour section.
if ($tours_ok) {
$this->assertText('Tours guide you through workflows');
}
else {
$this->assertNoText('Tours guide you through workflows');
}
$titles = $this->getTourList();
// Test the titles that should be links.
foreach ($titles[0] as $title) {
if ($tours_ok) {
$this->assertLink($title);
}
else {
$this->assertNoLink($title);
// Just test the first item in the list of links that should not
// be there, because the second matches the name of a module that is
// in the Module overviews section, so the link will be there and
// this test will fail. Testing one should be sufficient to verify
// the page is working correctly.
break;
}
}
// Test the titles that should not be links.
foreach ($titles[1] as $title) {
if ($tours_ok) {
$this->assertText($title);
$this->assertSession()->linkNotExistsExact($title);
}
else {
$this->assertNoText($title);
// Just test the first item in the list of text that should not
// be there, because the second matches part of the name of a module
// that is in the Module overviews section, so the text will be there
// and this test will fail. Testing one should be sufficient to verify
// the page is working correctly.
break;
}
}
}
/**
* Gets a list of modules to test for hook_help() pages.
*
* @return array
* A list of module names to test.
*/
protected function getModuleList() {
return ['Help', 'Tour'];
}
/**
* Gets a list of tours to test.
*
* @return array
* A list of tour titles to test. The first array element is a list of tours
* with links, and the second is a list of tours without links. Assumes
* that the user being tested has 'administer languages' permission but
* not 'translate interface'.
*/
protected function getTourList() {
return [['Adding languages', 'Language'], ['Editing languages', 'Translation']];
}
}

View file

@ -0,0 +1,188 @@
<?php
namespace Drupal\Tests\tour\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\tour\Entity\Tour;
/**
* Tests the functionality of tour tips.
*
* @group tour
*/
class TourTest extends TourTestBasic {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['block', 'tour', 'locale', 'language', 'tour_test'];
/**
* The permissions required for a logged in user to test tour tips.
*
* @var array
* A list of permissions.
*/
protected $permissions = ['access tour', 'administer languages'];
/**
* 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' => [],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('local_actions_block', [
'theme' => 'seven',
'region' => 'content',
]);
}
/**
* Test tour functionality.
*/
public function testTourFunctionality() {
// Navigate to tour-test-1 and verify the tour_test_1 tip is found with appropriate classes.
$this->drupalGet('tour-test-1');
// Test the TourTestBase class assertTourTips() method.
$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)]]', [
':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')");
$this->assertEqual(count($elements), 1, 'Found English variant of tip 1.');
$elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
$this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 2.');
$elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')");
$this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.');
// Ensure that plugins work.
$elements = $this->xpath('//img[@src="http://local/image.png"]');
$this->assertEqual(count($elements), 1, 'Image plugin tip found.');
// Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found.
$this->drupalGet('tour-test-2/subpath');
$elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
$this->assertEqual(count($elements), 1, 'Found English variant of tip 2.');
$elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')");
$this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.');
// Enable Italian language and navigate to it/tour-test1 and verify italian
// version of tip is found.
ConfigurableLanguage::createFromLangcode('it')->save();
$this->drupalGet('it/tour-test-1');
$elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')");
$this->assertEqual(count($elements), 1, 'Found Italian variant of tip 1.');
$elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
$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([
'id' => 'tour-entity-create-test-en',
'label' => 'Tour test english',
'langcode' => 'en',
'module' => 'system',
'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' => [
'data-id' => 'tour-code-test-1',
],
],
'tour-code-test-2' => [
'id' => 'tour-code-test-2',
'plugin' => 'image',
'label' => 'The awesome image',
'url' => 'http://local/image.png',
'weight' => 1,
'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'], ['system', 'tour_test']);
$this->drupalGet('tour-test-1');
// Load it back from the database and verify storage worked.
$entity_save_tip = Tour::load('tour-entity-create-test-en');
// Verify that hook_ENTITY_TYPE_load() integration worked.
$this->assertEqual($entity_save_tip->loaded, 'Load hooks work');
// Verify that hook_ENTITY_TYPE_presave() integration worked.
$this->assertEqual($entity_save_tip->label(), 'Tour test english alter');
// Navigate to tour-test-1 and verify the new tip is found.
$this->drupalGet('tour-test-1');
$elements = $this->cssSelect("li[data-id=tour-code-test-1] h2:contains('The rain in spain')");
$this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4');
// Verify that the weight sorting works by ensuring the lower weight item
// (tip 4) has the 'End tour' button.
$elements = $this->cssSelect("li[data-id=tour-code-test-1][data-text='End tour']");
$this->assertEqual(count($elements), 1, 'Found code tip was weighted last and had "End tour".');
// Test hook_tour_alter().
$this->assertText('Altered by hook_tour_tips_alter');
// 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)]]', [
':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)]]', [
':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

@ -0,0 +1,72 @@
<?php
namespace Drupal\Tests\tour\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Base class for testing Tour functionality.
*/
abstract class TourTestBase extends BrowserTestBase {
/**
* Assert function to determine if tips rendered to the page
* have a corresponding page element.
*
* @param array $tips
* A list of tips which provide either a "data-id" or "data-class".
*
* @code
* // Basic example.
* $this->assertTourTips();
*
* // Advanced example. The following would be used for multipage or
* // targeting a specific subset of tips.
* $tips = array();
* $tips[] = array('data-id' => 'foo');
* $tips[] = array('data-id' => 'bar');
* $tips[] = array('data-class' => 'baz');
* $this->assertTourTips($tips);
* @endcode
*/
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">.
$rendered_tips = $this->xpath('//ol[@id = "tour"]//li[starts-with(@class, "tip")]');
foreach ($rendered_tips as $rendered_tip) {
$tips[] = [
'data-id' => $rendered_tip->getAttribute('data-id'),
'data-class' => $rendered_tip->getAttribute('data-class'),
];
}
}
// If the tips are still empty we need to fail.
if (empty($tips)) {
$this->fail('Could not find tour tips on the current page.');
}
else {
// Check for corresponding page elements.
$total = 0;
$modals = 0;
foreach ($tips as $tip) {
if (!empty($tip['data-id'])) {
$elements = $this->getSession()->getPage()->findAll('css', '#' . $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 = $this->getSession()->getPage()->findAll('css', '.' . $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.
$modals++;
}
$total++;
}
$this->pass(format_string('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals]));
}
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Drupal\Tests\tour\Functional;
/**
* Simple tour tips test base.
*/
abstract class TourTestBasic extends TourTestBase {
/**
* Tour tip attributes to be tested. Keyed by the path.
*
* @var array
* An array of tip attributes, keyed by path.
*
* @code
* protected $tips = array(
* '/foo/bar' => array(
* array('data-id' => 'foo'),
* array('data-class' => 'bar'),
* ),
* );
* @endcode
*/
protected $tips = [];
/**
* 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'];
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);
}
/**
* A simple tip test.
*/
public function testTips() {
foreach ($this->tips as $path => $attributes) {
$this->drupalGet($path);
$this->assertTourTips($attributes);
}
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace Drupal\Tests\tour\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the functionality of tour plugins.
*
* @group tour
*/
class TourPluginTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['tour'];
/**
* Stores the tour plugin manager.
*
* @var \Drupal\tour\TipPluginManager
*/
protected $pluginManager;
protected function setUp() {
parent::setUp();
$this->installConfig(['tour']);
$this->pluginManager = $this->container->get('plugin.manager.tour.tip');
}
/**
* Test tour plugins.
*/
public function testTourPlugins() {
$this->assertIdentical(count($this->pluginManager->getDefinitions()), 1, 'Only tour plugins for the enabled modules were returned.');
}
}

View file

@ -0,0 +1,138 @@
<?php
namespace Drupal\Tests\tour\Unit\Entity;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\tour\Entity\Tour
* @group tour
*/
class TourTest extends UnitTestCase {
/**
* Tests \Drupal\tour\Entity\Tour::hasMatchingRoute().
*
* @param array $routes
* Array of routes as per the Tour::routes property.
* @param string $route_name
* The route name to match.
* @param array $route_params
* Array of route params.
* @param bool $result
* Expected result.
*
* @covers ::hasMatchingRoute
*
* @dataProvider routeProvider
*/
public function testHasMatchingRoute($routes, $route_name, $route_params, $result) {
$tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour')
->disableOriginalConstructor()
->setMethods(['getRoutes'])
->getMock();
$tour->expects($this->any())
->method('getRoutes')
->will($this->returnValue($routes));
$this->assertSame($result, $tour->hasMatchingRoute($route_name, $route_params));
$tour->resetKeyedRoutes();
}
/**
* Provides sample routes for testing.
*/
public function routeProvider() {
return [
// Simple match.
[
[
['route_name' => 'some.route'],
],
'some.route',
[],
TRUE,
],
// Simple non-match.
[
[
['route_name' => 'another.route'],
],
'some.route',
[],
FALSE,
],
// Empty params.
[
[
[
'route_name' => 'some.route',
'route_params' => ['foo' => 'bar'],
],
],
'some.route',
[],
FALSE,
],
// Match on params.
[
[
[
'route_name' => 'some.route',
'route_params' => ['foo' => 'bar'],
],
],
'some.route',
['foo' => 'bar'],
TRUE,
],
// Non-matching params.
[
[
[
'route_name' => 'some.route',
'route_params' => ['foo' => 'bar'],
],
],
'some.route',
['bar' => 'foo'],
FALSE,
],
// One matching, one not.
[
[
[
'route_name' => 'some.route',
'route_params' => ['foo' => 'bar'],
],
[
'route_name' => 'some.route',
'route_params' => ['bar' => 'foo'],
],
],
'some.route',
['bar' => 'foo'],
TRUE,
],
// One matching, one not.
[
[
[
'route_name' => 'some.route',
'route_params' => ['foo' => 'bar'],
],
[
'route_name' => 'some.route',
'route_params' => ['foo' => 'baz'],
],
],
'some.route',
['foo' => 'baz'],
TRUE,
],
];
}
}

View file

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

View file

@ -0,0 +1,5 @@
label: Tour test italian
tips:
tour-test-1:
label: La pioggia cade in spagna
body: Per lo più in pianura.

View file

@ -0,0 +1,15 @@
id: tour-test-2
module: tour_test
label: 'Tour test english'
langcode: en
routes:
- route_name: tour_test.2
tips:
tour-test-2:
id: tour-test-2
plugin: text
label: 'The quick brown fox'
body: 'Per lo più in pianura.'
weight: 2
attributes:
data-id: tour-test-2

View file

@ -0,0 +1,40 @@
id: tour-test
module: tour_test
label: 'Tour test english'
langcode: en
routes:
- route_name: tour_test.1
- route_name: tour_test.3
route_params:
locale: foo
tips:
tour-test-1:
id: tour-test-1
plugin: text
label: 'The first tip'
body: 'Is <a href="[site:url]">[site:name]</a> always the best dressed?'
weight: 1
attributes:
data-id: tour-test-1
tour-test-action:
id: tour-test-3
plugin: text
label: 'The action'
body: 'The action button of awesome'
weight: 2
attributes:
data-class: button-action
tour-test-3:
id: tour-test-3
plugin: image
label: 'The awesome image'
url: 'http://local/image.png'
weight: 1
tour-test-6:
id: tour-test-6
plugin: text
label: 'Im a list'
body: '<p>Im all these things:</p><ul><li>Modal</li><li>Awesome</li></ul>'
weight: 6
attributes:
data-id: tour-test-3

View file

@ -0,0 +1,9 @@
# Schema for the configuration files of the Tour Test module.
tour.tip.image:
type: tour.tip
label: 'Image tour tip'
mapping:
url:
type: uri
label: 'Image URL'

View file

@ -0,0 +1,74 @@
<?php
namespace Drupal\tour_test\Controller;
/**
* Controller routines for tour_test routes.
*/
class TourTestController {
/**
* Outputs some content for testing tours.
*
* @param string $locale
* (optional) Dummy locale variable for testing routing parameters. Defaults
* to 'foo'.
*
* @return array
* Array of markup.
*/
public function tourTest1($locale = 'foo') {
return [
'tip-1' => [
'#type' => 'container',
'#attributes' => [
'id' => 'tour-test-1',
],
'#children' => t('Where does the rain in Spain fail?'),
],
'tip-3' => [
'#type' => 'container',
'#attributes' => [
'id' => 'tour-test-3',
],
'#children' => t('Tip created now?'),
],
'tip-4' => [
'#type' => 'container',
'#attributes' => [
'id' => 'tour-test-4',
],
'#children' => t('Tip created later?'),
],
'tip-5' => [
'#type' => 'container',
'#attributes' => [
'class' => ['tour-test-5'],
],
'#children' => t('Tip created later?'),
],
'code-tip-1' => [
'#type' => 'container',
'#attributes' => [
'id' => 'tour-code-test-1',
],
'#children' => t('Tip created now?'),
],
];
}
/**
* Outputs some content for testing tours.
*/
public function tourTest2() {
return [
'#type' => 'container',
'#attributes' => [
'id' => 'tour-test-2',
],
'#children' => t('Pangram example'),
];
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\tour_test\Plugin\tour\tip;
use Drupal\Component\Utility\Html;
use Drupal\tour\TipPluginBase;
/**
* Displays an image as a tip.
*
* @Tip(
* id = "image",
* title = @Translation("Image")
* )
*/
class TipPluginImage extends TipPluginBase {
/**
* The url which is used for the image in this Tip.
*
* @var string
* A url used for the image.
*/
protected $url;
/**
* The alt text which is used for the image in this Tip.
*
* @var string
* A alt text used for the image.
*/
protected $alt;
/**
* {@inheritdoc}
*/
public function getOutput() {
$prefix = '<h2 class="tour-tip-label" id="tour-tip-' . $this->get('ariaId') . '-label">' . Html::escape($this->get('label')) . '</h2>';
$prefix .= '<p class="tour-tip-image" id="tour-tip-' . $this->get('ariaId') . '-contents">';
return [
'#prefix' => $prefix,
'#theme' => 'image',
'#uri' => $this->get('url'),
'#alt' => $this->get('alt'),
'#suffix' => '</p>',
];
}
}

View file

@ -0,0 +1,8 @@
name: Tour module tests
type: module
description: Tests module for tour module.
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:tour

View file

@ -0,0 +1,5 @@
tour_test_action:
route_name: tour_test.1_action
title: 'Tour test action'
appears_on:
- tour_test.1

View file

@ -0,0 +1,37 @@
<?php
/**
* @file
* Provides tests for tour module
*/
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_ENTITY_TYPE_load() for tour.
*/
function tour_test_tour_load($entities) {
if (isset($entities['tour-entity-create-test-en'])) {
$entities['tour-entity-create-test-en']->loaded = 'Load hooks work';
}
}
/**
* Implements hook_ENTITY_TYPE_presave() for tour.
*/
function tour_test_tour_presave($entity) {
if ($entity->id() == 'tour-entity-create-test-en') {
$entity->set('label', $entity->label() . ' alter');
}
}
/**
* Implements hook_tour_tips_alter().
*/
function tour_test_tour_tips_alter(array &$tour_tips, EntityInterface $entity) {
foreach ($tour_tips as $tour_tip) {
if ($tour_tip->get('id') == 'tour-code-test-1') {
$tour_tip->set('body', 'Altered by hook_tour_tips_alter');
}
}
}

View file

@ -0,0 +1,30 @@
tour_test.1:
path: '/tour-test-1'
defaults:
_controller: '\Drupal\tour_test\Controller\TourTestController::tourTest1'
options:
_admin_route: TRUE
requirements:
_access: 'TRUE'
tour_test.1_action:
path: '/tour-test-1/action'
defaults:
_controller: '\Drupal\tour_test\Controller\TourTestController::tourTest1'
requirements:
_access: 'TRUE'
tour_test.2:
path: '/tour-test-2/subpath'
defaults:
_controller: '\Drupal\tour_test\Controller\TourTestController::tourTest2'
requirements:
_access: 'TRUE'
tour_test.3:
path: '/tour-test-3/{locale}'
defaults:
locale: 'foo'
_controller: '\Drupal\tour_test\Controller\TourTestController::tourTest1'
requirements:
_access: 'TRUE'