From #2335661-114: Outbound path & route processors must specify cacheability metadata.8:

+++ b/core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php
@@ -154,3 +275,13 @@ public function providerTestDomain() {
+namespace {
+  if (!function_exists('base_path')) {
+    function base_path() {
+      return '/';
+    }
+  }
+}

Do you mind opening up a follow up to replace that usage of base_path()? It would be ne of the last ones ...

Comments

joshi.rohit100’s picture

Unable to find base_path() in LanguageNegotiationUrlTest. Looks like its already fixed.

wim leers’s picture

The usage is not in the test, but in the code itself.

afedoruk’s picture

Status: Active » Needs review
StatusFileSize
new845 bytes

Status: Needs review » Needs work

The last submitted patch, 3: remove_LanguageNegotiationUrl_base_path_2481833_3.patch, failed testing.

afedoruk’s picture

I'm a novice and I'm not sure what should I do if test passes on my local installation but fails during d.o test.

BTW, failed LanguageUILanguageNegotiationTest itself uses base_path()

dileepmaurya’s picture

replaced rtrim(base_path(), '/'); with $request->getBasePath();

dileepmaurya’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: remove_LanguageNegotiationUrl_base_path_2481833_6.patch, failed testing.

wim leers’s picture

It may be passing locally because it only works for sites installed in the root (i.e. http://example.com/), not in a subdirectory (i.e. http://example.com/subdir/).

These tests can indeed be tricky/frustrating to get right. Don't let yourself become demotivated!

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new845 bytes

hi,
hopefully this one passes :)

Status: Needs review » Needs work

The last submitted patch, 10: remove_LanguageNegotiationUrl_base_path_2481833_10.patch, failed testing.

izus’s picture

What about this !

izus’s picture

Status: Needs work » Needs review
cilefen’s picture

Status: Needs review » Needs work

The last submitted patch, 12: remove_LanguageNegotiationUrl_base_path_2481833_12.patch, failed testing.

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new845 bytes

Status: Needs review » Needs work

The last submitted patch, 16: remove_LanguageNegotiationUrl_base_path_2481833_16.patch, failed testing.

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new842 bytes

don't give up !

Status: Needs review » Needs work

The last submitted patch, 18: remove_LanguageNegotiationUrl_base_path_2481833_18.patch, failed testing.

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new844 bytes

Status: Needs review » Needs work

The last submitted patch, 20: remove_LanguageNegotiationUrl_base_path_2481833_20.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: remove_LanguageNegotiationUrl_base_path_2481833_20.patch, failed testing.

The last submitted patch, 16: remove_LanguageNegotiationUrl_base_path_2481833_16.patch, failed testing.

izus’s picture

#16 seems to make it but there is something wrong with the "// Test HTTPS via current URL scheme." in Drupal\language\Tests\LanguageUILanguageNegotiationTest
that's the only failing test

neetu morwani’s picture

Assigned: Unassigned » neetu morwani
Issue tags: +Needs reroll

Last Patch does not apply anymore.

neetu morwani’s picture

Assigned: neetu morwani » Unassigned
Status: Needs work » Needs review
StatusFileSize
new768 bytes
neetu morwani’s picture

Issue tags: -Needs reroll
plach’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Something went wrong with reroll, the patch contains only an empty line now.

joshi.rohit100’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new846 bytes

Status: Needs review » Needs work

The last submitted patch, 31: 2481833-31.patch, failed testing.

borisson_’s picture

StatusFileSize
new867 bytes
new1.67 KB

The failure in the tests can be traced back to the Request::create in LanguageUILanguageNegotiationTest::testLanguageDomain.

This only happens when running drupal from a sub-folder (something like http://example.com/drupal/), as far as I can see this is because the request::getBaseUrl method can't correctly generate a base url in Request::prepareBaseUrl.
I'm assuming the best way to fix this is to change the Request::create code to include one (or more) of the needed server variables (SCRIPT_NAME, SCRIPT_FILENAME, PHP_SELF) to make sure that the base url is getting returned correctly.

I can't seem to figure out what combination of those variables should work though.

Attached patch does remove the base_path function from the test. The LanguageNegotiationUrlTest still passes without this.

znerol’s picture

Maybe take a look at #2529170: [PP-1] Remove DrupalKernel::initializeRequestGlobals and replace base_root, base_url and base_path with a service, but I'm not sure whether the changes over there are isolatable and portable to this issue.

znerol’s picture

+++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
@@ -183,7 +183,7 @@ public function processOutbound($path, &$options = array(), Request $request = N
-        $options['base_url'] .= rtrim(base_path(), '/');
+        $options['base_url'] .= rtrim($request->getBaseUrl(), '/');

Two problems here.

The first one: Use getBasePath() (not getBaseUrl()). Also the Symfony version does not add a slash, therefore I expect the rtrim to be superflous.

The second one: $request->getBaseXXX() is always relative to the front controller (i.e. index.php). If this is executed from within a nested front controller (e.g. core/authorize.php), then /core is appended to the base path to the drupal root. This is what the other issue is trying to resolve.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.69 KB
new2.52 KB

Using getBasePath() over getBaseUrl() doesn't make a difference.
In the testing I've done, the request come from /index.php as front controller, so the change in the other issue doesn't seem relevant here.

I've added a patch that uses the getBasePath() and introduces 2 new debug statements so it's clearer what the actual problem is. The tests will still fail with the attached patch.

Status: Needs review » Needs work

The last submitted patch, 36: remove-2481833-36.patch, failed testing.

dcmul queued 31: 2481833-31.patch for re-testing.

The last submitted patch, 31: 2481833-31.patch, failed testing.

borisson_’s picture

Status: Postponed » Closed (duplicate)
tr’s picture

Version: 8.0.x-dev » 9.2.x-dev
Status: Closed (duplicate) » Active
Issue tags: -

No, the problem in this issue is NOT fixed by the patch in #2529170: [PP-1] Remove DrupalKernel::initializeRequestGlobals and replace base_root, base_url and base_path with a service. Maybe it should be, but none of the above information was posted to that other issue so the existing patch in that issue doesn't even try to remove base_path() from the unit test. Closing this issue just hides the problem and assures it won't be fixed.

This remains a valid, unaccomplished task that still needs to be addressed. If you think that #2529170: [PP-1] Remove DrupalKernel::initializeRequestGlobals and replace base_root, base_url and base_path with a service should handle this problem, then this information needs to be added to that issue and the patch in that issue needs to be re-rolled to include the changes from #36 above.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Active » Closed (duplicate)
Issue tags: -Novice

I just read the MR over in #2529170: [PP-1] Remove DrupalKernel::initializeRequestGlobals and replace base_root, base_url and base_path with a service and it now includes updating the Unit test. I am closing this as a duplicate and transferring credit.