Problem/Motivation

Testing out #3390193: Add a drupalGet() method to KernelTestBase on help.module

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3517299

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan changed the visibility of the branch 3390193-add-drupalget-with-mink-to-kerneltestbase to hidden.

mstrelan’s picture

Added an MR against 3390193-add-drupalget-with-mink-to-kerneltestbase but since it's against that branch it doesn't appear on the issue page, and the pipelines don't work. But I did it this way so we can see only the changes to Help module and not all the changes in the parent issue.

https://git.drupalcode.org/issue/drupal-3517299/-/merge_requests/1

It was a little annoying having to deal with the fact that we can't perform multiple requests in the same test, but overall it's still faster for the cases that I split. My test times below:

MySQL
ExperimentalHelpTest - Kernel 6.348s, Functional 13.550s
HelpBlockTest - Kernel 8.376s, Functional 13.642s
HelpPageOrderTest - Kernel 3.216s, Functional 14.067s
HelpPageReverseOrderTest - Kernel 3.212s, Functional 13.407s
NoHelpTest - Kernel 7.468s, Functional 15.771s

Total: Kernel 28.62s, Functional 70.437s

MySQL w/ tmpfs
ExperimentalHelpTest - Kernel 3.396s, Functional 6.374s
HelpBlockTest - Kernel 4.992s, Functional 5.254s
HelpPageOrderTest - Kernel 1.686s, Functional 5.254s
HelpPageReverseOrderTest - Kernel 1.700s, Functional 5.404s
NoHelpTest - Kernel 3.574s, Functional 5.754s

Total: Kernel 15.348, Functional 28.04s

So for MySQL with a normal filesystem this is a massive improvement! For tmpfs it's a decent improvement for the tests that only had one drupalGet, but it's much less of an improvement when the test had to be split and we repeat the setup tasks. It might be worth waiting for #2708827: Allows DrupalKernel::handle to handle more than one requests (rough support for PHP-PM) for those tests.

mstrelan’s picture

I investigated the multiple requests issue a little further, and it turns out the only issue is that the paths weren't prefixed with a preceding slash, so the path was appended to the path of the previous request resulting in 404s. After fixing those the updated timing is below.

MySQL
ExperimentalHelpTest - Kernel 3.246s, Functional 13.550s
HelpBlockTest - Kernel 2.818s, Functional 13.642s
HelpPageOrderTest - Kernel 3.216s, Functional 14.067s
HelpPageReverseOrderTest - Kernel 3.212s, Functional 13.407s
NoHelpTest - Kernel 3.831s, Functional 15.771s

Total: Kernel 16.323s, Functional 70.437s

MySQL w/ tmpfs
ExperimentalHelpTest - Kernel 1.739s, Functional 6.374s
HelpBlockTest - Kernel 1.634s, Functional 5.254s
HelpPageOrderTest - Kernel 1.686s, Functional 5.254s
HelpPageReverseOrderTest - Kernel 1.700s, Functional 5.404s
NoHelpTest - Kernel 1.754s, Functional 5.754s

Total: Kernel 8.513s, Functional 28.04s

Those numbers make this much more compelling.

dww’s picture

Thanks for doing a trial run like this! Very helpful and encouraging that the parent issue is on the right track.

If a branch off an issue branch confuses the tooling so much, probably not the end of the world to have an initial commit of #3390193: Add a drupalGet() method to KernelTestBase in here, no? The changes tab will be bloated, but it should be fairly simple to review changes via each proceeding commit...

Anyway, thanks again!

mstrelan’s picture

@dww sure, I've created an MR against 11.x. As a bonus you don't have to review it one commit at a time because all the changes are limited to the help module, other than a7f43433.

mstrelan’s picture

Added 2 more, HelpTest and HelpTopicTest, both of this are much faster now but I don't have the numbers. I did have a go at HelpTopicsSyntaxTest but it was actually significantly slower!

joachim’s picture

> and it turns out the only issue is that the paths weren't prefixed with a preceding slash, so the path was appended to the path of the previous request resulting in 404s

Can you explain a bit more about where this path appending thing happens? Is it something we can maybe fix?
Though OTOH, since the Drupal convention is now that paths should have the initial slash, it's probably a good thing to add that consistently.

I've had a look at your patch on the other issue for converting BlockContentPageViewTest. I'm honestly confused by what this failing test is doing anyway:

  public function testPageEdit(): void {
    $block = $this->createBlockContent();

    // Attempt to view the block.
    $this->drupalGet('block-content/' . $block->id());

    // Ensure user was able to view the block.
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet('/block-content-test');
    $this->assertSession()->pageTextContains('This block is broken or missing. You may be missing content or you might need to install the original module.');
  }

Why would the block report as being broken? What's causing it to be broken? This test needs to explain what it is doing!

mstrelan’s picture

Can you explain a bit more about where this path appending thing happens? Is it something we can maybe fix?

I'm offline for over a week now but when from what I recall you can see it in the html output for ExperimentalHelpTest if you remove the slash and run the test. Didn't look at what was causing it.

Why would the block report as being broken? What's causing it to be broken? This test needs to explain what it is doing!

IIRC there is a test module that includes config for a block, but that block is referencing the uuid of a block content entity that doesn't exist. Couldn't tell you why, but it's not really relevant. I think let's ignore that test for now.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

catch’s picture

Title: [PP-1] Convert functional tests in help module to kernel tests » Convert functional tests in help module to kernel tests
Status: Postponed » Needs work
joachim’s picture

Rebased.

I had to remove history module from being installed in one test, but it made no difference to the test at all!?!?

HelpTopicTest isn't working, and the error is to do with how the Help module or Twig is outputting inline links.

joachim’s picture

The problem is

        $options['absolute'] = TRUE;

in HelpTwigExtension.

joachim’s picture

Filed #3582382: absolute links don't work in Kernel tests.

We could skip HelpTopicTest for now to get this in.

joachim’s picture

joachim’s picture

I don't understand why we need to add this to drupalGet():

$this->content = $out

UiHelperTrait::drupalGet() doesn't have it.

joachim’s picture

We probably should switch from using AssertContentTrait methods to using Mink methods as part of the conversion.

dww’s picture

Re: #17 and #18: While I appreciate the desire for elegance and simplicity in the new trait, I'd strongly vote in favor of doing whatever we can to minimize the changes necessary to convert something from Functional to Kernel. If we have to update a ton of assertions, it's going to massively slow down conversions, bog down reviewers, require more cognitive load, etc. That 1 line (and minor waste of RAM while the test is running, if I understand correctly) seems like it'll save a ton of effort. So IMHO, I'd sacrifice a little elegance for easier conversions.

Thanks!
-Derek

joachim’s picture

I'm not totally against adding $this->content = $out but aren't PHPStan/PHPCS going to complain about a trait setting a property it doesn't have?

mstrelan’s picture

Phpstan analyses traits in the context of the class that uses them, it's essentially flattened before it's analysed.

joachim’s picture

joachim’s picture

Adding clickLink in #3582769: Add clickLink() to HttpKernelUiHelperTrait, changing this MR accordingly.

joachim’s picture

We should add these to the main trait in a separate issue:

+  /**
+   * 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();
joachim’s picture

Status: Needs work » Needs review
dww’s picture

Re #24: I opened #3583594: Add getUrl() and (renamed) xpath() helpers to HttpKernelUiHelperTrait but the pipeline in there fails all Kernel tests with a conflicting xpath() method in both traits. Seems #3582985: Add content from HttpKernelUiHelperTrait::drupalGet() to $this->content for use by AssertContentTrait is the better solution, then we don't need a separate copy of xpath(). Then that would leave #3583594 to only add the getUrl() method. As I wrote over there, maybe we should merge all these follow-ups to be easier to manage, coordinate, and hopefully backport?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new547 bytes

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joachim’s picture

Status: Needs work » Needs review

Rebased and fixed baseline issue.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joachim’s picture

Status: Needs work » Needs review

Rebased.

smustgrave’s picture

Should the MR still be in draft?

smustgrave’s picture

joachim’s picture

If that gets in first, it's going to be a nightmare to rebase this MR, because the files are moved.

smustgrave’s picture

Status: Needs review » Postponed

So the issue in #33 is RTBC and more then likely will land first. Vs making it a competition lets just postpone this as I feel that one is slightly more important, not to down play these conversions but the tests are there so nothing is lost. If that makes sense.

alexpott’s picture

Status: Postponed » Needs review

@smustgrave please don't postpone - we don't need to - resolve git conflicts is part of working together and are not horrible.

alexpott’s picture

$ git merge main                                                                                                 
Auto-merging core/modules/help/tests/src/Kernel/HelpTest.php
Auto-merging core/modules/help/tests/src/Kernel/HelpTopicTest.php
Merge made by the 'ort' strategy.
 core/modules/help/src/Controller/HelpController.php                                | 1 +
 core/modules/help/src/Hook/HelpHooks.php                                           | 5 ++++-
 core/modules/help/templates/help-section.html.twig                                 | 3 ++-
 core/modules/help/tests/src/Kernel/HelpTest.php                                    | 4 ++--
 core/modules/help/tests/src/Kernel/HelpTopicTest.php                               | 2 +-
 core/profiles/demo_umami/themes/umami/templates/classy/misc/help-section.html.twig | 3 ++-
 core/themes/claro/templates/classy/misc/help-section.html.twig                     | 3 ++-
 core/themes/stable9/templates/admin/help-section.html.twig                         | 3 ++-
 8 files changed, 16 insertions(+), 8 deletions(-)

And git correct merged the assertions. - I did not even need to do anything.

smustgrave’s picture

noted

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Only functional test that remains are upgrade tests and HelpTopicTranslationTest. I'm assuming HelpTopicTranslationTest has to remain as it does does a drupalLogin(). Rest looks good.

catch’s picture

Status: Reviewed & tested by the community » Needs review

I think we need to decide what to do about the xpath etc. methods in #28 - go ahead here then update the test once one of those issues is in, or wait for one of those to land. I don't have a strong preference as long as we end up in the same place, but moving back to needs review for that.

smustgrave’s picture

@catch you mean #3583594: Add getUrl() and (renamed) xpath() helpers to HttpKernelUiHelperTrait that is RTBC maybe it could be committed and used here?

smustgrave’s picture

Status: Needs review » Needs work

Now that #3583594: Add getUrl() and (renamed) xpath() helpers to HttpKernelUiHelperTrait I'm assuming catch you wanted to see that used here somewhere?

mstrelan’s picture

Status: Needs work » Needs review
Issue tags: +DrupalSouth 2026

I worked on this at DrupalSouth contribution day. Have rebased and removed the custom xpath and getCurrentUrl functions. Unfortunately there is a new problem in that AssertBreadcrumbTrait calls $this->xpath but can be used in either kernel or functional tests. I've added a method_exists call in that trait but I think for even better compatibility we should add getNodeElementsByXpath to BrowserTestBase and deprecate xpath.

mstrelan’s picture

I just found #3585774: rename xpath() methods in tests so either we postpone this on that or update that one after this gets in.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

This one was postponed once (all be it incorrectly by me) so let’s try and land it.

  • alexpott committed 2129f980 on main
    task: #3517299 Convert functional tests in help module to kernel tests...

  • alexpott committed 3c5fc5f3 on 11.x
    task: #3517299 Convert functional tests in help module to kernel tests...
alexpott’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 2129f98 and pushed to main. Thanks!
Committed 3c5fc5f and pushed to 11.x. Thanks!

I recreated the baseline on 11.x in order to merge this there.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 7df5aaea on 11.x
    Revert "task: #3517299 Convert functional tests in help module to kernel...
alexpott’s picture

Version: 11.x-dev » main

Actually the new tests are going to fail on 11.x so reverted.

  • alexpott committed 733f95f8 on 11.x
    task: #3517299 Convert functional tests in help module to kernel tests...
alexpott’s picture

Version: main » 11.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.