Same filename and directory in other branches
- 8.9.x core/modules/help/tests/src/Functional/HelpTest.php
- 9 core/modules/help/tests/src/Functional/HelpTest.php
Namespace
Drupal\Tests\help\Functional
File
core/modules/help/tests/src/Functional/HelpTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\help\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
class HelpTest extends BrowserTestBase {
protected static $modules = [
'block_content',
'breakpoint',
'editor',
'help',
'help_page_test',
'help_test',
'history',
];
protected $defaultTheme = 'claro';
protected $adminUser;
protected $anyUser;
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access help pages',
'view the administration theme',
'administer permissions',
]);
$this->anyUser = $this
->drupalCreateUser([]);
}
public function testHelp() {
$this
->drupalLogin($this
->drupalCreateUser([
'access help pages',
'access administration pages',
]));
$this
->verifyHelp();
$this
->drupalLogin($this->anyUser);
$this
->verifyHelp(403);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/help');
$this
->assertSession()
->responseContains('For more information, refer to the help listed on this page or to the <a href="https://www.drupal.org/documentation">online documentation</a> and <a href="https://www.drupal.org/support">support</a> pages at <a href="https://www.drupal.org">drupal.org</a>.');
$this
->assertSession()
->responseContains('<h2>Module overviews</h2>');
$this
->assertSession()
->responseContains('<p>Module overviews are provided by modules. Overviews available for your installed modules:</p>');
$this
->assertSession()
->responseContains('<h2>Empty section</h2>');
$this
->assertSession()
->responseContains('<p>This description should appear.</p>');
$this
->assertSession()
->pageTextContains('There is currently nothing in this section.');
foreach ($this
->getModuleList() as $module => $name) {
$this
->assertSession()
->linkExists($name, 0, new FormattableMarkup('Link properly added to @name (admin/help/@module)', [
'@module' => $module,
'@name' => $name,
]));
}
$module_name = \Drupal::service('extension.list.module')
->getName('help_test');
$this
->clickLink($module_name);
$this
->assertSession()
->pageTextContains('No help is available for module ' . $module_name);
$this
->drupalGet('admin/help');
$page_text = $this
->getTextContent();
$start = strpos($page_text, 'Module overviews');
$pos = $start;
$list = [
'Block',
'Block Content',
'Breakpoint',
'History',
'Text Editor',
];
foreach ($list as $name) {
$this
->assertSession()
->linkExists($name);
$new_pos = strpos($page_text, $name, $start);
$this
->assertGreaterThan($pos, $new_pos, "Order of {$name} is not correct on page");
$pos = $new_pos;
}
}
protected function verifyHelp($response = 200) {
$this
->drupalGet('admin/index');
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertSession()
->pageTextContains('This page shows you all available administration tasks for each module.');
}
else {
$this
->assertSession()
->pageTextNotContains('This page shows you all available administration tasks for each module.');
}
$module_list = \Drupal::service('extension.list.module');
foreach ($this
->getModuleList() as $module => $name) {
$this
->drupalGet('admin/help/' . $module);
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertSession()
->titleEquals("{$name} | Drupal");
$this
->assertEquals($name, $this
->cssSelect('h1.page-title')[0]
->getText(), "{$module} heading was displayed");
$info = $module_list
->getExtensionInfo($module);
$admin_tasks = \Drupal::service('system.module_admin_links_helper')
->getModuleAdminLinks($module);
if ($module_permissions_link = \Drupal::service('user.module_permissions_link_helper')
->getModulePermissionsLink($module, $info['name'])) {
$admin_tasks["user.admin_permissions.{$module}"] = $module_permissions_link;
}
if (!empty($admin_tasks)) {
$this
->assertSession()
->pageTextContains($name . ' administration pages');
}
foreach ($admin_tasks as $task) {
$this
->assertSession()
->linkExists($task['title']);
$this
->assertSession()
->assertNoEscaped('&');
$this
->assertSession()
->assertNoEscaped('<');
$this
->assertSession()
->assertNoEscaped('<');
}
$this
->assertSession()
->assertNoEscaped('&');
$this
->assertSession()
->assertNoEscaped('<');
if ($module === 'ckeditor5') {
continue;
}
$this
->assertSession()
->assertNoEscaped('<');
}
}
}
protected function getModuleList() {
$modules = [];
$module_data = $this->container
->get('extension.list.module')
->getList();
\Drupal::moduleHandler()
->invokeAllWith('help', function (callable $hook, string $module) use (&$modules, $module_data) {
$modules[$module] = $module_data[$module]->info['name'];
});
return $modules;
}
}
Classes
Name |
Description |
HelpTest |
Verify help display and user access to help based on permissions. |