Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,7 @@
|
|||
name: 'Help Page Test'
|
||||
type: module
|
||||
description: 'Module to test the help page.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
hidden: true
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Help Page Test module to test the help page.
|
||||
*/
|
||||
|
||||
use \Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function help_page_test_help($route_name, RouteMatchInterface $route_match) {
|
||||
|
||||
switch ($route_name) {
|
||||
case 'help.page.help_page_test':
|
||||
// Make the help text conform to core standards. See
|
||||
// \Drupal\system\Tests\Module\InstallUninstallTest::assertHelp().
|
||||
return t('Read the <a href=":url">online documentation for the Help Page Test module</a>.', [':url' => 'http://www.example.com']);
|
||||
case 'help_page_test.has_help':
|
||||
return t('I have help!');
|
||||
case 'help_page_test.test_array':
|
||||
return ['#markup' => 'Help text from help_page_test_help module.'];
|
||||
}
|
||||
|
||||
// Ensure that hook_help() can return an empty string and not cause the block
|
||||
// to display.
|
||||
return '';
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
help_page_test.has_help:
|
||||
path: '/help_page_test/has_help'
|
||||
defaults:
|
||||
_controller: '\Drupal\help_page_test\HelpPageTestController::hasHelp'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
help_page_test.no_help:
|
||||
path: '/help_page_test/no_help'
|
||||
defaults:
|
||||
_controller: '\Drupal\help_page_test\HelpPageTestController::noHelp'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
help_page_test.test_array:
|
||||
path: '/help_page_test/test_array'
|
||||
defaults:
|
||||
_controller: '\Drupal\help_page_test\HelpPageTestController::testArray'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help_page_test;
|
||||
|
||||
/**
|
||||
* Provides controllers for testing the help block.
|
||||
*/
|
||||
class HelpPageTestController {
|
||||
|
||||
/**
|
||||
* Provides a route with help.
|
||||
*
|
||||
* @return array
|
||||
* A render array.
|
||||
*/
|
||||
public function hasHelp() {
|
||||
return ['#markup' => 'A route with help.'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a route with no help.
|
||||
*
|
||||
* @return array
|
||||
* A render array.
|
||||
*/
|
||||
public function noHelp() {
|
||||
return ['#markup' => 'A route without help.'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a route which has multiple array returns from hook_help().
|
||||
*
|
||||
* @return array
|
||||
* A render array.
|
||||
*/
|
||||
public function testArray() {
|
||||
return ['#markup' => 'A route which has multiple array returns from hook_help().'];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help_page_test\Plugin\HelpSection;
|
||||
|
||||
use Drupal\help\Plugin\HelpSection\HelpSectionPluginBase;
|
||||
|
||||
/**
|
||||
* Provides an empty section for the help page, for testing.
|
||||
*
|
||||
* @HelpSection(
|
||||
* id = "empty_section",
|
||||
* title = @Translation("Empty section"),
|
||||
* description = @Translation("This description should appear."),
|
||||
* )
|
||||
*/
|
||||
class EmptyHelpSection extends HelpSectionPluginBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listTopics() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
name: help_test
|
||||
type: module
|
||||
core: 8.x
|
||||
package: Testing
|
||||
dependencies:
|
||||
- help
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test Help module.
|
||||
*/
|
||||
|
||||
use \Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function help_test_help($route_name, RouteMatchInterface $route_match) {
|
||||
// Do not implement a module overview page to test an empty implementation.
|
||||
// @see \Drupal\help\Tests\HelpTest
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\help_test;
|
||||
|
||||
use Drupal\Core\Routing\UrlGeneratorInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
/**
|
||||
* Implements a URL generator which always thrown an exception.
|
||||
*/
|
||||
class SupernovaGenerator implements UrlGeneratorInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContext(RequestContext $context) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext() {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPathFromRoute($name, $parameters = array()) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($name) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteDebugMessage($name, array $parameters = array()) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
name: 'More Help Page Test'
|
||||
type: module
|
||||
description: 'Module to test the help page.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
hidden: true
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* More Help Page Test module to test the help blocks.
|
||||
*/
|
||||
|
||||
use \Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function more_help_page_test_help($route_name, RouteMatchInterface $route_match) {
|
||||
|
||||
switch ($route_name) {
|
||||
// Return help for the same route as the help_page_test module.
|
||||
case 'help_page_test.test_array':
|
||||
return ['#markup' => 'Help text from more_help_page_test_help module.'];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\help\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Verifies help for experimental modules.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class ExperimentalHelpTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
|
||||
}
|
50
web/core/modules/help/tests/src/Functional/HelpBlockTest.php
Normal file
50
web/core/modules/help/tests/src/Functional/HelpBlockTest.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\help\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests display of help block.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class HelpBlockTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['help', 'help_page_test', 'block', 'more_help_page_test'];
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
||||
// Ensure that if two hook_help() implementations both return a render array
|
||||
// the output is as expected.
|
||||
$this->drupalGet('help_page_test/test_array');
|
||||
$this->assertText('Help text from more_help_page_test_help module.');
|
||||
$this->assertText('Help text from help_page_test_help module.');
|
||||
}
|
||||
|
||||
}
|
160
web/core/modules/help/tests/src/Functional/HelpTest.php
Normal file
160
web/core/modules/help/tests/src/Functional/HelpTest.php
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\help\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Verify help display and user access to help based on permissions.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class HelpTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* The help_test module implements hook_help() but does not provide a module
|
||||
* overview page. The help_page_test module has a page section plugin that
|
||||
* returns no links.
|
||||
*
|
||||
* @var array.
|
||||
*/
|
||||
public static $modules = array('help_test', 'help_page_test');
|
||||
|
||||
/**
|
||||
* Use the Standard profile to test help implementations of many core modules.
|
||||
*/
|
||||
protected $profile = 'standard';
|
||||
|
||||
/**
|
||||
* The admin user that will be created.
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* The anonymous user that will be created.
|
||||
*/
|
||||
protected $anyUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create users.
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer permissions'));
|
||||
$this->anyUser = $this->drupalCreateUser(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in users, tests help pages.
|
||||
*/
|
||||
public function testHelp() {
|
||||
// Log in the root user to ensure as many admin links appear as possible on
|
||||
// the module overview pages.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->verifyHelp();
|
||||
|
||||
// Log in the regular user.
|
||||
$this->drupalLogin($this->anyUser);
|
||||
$this->verifyHelp(403);
|
||||
|
||||
// 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 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 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) {
|
||||
$this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', array('@module' => $module, '@name' => $name)));
|
||||
}
|
||||
|
||||
// Ensure that module which does not provide an module overview page is
|
||||
// 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 pages.
|
||||
*
|
||||
* @param int $response
|
||||
* (optional) An HTTP response code. Defaults to 200.
|
||||
*/
|
||||
protected function verifyHelp($response = 200) {
|
||||
$this->drupalGet('admin/index');
|
||||
$this->assertResponse($response);
|
||||
if ($response == 200) {
|
||||
$this->assertText('This page shows you all available administration tasks for each module.');
|
||||
}
|
||||
else {
|
||||
$this->assertNoText('This page shows you all available administration tasks for each module.');
|
||||
}
|
||||
|
||||
foreach ($this->getModuleList() as $module => $name) {
|
||||
// View module help page.
|
||||
$this->drupalGet('admin/help/' . $module);
|
||||
$this->assertResponse($response);
|
||||
if ($response == 200) {
|
||||
$this->assertTitle($name . ' | Drupal', format_string('%module title was displayed', array('%module' => $module)));
|
||||
$this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed");
|
||||
$admin_tasks = system_get_module_admin_tasks($module, system_get_info('module', $module));
|
||||
if (!empty($admin_tasks)) {
|
||||
$this->assertText(t('@module administration pages', array('@module' => $name)));
|
||||
}
|
||||
foreach ($admin_tasks as $task) {
|
||||
$this->assertLink($task['title']);
|
||||
// Ensure there are no double escaped '&' or '<' characters.
|
||||
$this->assertNoEscaped('&', 'The help text does not have double escaped &.');
|
||||
$this->assertNoEscaped('<', 'The help text does not have double escaped <.');
|
||||
// Ensure there are no escaped '<' characters.
|
||||
$this->assertNoEscaped('<', 'The help text does not have single escaped <.');
|
||||
}
|
||||
// Ensure there are no double escaped '&' or '<' characters.
|
||||
$this->assertNoEscaped('&');
|
||||
$this->assertNoEscaped('<');
|
||||
// Ensure there are no escaped '<' characters.
|
||||
$this->assertNoEscaped('<');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of enabled modules that implement hook_help().
|
||||
*
|
||||
* @return array
|
||||
* A list of enabled modules.
|
||||
*/
|
||||
protected function getModuleList() {
|
||||
$modules = array();
|
||||
$module_data = system_rebuild_module_data();
|
||||
foreach (\Drupal::moduleHandler()->getImplementations('help') as $module) {
|
||||
$modules[$module] = $module_data[$module]->info['name'];
|
||||
}
|
||||
return $modules;
|
||||
}
|
||||
|
||||
}
|
49
web/core/modules/help/tests/src/Functional/NoHelpTest.php
Normal file
49
web/core/modules/help/tests/src/Functional/NoHelpTest.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\help\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Verify no help is displayed for modules not providing any help.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class NoHelpTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* Use one of the test modules that do not implement hook_help().
|
||||
*
|
||||
* @var array.
|
||||
*/
|
||||
public static $modules = array('help', 'menu_test');
|
||||
|
||||
/**
|
||||
* The user who will be created.
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures modules not implementing help do not appear on admin/help.
|
||||
*/
|
||||
public function testMainPageNoHelp() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->drupalGet('admin/help');
|
||||
$this->assertResponse(200);
|
||||
$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.');
|
||||
|
||||
$this->drupalGet('admin/help/menu_test');
|
||||
$this->assertResponse(404, 'Getting a module overview help page for a module that does not implement hook_help() results in a 404.');
|
||||
}
|
||||
|
||||
}
|
52
web/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php
Normal file
52
web/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\help\Kernel;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\help_test\SupernovaGenerator;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the empty HTML page.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class HelpEmptyPageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'help_test', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($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;
|
||||
});
|
||||
|
||||
$this->enableModules(array_keys($all_modules));
|
||||
$this->installEntitySchema('menu_link_content');
|
||||
|
||||
$route = \Drupal::service('router.route_provider')->getRouteByName('<front>');
|
||||
\Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue