Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
60
core/modules/help/src/Annotation/HelpSection.php
Normal file
60
core/modules/help/src/Annotation/HelpSection.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines a Plugin annotation object for help page section plugins.
|
||||
*
|
||||
* Plugin Namespace: Plugin\HelpSection
|
||||
*
|
||||
* For a working example, see \Drupal\help\Plugin\HelpSection\HookHelpSection.
|
||||
*
|
||||
* @see \Drupal\help\HelpSectionPluginInterface
|
||||
* @see \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase
|
||||
* @see \Drupal\help\HelpSectionManager
|
||||
* @see hook_help_section_info_alter()
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class HelpSection extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The text to use as the title of the help page section.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* The description of the help page section.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* The (optional) permission needed to view the help section.
|
||||
*
|
||||
* Only set if this section needs its own permission, beyond the generic
|
||||
* 'access administration pages' permission needed to see the /admin/help
|
||||
* page itself.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $permission = '';
|
||||
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Controller\HelpController.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Controller;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\help\HelpSectionManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
|
@ -25,14 +21,24 @@ class HelpController extends ControllerBase {
|
|||
*/
|
||||
protected $routeMatch;
|
||||
|
||||
/**
|
||||
* The help section plugin manager.
|
||||
*
|
||||
* @var \Drupal\help\HelpSectionManager
|
||||
*/
|
||||
protected $helpManager;
|
||||
|
||||
/**
|
||||
* Creates a new HelpController.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The current route match.
|
||||
* @param \Drupal\help\HelpSectionManager $help_manager
|
||||
* The help section manager.
|
||||
*/
|
||||
public function __construct(RouteMatchInterface $route_match) {
|
||||
public function __construct(RouteMatchInterface $route_match, HelpSectionManager $help_manager) {
|
||||
$this->routeMatch = $route_match;
|
||||
$this->helpManager = $help_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,62 +46,57 @@ class HelpController extends ControllerBase {
|
|||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('current_route_match')
|
||||
$container->get('current_route_match'),
|
||||
$container->get('plugin.manager.help_section')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a page listing a glossary of Drupal terminology.
|
||||
* Prints a page listing various types of help.
|
||||
*
|
||||
* @return string
|
||||
* An HTML string representing the contents of help page.
|
||||
* The page has sections defined by \Drupal\help\HelpSectionPluginInterface
|
||||
* plugins.
|
||||
*
|
||||
* @return array
|
||||
* A render array for the help page.
|
||||
*/
|
||||
public function helpMain() {
|
||||
$output = array(
|
||||
'#markup' => '<h2>' . $this->t('Help topics') . '</h2><p>' . $this->t('Help is available on the following items:') . '</p>',
|
||||
'links' => $this->helpLinksAsList(),
|
||||
);
|
||||
return $output;
|
||||
}
|
||||
$output = [];
|
||||
|
||||
/**
|
||||
* Provides a formatted list of available help topics.
|
||||
*
|
||||
* @return string
|
||||
* A string containing the formatted list.
|
||||
*/
|
||||
protected function helpLinksAsList() {
|
||||
$modules = array();
|
||||
foreach ($this->moduleHandler()->getImplementations('help') as $module) {
|
||||
$modules[$module] = $this->moduleHandler->getName($module);
|
||||
}
|
||||
asort($modules);
|
||||
// We are checking permissions, so add the user.permissions cache context.
|
||||
$cacheability = new CacheableMetadata();
|
||||
$cacheability->addCacheContexts(['user.permissions']);
|
||||
|
||||
// Output pretty four-column list.
|
||||
$count = count($modules);
|
||||
$break = ceil($count / 4);
|
||||
$column = array(
|
||||
'#type' => 'container',
|
||||
'links' => array('#theme' => 'item_list'),
|
||||
'#attributes' => array('class' => array('layout-column', 'layout-column--quarter')),
|
||||
);
|
||||
$output = array(
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
0 => $column,
|
||||
);
|
||||
$plugins = $this->helpManager->getDefinitions();
|
||||
$cacheability->addCacheableDependency($this->helpManager);
|
||||
|
||||
$i = 0;
|
||||
$current_column = 0;
|
||||
foreach ($modules as $module => $name) {
|
||||
$output[$current_column]['links']['#items'][] = $this->l($name, new Url('help.page', array('name' => $module)));
|
||||
if (($i + 1) % $break == 0 && ($i + 1) != $count) {
|
||||
$current_column++;
|
||||
$output[$current_column] = $column;
|
||||
foreach ($plugins as $plugin_id => $plugin_definition) {
|
||||
// Check the provided permission.
|
||||
if (!empty($plugin_definition['permission']) && !$this->currentuser()->hasPermission($plugin_definition['permission'])) {
|
||||
continue;
|
||||
}
|
||||
$i++;
|
||||
|
||||
// Add the section to the page.
|
||||
/** @var \Drupal\help\HelpSectionPluginInterface $plugin */
|
||||
$plugin = $this->helpManager->createInstance($plugin_id);
|
||||
$this_output = [
|
||||
'#theme' => 'help_section',
|
||||
'#title' => $plugin->getTitle(),
|
||||
'#description' => $plugin->getDescription(),
|
||||
'#empty' => $this->t('There is currently nothing in this section.'),
|
||||
'#links' => [],
|
||||
];
|
||||
|
||||
$links = $plugin->listTopics();
|
||||
if (is_array($links) && count($links)) {
|
||||
$this_output['#links'] = $links;
|
||||
}
|
||||
|
||||
$cacheability->addCacheableDependency($plugin);
|
||||
$output[$plugin_id] = $this_output;
|
||||
}
|
||||
|
||||
$cacheability->applyTo($output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
@ -116,12 +117,20 @@ class HelpController extends ControllerBase {
|
|||
$module_name = $this->moduleHandler()->getName($name);
|
||||
$build['#title'] = $module_name;
|
||||
|
||||
$info = system_get_info('module', $name);
|
||||
if ($info['package'] === 'Core (Experimental)') {
|
||||
drupal_set_message($this->t('This module is experimental. <a href=":url">Experimental modules</a> are provided for testing purposes only. Use at your own risk.', [':url' => 'https://www.drupal.org/core/experimental']), 'warning');
|
||||
}
|
||||
|
||||
$temp = $this->moduleHandler()->invoke($name, 'help', array("help.page.$name", $this->routeMatch));
|
||||
if (empty($temp)) {
|
||||
$build['top']['#markup'] = $this->t('No help is available for module %module.', array('%module' => $module_name));
|
||||
$build['top'] = ['#markup' => $this->t('No help is available for module %module.', array('%module' => $module_name))];
|
||||
}
|
||||
else {
|
||||
$build['top']['#markup'] = $temp;
|
||||
if (!is_array($temp)) {
|
||||
$temp = ['#markup' => $temp];
|
||||
}
|
||||
$build['top'] = $temp;
|
||||
}
|
||||
|
||||
// Only print list of administration pages if the module in question has
|
||||
|
|
37
core/modules/help/src/HelpSectionManager.php
Normal file
37
core/modules/help/src/HelpSectionManager.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
||||
/**
|
||||
* Manages help page section plugins.
|
||||
*
|
||||
* @see \Drupal\help\HelpSectionPluginInterface
|
||||
* @see \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase
|
||||
* @see \Drupal\help\Annotation\HelpSection
|
||||
* @see hook_help_section_info_alter()
|
||||
*/
|
||||
class HelpSectionManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* Constructs a new HelpSectionManager.
|
||||
*
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* Cache backend instance to use.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler for the alter hook.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/HelpSection', $namespaces, $module_handler, 'Drupal\help\HelpSectionPluginInterface', 'Drupal\help\Annotation\HelpSection');
|
||||
|
||||
$this->alterInfo('help_section_info');
|
||||
$this->setCacheBackend($cache_backend, 'help_section_plugins');
|
||||
}
|
||||
|
||||
}
|
49
core/modules/help/src/HelpSectionPluginInterface.php
Normal file
49
core/modules/help/src/HelpSectionPluginInterface.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help;
|
||||
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for a plugin for a section of the /admin/help page.
|
||||
*
|
||||
* Plugins of this type need to be annotated with
|
||||
* \Drupal\help\Annotation\HelpSection annotation, and placed in the
|
||||
* Plugin\HelpSection namespace directory. They are managed by the
|
||||
* \Drupal\help\HelpSectionManager plugin manager class. There is a base
|
||||
* class that may be helpful:
|
||||
* \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase.
|
||||
*/
|
||||
interface HelpSectionPluginInterface extends PluginInspectionInterface, CacheableDependencyInterface {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the title of the help section.
|
||||
*
|
||||
* @return string
|
||||
* The title text, which could be a plain string or an object that can be
|
||||
* cast to a string.
|
||||
*/
|
||||
public function getTitle();
|
||||
|
||||
/**
|
||||
* Returns the description text for the help section.
|
||||
*
|
||||
* @return string
|
||||
* The description text, which could be a plain string or an object that
|
||||
* can be cast to a string.
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
/**
|
||||
* Returns a list of topics to show in the help section.
|
||||
*
|
||||
* @return array
|
||||
* A sorted list of topic links or render arrays for topic links. The links
|
||||
* will be shown in the help section; if the returned array of links is
|
||||
* empty, the section will be shown with some generic empty text.
|
||||
*/
|
||||
public function listTopics();
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Plugin\Block\HelpBlock.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
@ -84,47 +79,32 @@ class HelpBlock extends BlockBase implements ContainerFactoryPluginInterface {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the help associated with the active menu item.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request.
|
||||
*
|
||||
* @return string
|
||||
* Help text of the matched route item as HTML.
|
||||
*/
|
||||
protected function getActiveHelp(Request $request) {
|
||||
// Do not show on a 403 or 404 page.
|
||||
if ($request->attributes->has('exception')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
|
||||
return $help ? implode("\n", $help) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
$help = $this->getActiveHelp($this->request);
|
||||
if (!$help) {
|
||||
// Do not show on a 403 or 404 page.
|
||||
if ($this->request->attributes->has('exception')) {
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
return [
|
||||
'#children' => $help,
|
||||
];
|
||||
|
||||
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
|
||||
$build = [];
|
||||
|
||||
// Remove any empty strings from $help.
|
||||
foreach (array_filter($help) as $item) {
|
||||
// Convert strings to #markup render arrays so that they will XSS admin
|
||||
// filtered.
|
||||
$build[] = is_array($item) ? $item : ['#markup' => $item];
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheContexts() {
|
||||
// The "Help" block must be cached per URL: help is defined for a
|
||||
// given path, and does not come with any access restrictions.
|
||||
return Cache::mergeContexts(parent::getCacheContexts(), ['url']);
|
||||
return Cache::mergeContexts(parent::getCacheContexts(), ['route']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help\Plugin\HelpSection;
|
||||
|
||||
use Drupal\Core\Cache\UnchangingCacheableDependencyTrait;
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\help\HelpSectionPluginInterface;
|
||||
|
||||
/**
|
||||
* Provides a base class for help section plugins.
|
||||
*
|
||||
* @see \Drupal\help\HelpSectionPluginInterface
|
||||
* @see \Drupal\help\Annotation\HelpSection
|
||||
* @see \Drupal\help\HelpSectionManager
|
||||
*/
|
||||
abstract class HelpSectionPluginBase extends PluginBase implements HelpSectionPluginInterface {
|
||||
|
||||
use UnchangingCacheableDependencyTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTitle() {
|
||||
return $this->getPluginDefinition()['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->getPluginDefinition()['description'];
|
||||
}
|
||||
|
||||
}
|
72
core/modules/help/src/Plugin/HelpSection/HookHelpSection.php
Normal file
72
core/modules/help/src/Plugin/HelpSection/HookHelpSection.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help\Plugin\HelpSection;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides the module topics list section for the help page.
|
||||
*
|
||||
* @HelpSection(
|
||||
* id = "hook_help",
|
||||
* title = @Translation("Module overviews"),
|
||||
* description = @Translation("Module overviews are provided by modules. Overviews available for your installed modules:"),
|
||||
* )
|
||||
*/
|
||||
class HookHelpSection extends HelpSectionPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* Constructs a HookHelpSection object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler service.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('module_handler')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listTopics() {
|
||||
$topics = [];
|
||||
foreach ($this->moduleHandler->getImplementations('help') as $module) {
|
||||
$title = $this->moduleHandler->getName($module);
|
||||
$topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]);
|
||||
}
|
||||
|
||||
// Sort topics by title, which is the array key above.
|
||||
ksort($topics);
|
||||
return $topics;
|
||||
}
|
||||
|
||||
}
|
56
core/modules/help/src/Tests/ExperimentalHelpTest.php
Normal file
56
core/modules/help/src/Tests/ExperimentalHelpTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Verifies help for experimental modules.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class ExperimentalHelpTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* The experimental_module_test module implements hook_help() and is in the
|
||||
* Core (Experimental) package.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('help', 'experimental_module_test', 'help_page_test');
|
||||
|
||||
/**
|
||||
* The admin user.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(['access administration pages']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a warning message is displayed for experimental modules.
|
||||
*/
|
||||
public function testExperimentalHelp() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('admin/help/experimental_module_test');
|
||||
$this->assertText('This module is experimental.');
|
||||
|
||||
// Regular modules should not display the message.
|
||||
$this->drupalGet('admin/help/help_page_test');
|
||||
$this->assertNoText('This module is experimental.');
|
||||
|
||||
// Ensure the actual help page is displayed to avoid a false positive.
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('online documentation for the Help Page Test module');
|
||||
}
|
||||
|
||||
}
|
44
core/modules/help/src/Tests/HelpBlockTest.php
Normal file
44
core/modules/help/src/Tests/HelpBlockTest.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests display of help block.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class HelpBlockTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['help', 'help_page_test', 'block'];
|
||||
|
||||
/**
|
||||
* The help block instance.
|
||||
*
|
||||
* @var \Drupal\block\Entity\Block
|
||||
*/
|
||||
protected $helpBlock;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->helpBlock = $this->placeBlock('help_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in users, tests help pages.
|
||||
*/
|
||||
public function testHelp() {
|
||||
$this->drupalGet('help_page_test/has_help');
|
||||
$this->assertText(t('I have help!'));
|
||||
$this->assertText($this->helpBlock->label());
|
||||
|
||||
$this->drupalGet('help_page_test/no_help');
|
||||
// The help block should not appear when there is no help.
|
||||
$this->assertNoText($this->helpBlock->label());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Tests\HelpEmptyPageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\help_test\SupernovaGenerator;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the empty HTML page.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class HelpEmptyPageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'help_test', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installSchema('system', 'router');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function containerBuild(ContainerBuilder $container) {
|
||||
parent::containerBuild($container);
|
||||
|
||||
$container->set('url_generator', new SupernovaGenerator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that no URL generator is called on a page without hook_help().
|
||||
*/
|
||||
public function testEmptyHookHelp() {
|
||||
$all_modules = system_rebuild_module_data();
|
||||
$all_modules = array_filter($all_modules, function ($module) {
|
||||
// Filter contrib, hidden, already enabled modules and modules in the
|
||||
// Testing package.
|
||||
if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
});
|
||||
|
||||
\Drupal::service('module_installer')->install(array_keys($all_modules));
|
||||
|
||||
$route = \Drupal::service('router.route_provider')->getRouteByName('<front>');
|
||||
\Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Tests\HelpTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
@ -20,11 +15,12 @@ class HelpTest extends WebTestBase {
|
|||
* Modules to enable.
|
||||
*
|
||||
* The help_test module implements hook_help() but does not provide a module
|
||||
* overview page.
|
||||
* overview page. The help_page_test module has a page section plugin that
|
||||
* returns no links.
|
||||
*
|
||||
* @var array.
|
||||
*/
|
||||
public static $modules = array('help_test');
|
||||
public static $modules = array('help_test', 'help_page_test');
|
||||
|
||||
/**
|
||||
* Use the Standard profile to test help implementations of many core modules.
|
||||
|
@ -52,7 +48,7 @@ class HelpTest extends WebTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Logs in users, creates dblog events, and tests dblog functionality.
|
||||
* Logs in users, tests help pages.
|
||||
*/
|
||||
public function testHelp() {
|
||||
// Login the root user to ensure as many admin links appear as possible on
|
||||
|
@ -67,10 +63,16 @@ class HelpTest extends WebTestBase {
|
|||
// Verify that introductory help text exists, goes for 100% module coverage.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('admin/help');
|
||||
$this->assertRaw(t('For more information, refer to the subjects listed in the Help Topics section or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', array(':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org')), 'Help intro text correctly appears.');
|
||||
$this->assertRaw(t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', array(':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org')));
|
||||
|
||||
// Verify that help topics text appears.
|
||||
$this->assertRaw('<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>', 'Help topics text correctly appears.');
|
||||
// Verify that hook_help() section title and description appear.
|
||||
$this->assertRaw('<h2>' . t('Module overviews') . '</h2>');
|
||||
$this->assertRaw('<p>' . t('Module overviews are provided by modules. Overviews available for your installed modules:'), '</p>');
|
||||
|
||||
// Verify that an empty section is handled correctly.
|
||||
$this->assertRaw('<h2>' . t('Empty section') . '</h2>');
|
||||
$this->assertRaw('<p>' . t('This description should appear.'), '</p>');
|
||||
$this->assertText(t('There is currently nothing in this section.'));
|
||||
|
||||
// Make sure links are properly added for modules implementing hook_help().
|
||||
foreach ($this->getModuleList() as $module => $name) {
|
||||
|
@ -81,10 +83,25 @@ class HelpTest extends WebTestBase {
|
|||
// handled correctly.
|
||||
$this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
|
||||
$this->assertRaw(t('No help is available for module %module.', array('%module' => \Drupal::moduleHandler()->getName('help_test'))));
|
||||
|
||||
// Verify that the order of topics is alphabetical by displayed module
|
||||
// name, by checking the order of some modules, including some that would
|
||||
// have a different order if it was done by machine name instead.
|
||||
$this->drupalGet('admin/help');
|
||||
$page_text = $this->getTextContent();
|
||||
$start = strpos($page_text, 'Module overviews');
|
||||
$pos = $start;
|
||||
$list = ['Block', 'Color', 'Custom Block', 'History', 'Text Editor'];
|
||||
foreach ($list as $name) {
|
||||
$this->assertLink($name);
|
||||
$new_pos = strpos($page_text, $name, $start);
|
||||
$this->assertTrue($new_pos > $pos, 'Order of ' . $name . ' is correct on page');
|
||||
$pos = $new_pos;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the logged in user has access to the various help nodes.
|
||||
* Verifies the logged in user has access to the various help pages.
|
||||
*
|
||||
* @param int $response
|
||||
* (optional) An HTTP response code. Defaults to 200.
|
||||
|
@ -100,7 +117,7 @@ class HelpTest extends WebTestBase {
|
|||
}
|
||||
|
||||
foreach ($this->getModuleList() as $module => $name) {
|
||||
// View module help node.
|
||||
// View module help page.
|
||||
$this->drupalGet('admin/help/' . $module);
|
||||
$this->assertResponse($response);
|
||||
if ($response == 200) {
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Tests\NoHelpTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
@ -43,7 +38,7 @@ class NoHelpTest extends WebTestBase {
|
|||
|
||||
$this->drupalGet('admin/help');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Help is available on the following items', 'Help page is found.');
|
||||
$this->assertText('Module overviews are provided by modules');
|
||||
$this->assertFalse(\Drupal::moduleHandler()->implementsHook('menu_test', 'help'), 'The menu_test module does not implement hook_help');
|
||||
$this->assertNoText(\Drupal::moduleHandler()->getName('menu_test'), 'Making sure the test module menu_test does not display a help link on admin/help.');
|
||||
|
||||
|
|
Reference in a new issue