Problem/Motivation

I noticed this while working on https://www.drupal.org/project/admin_toolbar/issues/3407845, where a test in the newly set-up CI fails. This is because the test just extends ToolbarAdminMenuTest, where drupalGet is called thusly:

$this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']);

Resulting in this pipeline-error:

TypeError: Behat\Mink\Session::setRequestHeader(): Argument #1 ($name) must be of type string, int given, called in /builds/issue/admin_toolbar-3407845/web/core/tests/Drupal/Tests/UiHelperTrait.php on line 235

As the documentation for drupalGet() states:

An array containing additional HTTP request headers, the array keys are the header names and the array values the header values.

So in the above case it would be

$this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']);

Proposed resolution

Try and find all spots in the code where drupalGet() is called with headers where only one string per header instead of a key-value pair is used, and split them up.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#5 3440169-nr-bot.txt90 bytesneeds-review-queue-bot

Issue fork drupal-3440169

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

marcoliver created an issue. See original summary.

marcoliver’s picture

Status: Active » Needs review

See MR.

Basically just Ctrl-Shift-F'ed Core for drupalGet\(.*,.*,.* and then manually combed through the results to find any offending calls.

marcoliver’s picture

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 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.

dydave’s picture

Thanks a lot Marc-Oliver (@marcoliver) for raising this issue and for your code contributions, it's greatly appreciated!

Just a quick comment to confirm the core module Toolbar test:
Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testSubtreesJsonRequest

currently seems to be failing 🔴 (10.3.x/10.4.x), see:
https://git.drupalcode.org/project/drupal/-/blob/10.3.x/core/modules/too...

$ ./vendor/bin/phpunit ./web/core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php

PHPUnit 9.6.19 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest
.....E...                                                           9 / 9 (100%)

Time: 01:23.484, Memory: 4.00 MB

There was 1 error:

1) Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testSubtreesJsonRequest
TypeError: Behat\Mink\Session::setRequestHeader(): Argument #1 ($name) must be of type string, int given, called in /var/www/html/web/core/tests/Drupal/Tests/UiHelperTrait.php on line 235

/var/www/html/vendor/behat/mink/src/Session.php:199
/var/www/html/web/core/tests/Drupal/Tests/UiHelperTrait.php:235
/var/www/html/web/core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php:387
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729

ERRORS!
Tests: 9, Assertions: 207, Errors: 1.

 

I haven't had the time to look any further than that or really test the changes from the merge request (MR!7445), but we would definitely appreciate some reviews, testing and feedback.

Thanks in advance!

marcoliver’s picture

Status: Needs work » Needs review
smustgrave’s picture

Version: 10.3.x-dev » 11.0.x-dev
Status: Needs review » Needs work

Have not reviewed but MR should be against 11.x as the latest dev branch.

dydave’s picture

@marcoliver, when you get a moment, could you please change the target branch of the merge request to 11.x, as requested at #8 ?
It seems I'm unable to edit the merge request, even with push access to the issue fork.

Otherwise if we need to create a new MR, let me know I would be glad to do so.
Thanks!

marcoliver’s picture

Status: Needs work » Needs review

Sure thing! I created a new MR (8257) targeting 11.0.x.

smustgrave’s picture

Status: Needs review » Needs work

So MR should be against 11.x not 11.0.x

marcoliver changed the visibility of the branch 11.x to hidden.

marcoliver’s picture

Status: Needs work » Needs review

Oops, my bad! MR 8277 now targets 11.x

smustgrave’s picture

Version: 11.0.x-dev » 11.x-dev
Status: Needs review » Reviewed & tested by the community

Thanks, seems like a good refactor.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This is a duplicate of #3421105: Add deprecations for update to behat/* dependencies - it's fine if we continue in this issue as we've start here and not there. But we need to trigger a deprecation in \Drupal\Tests\UiHelperTrait::drupalGet() when if (is_int($header_name)) {.

If this issue does not add the deprecation then we cannot prove we've fixed this in core.

pooja_sharma made their first commit to this issue’s fork.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to hidden.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to active.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to hidden.

pooja_sharma changed the visibility of the branch 11.x to active.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to active.

pooja_sharma changed the visibility of the branch 11.x to hidden.

pooja_sharma’s picture

Addressed the mentioned changes, fixed the test failures case as well

Please review, moved NR

pooja_sharma’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Left some comments about the link. Not sure if the intention is to point to https://www.drupal.org/node/3408184 but currently it's pointing to a drupal issues vs CR.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to hidden.

pooja_sharma’s picture

Status: Needs work » Needs review

Updated the change record nid

Please review , moved NR

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to active.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to hidden.

pooja_sharma changed the visibility of the branch 11.x to active.

pooja_sharma changed the visibility of the branch 3440169-when-using-drupalget-11.x to active.

smustgrave’s picture

Status: Needs review » Needs work

Comment #31 was a suggestion/question. But if that is the CR it needs to be updated as the CR doesn't match what is being done in the code. Either that's suppose to be the one used or a new one needs to be written.

pooja_sharma’s picture

This is something I'm uncertain about.

@alexpott, I have reused change request https://www.drupal.org/node/3408184

can you please confirm is this correct or needs to be written new one?

pooja_sharma’s picture

I have added change record for respective deprecations & updated change record nid in MR.

Rebased MR, Please review , moved NR

pooja_sharma’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Would need to deprecate in 10.4 so this can be backported too.

pooja_sharma’s picture

Status: Needs work » Needs review

Updated deprecate message version in 10.4

Please review, moved NR

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thanks believe this one is good to go.

pooja_sharma’s picture

Rebased the MR with latest code, seems fine

pooja_sharma’s picture

Rebased the MR with latest code, seems fine

alexpott’s picture

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

Committed ebe942c and pushed to 11.x. Thanks!
Committed and pushed 519cafc4ab to 11.0.x and 72ea6d707b to 10.4.x and 5ac4362491 to 10.3.x. Thanks!

I've moved the deprecation to 11.1.0 (less disruptive) but backported the changes to 10.3.x as a test-only fix to keep everything aligned and make for easier backports.

diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php
index f3d9f6c164..a1ea81aec3 100644
--- a/core/tests/Drupal/Tests/UiHelperTrait.php
+++ b/core/tests/Drupal/Tests/UiHelperTrait.php
@@ -245,11 +245,11 @@ protected function drupalGet($path, array $options = [], array $headers = []) {
     $this->prepareRequest();
     foreach ($headers as $header_name => $header_value) {
       if (is_int($header_name)) {
-        @trigger_error('Passing an integer as header name to ' . __METHOD__ . '() is deprecated in drupal:10.4.0 and will be removed from drupal:12.0.0. Update the calling code to pass the header name as a key. See https://www.drupal.org/node/3456178', E_USER_DEPRECATED);
+        @trigger_error('Passing an integer as header name to ' . __METHOD__ . '() is deprecated in drupal:11.1.0 and will be removed from drupal:12.0.0. Update the calling code to pass the header name as a key. See https://www.drupal.org/node/3456178', E_USER_DEPRECATED);
         [$header_name, $header_value] = explode(':', $header_value);
       }
       if (is_null($header_value)) {
-        @trigger_error('Using null as a header value to ' . __METHOD__ . '() is deprecated in drupal:10.4.0 and will be removed from drupal:12.0.0. Use an empty string instead. See https://www.drupal.org/node/3456233', E_USER_DEPRECATED);
+        @trigger_error('Using null as a header value to ' . __METHOD__ . '() is deprecated in drupal:11.1.0 and will be removed from drupal:12.0.0. Use an empty string instead. See https://www.drupal.org/node/3456233', E_USER_DEPRECATED);
         $header_value = '';
       }
       $session->setRequestHeader($header_name, $header_value);

  • alexpott committed 5ac43624 on 10.3.x
    Issue #3440169 by pooja_sharma, marcoliver, smustgrave, DYdave, alexpott...

  • alexpott committed 72ea6d70 on 10.4.x
    Issue #3440169 by pooja_sharma, marcoliver, smustgrave, DYdave, alexpott...

  • alexpott committed 519cafc4 on 11.0.x
    Issue #3440169 by pooja_sharma, marcoliver, smustgrave, DYdave, alexpott...

  • alexpott committed ebe942c7 on 11.x
    Issue #3440169 by pooja_sharma, marcoliver, smustgrave, DYdave, alexpott...

Status: Fixed » Closed (fixed)

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