diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index af4e5513cc00541959a991b34619d9c9520b2064..c00a10e53c04055cae1d17ebdda032508dd7c1c8 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -19795,19 +19795,19 @@ 'message' => '#^Method Drupal\\\\Tests\\\\help\\\\Functional\\\\HelpTopicTest\\:\\:assertBreadcrumb\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, - 'path' => __DIR__ . '/modules/help/tests/src/Functional/HelpTopicTest.php', + 'path' => __DIR__ . '/modules/help/tests/src/Kernel/HelpTopicTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\help\\\\Functional\\\\HelpTopicTest\\:\\:assertBreadcrumbParts\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, - 'path' => __DIR__ . '/modules/help/tests/src/Functional/HelpTopicTest.php', + 'path' => __DIR__ . '/modules/help/tests/src/Kernel/HelpTopicTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\help\\\\Functional\\\\HelpTopicTest\\:\\:assertMenuActiveTrail\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, - 'path' => __DIR__ . '/modules/help/tests/src/Functional/HelpTopicTest.php', + 'path' => __DIR__ . '/modules/help/tests/src/Kernel/HelpTopicTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\help\\\\Unit\\\\HelpTopicTwigTest\\:\\:getTwigMock\\(\\) has no return type specified\\.$#', @@ -54429,7 +54429,6 @@ 'path' => __DIR__ . '/tests/Drupal/Tests/BrowserTestBase.php', ]; $ignoreErrors[] = [ - // identifier: missingType.return 'message' => '#^Method Drupal\\\\Tests\\\\BrowserTestBase\\:\\:initConfig\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, diff --git a/core/modules/help/tests/src/Functional/ExperimentalHelpTest.php b/core/modules/help/tests/src/Kernel/ExperimentalHelpTest.php similarity index 63% rename from core/modules/help/tests/src/Functional/ExperimentalHelpTest.php rename to core/modules/help/tests/src/Kernel/ExperimentalHelpTest.php index 7c8a39335758f8133d79959a8a32ddfd5ea12c15..967974174bcc07d5a0bda2b74a9caa633de1d7a0 100644 --- a/core/modules/help/tests/src/Functional/ExperimentalHelpTest.php +++ b/core/modules/help/tests/src/Kernel/ExperimentalHelpTest.php @@ -2,16 +2,22 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; -use Drupal\Tests\BrowserTestBase; +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\HttpKernelUiHelperTrait; +use Drupal\Tests\user\Traits\UserCreationTrait; +use Drupal\user\UserInterface; /** * Verifies help for experimental modules. * * @group help */ -class ExperimentalHelpTest extends BrowserTestBase { +class ExperimentalHelpTest extends KernelTestBase { + + use HttpKernelUiHelperTrait; + use UserCreationTrait; /** * Modules to install. @@ -25,38 +31,34 @@ class ExperimentalHelpTest extends BrowserTestBase { 'help', 'experimental_module_test', 'help_page_test', + 'user', + 'system', ]; - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - /** * The admin user. - * - * @var \Drupal\user\UserInterface */ - protected $adminUser; + protected UserInterface $adminUser; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(['access help pages']); + $this->installEntitySchema('user'); + $this->adminUser = $this->createUser(['access help pages']); + $this->setCurrentUser($this->adminUser); } /** * Verifies that a warning message is displayed for experimental modules. */ public function testExperimentalHelp(): void { - $this->drupalLogin($this->adminUser); - $this->drupalGet('admin/help/experimental_module_test'); + $this->drupalGet('/admin/help/experimental_module_test'); $this->assertSession()->statusMessageContains('This module is experimental.', 'warning'); // Regular modules should not display the message. - $this->drupalGet('admin/help/help_page_test'); + $this->drupalGet('/admin/help/help_page_test'); $this->assertSession()->statusMessageNotContains('This module is experimental.'); // Ensure the actual help page is displayed to avoid a false positive. diff --git a/core/modules/help/tests/src/Functional/HelpBlockTest.php b/core/modules/help/tests/src/Kernel/HelpBlockTest.php similarity index 65% rename from core/modules/help/tests/src/Functional/HelpBlockTest.php rename to core/modules/help/tests/src/Kernel/HelpBlockTest.php index 074629593ce8bb7e522b45b417ec666057f9a8c4..6e4453fecc0a5b320e656984e04cb64c5a845048 100644 --- a/core/modules/help/tests/src/Functional/HelpBlockTest.php +++ b/core/modules/help/tests/src/Kernel/HelpBlockTest.php @@ -2,16 +2,21 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; -use Drupal\Tests\BrowserTestBase; +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\block\Traits\BlockCreationTrait; +use Drupal\Tests\HttpKernelUiHelperTrait; /** * Tests display of help block. * * @group help */ -class HelpBlockTest extends BrowserTestBase { +class HelpBlockTest extends KernelTestBase { + + use HttpKernelUiHelperTrait; + use BlockCreationTrait; /** * {@inheritdoc} @@ -21,13 +26,10 @@ class HelpBlockTest extends BrowserTestBase { 'help_page_test', 'block', 'more_help_page_test', + 'system', + 'user', ]; - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - /** * The help block instance. * @@ -40,6 +42,9 @@ class HelpBlockTest extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); + $this->installEntitySchema('block'); + $this->container->get('theme_installer')->install(['stark']); + $this->config('system.theme')->set('default', 'stark')->save(); $this->helpBlock = $this->placeBlock('help_block'); } @@ -47,17 +52,17 @@ protected function setUp(): void { * Logs in users, tests help pages. */ public function testHelp(): void { - $this->drupalGet('help_page_test/has_help'); + $this->drupalGet('/help_page_test/has_help'); $this->assertSession()->pageTextContains('I have help!'); $this->assertSession()->pageTextContains($this->helpBlock->label()); - $this->drupalGet('help_page_test/no_help'); // The help block should not appear when there is no help. + $this->drupalGet('/help_page_test/no_help'); $this->assertSession()->pageTextNotContains($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->drupalGet('/help_page_test/test_array'); $this->assertSession()->pageTextContains('Help text from more_help_page_test_help module.'); $this->assertSession()->pageTextContains('Help text from help_page_test_help module.'); } diff --git a/core/modules/help/tests/src/Functional/HelpPageOrderTest.php b/core/modules/help/tests/src/Kernel/HelpPageOrderTest.php similarity index 61% rename from core/modules/help/tests/src/Functional/HelpPageOrderTest.php rename to core/modules/help/tests/src/Kernel/HelpPageOrderTest.php index 3013d5671c137674f32f099a651c71091103ecde..b12098ff294b042bf6200f5cfade3bb3c7c6f35b 100644 --- a/core/modules/help/tests/src/Functional/HelpPageOrderTest.php +++ b/core/modules/help/tests/src/Kernel/HelpPageOrderTest.php @@ -2,33 +2,33 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; -use Drupal\Tests\BrowserTestBase; +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\HttpKernelUiHelperTrait; +use Drupal\Tests\user\Traits\UserCreationTrait; /** * Verify the order of the help page. * * @group help */ -class HelpPageOrderTest extends BrowserTestBase { +class HelpPageOrderTest extends KernelTestBase { - /** - * {@inheritdoc} - */ - protected static $modules = ['help', 'help_page_test']; + use HttpKernelUiHelperTrait; + use UserCreationTrait; /** * {@inheritdoc} */ - protected $defaultTheme = 'stark'; + protected static $modules = ['help', 'help_page_test', 'system', 'user']; /** * Strings to search for on admin/help, in order. * * @var string[] */ - protected $stringOrder = [ + protected array $stringOrder = [ 'Module overviews are provided', 'This description should appear', ]; @@ -38,14 +38,13 @@ class HelpPageOrderTest extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); + $this->installEntitySchema('user'); // Create and log in user. - $account = $this->drupalCreateUser([ + $account = $this->createUser([ 'access help pages', - 'view the administration theme', - 'administer permissions', ]); - $this->drupalLogin($account); + $this->setCurrentUser($account); } /** @@ -53,7 +52,7 @@ protected function setUp(): void { */ public function testHelp(): void { $pos = 0; - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $page_text = $this->getTextContent(); foreach ($this->stringOrder as $item) { $new_pos = strpos($page_text, $item, $pos); diff --git a/core/modules/help/tests/src/Functional/HelpPageReverseOrderTest.php b/core/modules/help/tests/src/Kernel/HelpPageReverseOrderTest.php similarity index 77% rename from core/modules/help/tests/src/Functional/HelpPageReverseOrderTest.php rename to core/modules/help/tests/src/Kernel/HelpPageReverseOrderTest.php index dad596a48e73f4bf3ceeff198823abe09907c28f..1221e6a73b4caa36625638d3b28705a94a9ed5e8 100644 --- a/core/modules/help/tests/src/Functional/HelpPageReverseOrderTest.php +++ b/core/modules/help/tests/src/Kernel/HelpPageReverseOrderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; /** * Verify the order of the help page with an alter hook. @@ -16,11 +16,6 @@ class HelpPageReverseOrderTest extends HelpPageOrderTest { */ protected static $modules = ['more_help_page_test']; - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - /** * Strings to search for on admin/help, in order. * @@ -28,7 +23,7 @@ class HelpPageReverseOrderTest extends HelpPageOrderTest { * * @var string[] */ - protected $stringOrder = [ + protected array $stringOrder = [ 'This description should appear', 'Module overviews are provided', ]; diff --git a/core/modules/help/tests/src/Functional/HelpTest.php b/core/modules/help/tests/src/Kernel/HelpTest.php similarity index 80% rename from core/modules/help/tests/src/Functional/HelpTest.php rename to core/modules/help/tests/src/Kernel/HelpTest.php index 3a954ac0eadddbf2021bb6ccf4861cc5a81f04fe..908acdab1cd6fd196ffcf612e0b53e9890e7c41f 100644 --- a/core/modules/help/tests/src/Functional/HelpTest.php +++ b/core/modules/help/tests/src/Kernel/HelpTest.php @@ -2,17 +2,24 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; use Drupal\Component\Render\FormattableMarkup; -use Drupal\Tests\BrowserTestBase; +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\block\Traits\BlockCreationTrait; +use Drupal\Tests\HttpKernelUiHelperTrait; +use Drupal\Tests\user\Traits\UserCreationTrait; /** * Verify help display and user access to help based on permissions. * * @group help */ -class HelpTest extends BrowserTestBase { +class HelpTest extends KernelTestBase { + + use BlockCreationTrait; + use HttpKernelUiHelperTrait; + use UserCreationTrait; /** * Modules to install. @@ -24,20 +31,19 @@ class HelpTest extends BrowserTestBase { * @var array */ protected static $modules = [ + 'block', 'block_content', 'breakpoint', 'editor', + 'filter', 'help', 'help_page_test', 'help_test', 'history', + 'system', + 'user', ]; - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'claro'; - /** * The admin user that will be created. * @@ -57,14 +63,25 @@ class HelpTest extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); + $this->installEntitySchema('block'); + $this->installEntitySchema('block_content'); + $this->installEntitySchema('user'); // Create users. - $this->adminUser = $this->drupalCreateUser([ + $this->adminUser = $this->createUser([ 'access help pages', 'view the administration theme', 'administer permissions', ]); - $this->anyUser = $this->drupalCreateUser([]); + $this->anyUser = $this->createUser(); + + $this->installConfig('system'); + $this->config('system.site')->set('name', 'Drupal')->save(); + + $this->container->get('theme_installer')->install(['stark']); + $this->config('system.theme')->set('default', 'stark')->save(); + $this->placeBlock('page_title_block'); + $this->placeBlock('help_block'); } /** @@ -73,19 +90,19 @@ protected function setUp(): void { public function testHelp(): void { // Log in the root user to ensure as many admin links appear as possible on // the module overview pages. - $this->drupalLogin($this->drupalCreateUser([ + $this->setCurrentUser($this->createUser([ 'access help pages', 'access administration pages', ])); $this->verifyHelp(); // Log in the regular user. - $this->drupalLogin($this->anyUser); + $this->setCurrentUser($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->setCurrentUser($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>.'); // Verify that hook_help() section title and description appear. @@ -99,19 +116,23 @@ public function testHelp(): void { // Make sure links are properly added for modules implementing hook_help(). 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])); + $this->assertSession()->linkExists($name, 0, new FormattableMarkup('Link properly added to @name (admin/help/@module)', [ + '@module' => $module, + '@name' => $name, + ])); } // Ensure a module which does not provide a module overview page is handled // correctly. $module_name = \Drupal::service('extension.list.module')->getName('help_test'); - $this->clickLink($module_name); + $link = $this->getSession()->getPage()->find('named', ['link', $module_name]); + $this->drupalGet($link->getAttribute('href')); $this->assertSession()->pageTextContains('No help is available for module ' . $module_name); // 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'); + $this->drupalGet('/admin/help'); $page_text = $this->getTextContent(); $start = strpos($page_text, 'Module overviews'); $pos = $start; @@ -131,7 +152,7 @@ public function testHelp(): void { * (optional) An HTTP response code. Defaults to 200. */ protected function verifyHelp($response = 200): void { - $this->drupalGet('admin/index'); + $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.'); @@ -143,11 +164,11 @@ protected function verifyHelp($response = 200): void { $module_list = \Drupal::service('extension.list.module'); foreach ($this->getModuleList() as $module => $name) { // View module help page. - $this->drupalGet('admin/help/' . $module); + $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"); + $this->assertSession()->elementTextEquals('css', 'h1', $name); $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'])) { diff --git a/core/modules/help/tests/src/Functional/HelpTopicTest.php b/core/modules/help/tests/src/Kernel/HelpTopicTest.php similarity index 75% rename from core/modules/help/tests/src/Functional/HelpTopicTest.php rename to core/modules/help/tests/src/Kernel/HelpTopicTest.php index 7675d765ce5ac084de6cfb46bd508f46b4c3a150..e7a51ddf1b4492f57baa47587a67672fe207bc3a 100644 --- a/core/modules/help/tests/src/Functional/HelpTopicTest.php +++ b/core/modules/help/tests/src/Kernel/HelpTopicTest.php @@ -2,18 +2,26 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; -use Drupal\Tests\BrowserTestBase; +use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\block\Traits\BlockCreationTrait; +use Drupal\Tests\HttpKernelUiHelperTrait; use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait; +use Drupal\Tests\user\Traits\UserCreationTrait; /** * Verifies help topic display and user access to help based on permissions. * * @group help */ -class HelpTopicTest extends BrowserTestBase { +class HelpTopicTest extends KernelTestBase { + use AssertBreadcrumbTrait; + use BlockCreationTrait; + use HttpKernelUiHelperTrait; + use UserCreationTrait; /** * {@inheritdoc} @@ -22,13 +30,11 @@ class HelpTopicTest extends BrowserTestBase { 'help_topics_test', 'help', 'block', + 'user', + 'system', + 'path_alias', ]; - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - /** * The admin user that will be created. * @@ -50,15 +56,31 @@ class HelpTopicTest extends BrowserTestBase { */ protected $anyUser; + /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container): void { + parent::register($container); + $container->setParameter('http.response.debug_cacheability_headers', TRUE); + } + /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); + $this->installEntitySchema('path_alias'); + $this->installEntitySchema('user'); + $this->installSchema('user', ['users_data']); + + $this->installConfig('system'); + $this->config('system.site')->set('name', 'Drupal')->save(); + // These tests rely on some markup from the 'stark' theme and we test theme // provided help topics. - \Drupal::service('theme_installer')->install(['help_topics_test_theme']); + \Drupal::service('theme_installer')->install(['help_topics_test_theme', 'stark']); + $this->config('system.theme')->set('default', 'stark')->save(); // Place various blocks. $settings = [ @@ -88,7 +110,7 @@ protected function setUp(): void { 'administer site configuration', ]); - $this->anyUser = $this->createUser([]); + $this->anyUser = $this->createUser(); } /** @@ -98,16 +120,16 @@ public function testHelp(): void { $session = $this->assertSession(); // Log in the regular user. - $this->drupalLogin($this->anyUser); + $this->setCurrentUser($this->anyUser); $this->verifyHelp(403); // Log in the admin user. - $this->drupalLogin($this->adminUser); + $this->setCurrentUser($this->adminUser); $this->verifyHelp(); $this->verifyBreadCrumb(); // Verify that help topics text appears on admin/help, and cache tags. - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $session->responseContains('<h2>Topics</h2>'); $session->pageTextContains('Topics can be provided by modules or themes'); $session->responseHeaderContains('X-Drupal-Cache-Tags', 'core.extension'); @@ -128,11 +150,11 @@ public function testHelp(): void { $session->linkExists('ABC Help Test module'); \Drupal::state()->set('help_topics_test.test:top_level', FALSE); \Drupal::service('plugin.manager.help_topic')->clearCachedDefinitions(); - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $session->linkNotExists('ABC Help Test module'); \Drupal::state()->set('help_topics_test.test:top_level', TRUE); \Drupal::service('plugin.manager.help_topic')->clearCachedDefinitions(); - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); // Ensure all the expected links are present before uninstalling. $session->linkExists('ABC Help Test module'); @@ -142,14 +164,14 @@ public function testHelp(): void { // Uninstall the test module and verify the topics are gone, after // reloading page. $this->container->get('module_installer')->uninstall(['help_topics_test']); - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $session->linkNotExists('ABC Help Test module'); $session->linkNotExists('ABC Help Test'); $session->linkExists('XYZ Help Test theme'); // Uninstall the test theme and verify the topic is gone. $this->container->get('theme_installer')->uninstall(['help_topics_test_theme']); - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $session->linkNotExists('XYZ Help Test theme'); } @@ -165,7 +187,7 @@ protected function verifyHelp($response = 200): void { // Verify access to help topic pages. foreach ($this->getTopicList() as $topic => $info) { // View help topic page. - $this->drupalGet('admin/help/topic/' . $topic); + $this->drupalGet('/admin/help/topic/' . $topic); $session = $this->assertSession(); $session->statusCodeEquals($response); if ($response == 200) { @@ -185,10 +207,10 @@ protected function verifyHelp($response = 200): void { */ public function testHelpLinks(): void { $session = $this->assertSession(); - $this->drupalLogin($this->adminUser); + $this->setCurrentUser($this->adminUser); // Verify links on the test top-level page. - $page = 'admin/help/topic/help_topics_test.test'; + $page = '/admin/help/topic/help_topics_test.test'; // Array element is the page text if you click through. $links = [ 'Linked topic' => 'This topic is not supposed to be top-level', @@ -197,24 +219,26 @@ public function testHelpLinks(): void { ]; foreach ($links as $link_text => $page_text) { $this->drupalGet($page); - $this->clickLink($link_text); + $link = $this->getSession()->getPage()->find('named', ['link', $link_text]); + $this->drupalGet($link->getAttribute('href')); $session->pageTextContains($page_text); } // Verify theme provided help topics work and can be related. - $this->drupalGet('admin/help/topic/help_topics_test_theme.test'); + $this->drupalGet('/admin/help/topic/help_topics_test_theme.test'); $session->pageTextContains('This is a theme provided topic.'); $this->assertStringContainsString('This is a theme provided topic.', $session->elementExists('css', 'article')->getText()); - $this->clickLink('Additional topic'); + $link = $this->getSession()->getPage()->find('named', ['link', 'Additional topic']); + $this->drupalGet($link->getAttribute('href')); $session->linkExists('XYZ Help Test theme'); // Verify that the non-top-level topics do not appear on the Help page. - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $session->linkNotExists('Linked topic'); $session->linkNotExists('Additional topic'); // Verify links and non-links on the URL test page. - $this->drupalGet('admin/help/topic/help_topics_test.test_urls'); + $this->drupalGet('/admin/help/topic/help_topics_test.test_urls'); $links = [ 'not a route' => FALSE, 'missing params' => FALSE, @@ -236,8 +260,8 @@ public function testHelpLinks(): void { // Verify that the "no test" user, who should not be able to access // the 'valid link' URL, sees it as not a link. - $this->drupalLogin($this->noTestUser); - $this->drupalGet('admin/help/topic/help_topics_test.test_urls'); + $this->setCurrentUser($this->noTestUser); + $this->drupalGet('/admin/help/topic/help_topics_test.test_urls'); $session->pageTextContains('valid link'); $session->linkNotExists('valid link'); } @@ -279,7 +303,7 @@ public function verifyBreadCrumb(): void { 'admin' => 'Administration', 'admin/help' => 'Help', ]; - $this->assertBreadcrumb('admin/help/topic/help_topics_test.test', $trail); + $this->assertBreadcrumb('/admin/help/topic/help_topics_test.test', $trail); // Ensure we are on the expected help topic page. $this->assertSession()->pageTextContains('Also there should be a related topic link below to the Help module topic page and the linked topic.'); @@ -290,7 +314,27 @@ public function verifyBreadCrumb(): void { 'admin/config' => 'Configuration', 'admin/config/system' => 'System', ]; - $this->assertBreadcrumb('admin/config/system/site-information', $trail); + $this->assertBreadcrumb('/admin/config/system/site-information', $trail); + } + + /** + * Overrides AssertContentTrait for use in Kernel tests. + * + * @see \Drupal\KernelTests\AssertContentTrait::xpath() + * @see \Drupal\Tests\BrowserTestBase::xpath() + */ + protected function xpath($xpath, array $arguments = []): array { + $xpath = $this->assertSession()->buildXPathQuery($xpath, $arguments); + return $this->getSession()->getPage()->findAll('xpath', $xpath); + } + + /** + * Get the current URL from the browser. + * + * @see \Drupal\Tests\UiHelperTrait::getUrl + */ + protected function getUrl(): string { + return $this->getSession()->getCurrentUrl(); } } diff --git a/core/modules/help/tests/src/Functional/NoHelpTest.php b/core/modules/help/tests/src/Kernel/NoHelpTest.php similarity index 69% rename from core/modules/help/tests/src/Functional/NoHelpTest.php rename to core/modules/help/tests/src/Kernel/NoHelpTest.php index 88f1c60fabe57ad7084eacc72c7265f842ba0d9f..1136eed578157c26a09b8807f6fd89c90e13f813 100644 --- a/core/modules/help/tests/src/Functional/NoHelpTest.php +++ b/core/modules/help/tests/src/Kernel/NoHelpTest.php @@ -2,16 +2,21 @@ declare(strict_types=1); -namespace Drupal\Tests\help\Functional; +namespace Drupal\Tests\help\Kernel; -use Drupal\Tests\BrowserTestBase; +use Drupal\KernelTests\KernelTestBase; +use Drupal\Tests\HttpKernelUiHelperTrait; +use Drupal\Tests\user\Traits\UserCreationTrait; /** * Verify no help is displayed for modules not providing any help. * * @group help */ -class NoHelpTest extends BrowserTestBase { +class NoHelpTest extends KernelTestBase { + + use HttpKernelUiHelperTrait; + use UserCreationTrait; /** * Modules to install. @@ -20,12 +25,7 @@ class NoHelpTest extends BrowserTestBase { * * @var array */ - protected static $modules = ['help', 'menu_test']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; + protected static $modules = ['help', 'menu_test', 'user', 'system']; /** * The user who will be created. @@ -39,16 +39,16 @@ class NoHelpTest extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(['access help pages']); + $this->installEntitySchema('user'); + $this->adminUser = $this->createUser(['access help pages']); + $this->setCurrentUser($this->adminUser); } /** * Ensures modules not implementing help do not appear on admin/help. */ public function testMainPageNoHelp(): void { - $this->drupalLogin($this->adminUser); - - $this->drupalGet('admin/help'); + $this->drupalGet('/admin/help'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('Module overviews are provided by modules'); $this->assertFalse(\Drupal::moduleHandler()->hasImplementations('help', 'menu_test'), 'The menu_test module does not implement hook_help'); @@ -58,7 +58,7 @@ public function testMainPageNoHelp(): void { // Ensure that the module overview help page for a module that does not // implement hook_help() results in a 404. - $this->drupalGet('admin/help/menu_test'); + $this->drupalGet('/admin/help/menu_test'); $this->assertSession()->statusCodeEquals(404); } diff --git a/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php b/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php index 62f396a6ebda65a8bc176da9a3c3d1b84516d2ac..d71c38caa828cd32b0526c1c527dfea711a54503 100644 --- a/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php +++ b/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php @@ -106,7 +106,7 @@ protected function getHtmlOutputHeaders() { * * @see \Drupal\Tests\Listeners\VerbosePrinter::printResult() * - * @return void + * @phpstan-ignore missingType.return */ protected function htmlOutput($message = NULL) { if (!$this->htmlOutputEnabled) { @@ -126,7 +126,7 @@ protected function htmlOutput($message = NULL) { /** * Creates the directory to store browser output. * - * @return void + * @phpstan-ignore missingType.return */ protected function initBrowserOutputFile() { $browserOutputFile = getenv('BROWSERTEST_OUTPUT_FILE'); diff --git a/core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php b/core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php index c9fe1ac8e4c17890d4cea71740312e42f67c3ed3..840bdbe0194d7aeff9149f99cb572ae84947a819 100644 --- a/core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php +++ b/core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php @@ -10,7 +10,6 @@ use Behat\Mink\Selector\SelectorsHandler; use Behat\Mink\Session; use Drupal\Core\Url; -use Drupal\Tests\WebAssert; use Symfony\Component\HttpKernel\HttpKernelBrowser; /** @@ -81,6 +80,7 @@ protected function drupalGet($path, array $options = [], array $headers = []): s $session->visit($path); $out = $session->getPage()->getContent(); + $this->content = $out; if ($this->htmlOutputEnabled) { $html_output = 'GET request to: ' . $path;