Problem/Motivation

Follow-up for #2575869-70: Remove all remaining usage of deprecated UrlGeneratorInterface::generateFromPath() and delete it.

+++ b/core/modules/simpletest/src/BrowserTestBase.php
@@ -412,7 +412,7 @@ protected function drupalGet($path, array $options = array()) {
+        $url = Url::fromUri('base:/' . $path, $options)->toString();
+++ b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
@@ -34,7 +34,7 @@ public function testGoTo() {
-    $this->drupalGet('/test-page');


@@ -46,7 +46,7 @@ public function testGoTo() {
-    $this->drupalGet('/form-test/object-builder');

@larowlan:

Instead of changing the ->drupalGet calls, could we just use ltrim($path, '/') in drupalGet method

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JeroenT created an issue. See original summary.

JeroenT’s picture

JeroenT’s picture

Title: Followup for #2575869. ltrim($path, '/') in drupalGet method » Add ltrim($path, '/') in drupalGet method
Issue summary: View changes
JeroenT’s picture

Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
Status: Active » Needs review
FileSize
552 bytes

Patch uploaded contains ltrim in drupalGet() and tested. Please review and post feedback.

Thanks

Status: Needs review » Needs work

The last submitted patch, 10: add_ltrim_path-2581557-10.patch, failed testing. View results

dawehner’s picture

I like the general idea, one less thing to worry about.

Note: the failures are caused by you calling ltrim to $url if url is an object, see the error message:

ltrim() expects parameter 1 to be string, object given
sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
mxh’s picture

Status: Needs work » Needs review
FileSize
753 bytes

Patch from #10 would break Url::isExternal in case a string path starting with // is given. Moving this part into buildUrl() method.

dawehner’s picture

@mxh
Please try to avoid taking over someone's issue when they assigned themselves a short time ago. We all want to avoid redundant work, don't we?

sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
mxh’s picture

Sorry, I have overlooked the fixed assignment.

dawehner’s picture

Issue tags: +Needs tests

No worries :)

Patch from #10 would break Url::isExternal in case a string path starting with // is given. Moving this part into buildUrl() method.

Nice catch!

Do you think we can add some little test which calls explicitely with a starting slash?

mxh’s picture

This one might fail as I'm currently unable to have an environment which executes the test. Not sure whether this is sufficient / at the right place as well.

mxh’s picture

Argh, wrong assert.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

That's some serious amount of test coverage. Thank you!

xjm’s picture

Great work on the tests!

I've uploaded a test-only patch, which should presumably fail on the leading slash case in HEAD? In general it's always a good idea to provide a test-only patch along with the fix.

dawehner’s picture

Let's make it actually fail

mxh’s picture

The added test testBuildUrl() should also presumably fail in case add_ltrim_path-2581557-10.patch has been applied.

xjm’s picture

Ha, #fail indeed xjm. :P

xjm’s picture

Status: Reviewed & tested by the community » Needs review

So, it didn't fail.

Is this change still needed? The issue was filed as a followup before release.

dawehner’s picture

I could easily imagine that this works on BrowserTestBase but maybe not on WebTestBase?

mxh’s picture

I don't know why the test isn't actually covering the change being made in add_ltrim_path-2581557-20.patch.

mxh’s picture

I'm wondering, whether this part

<?php
$uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
?>

shouldn't include the slash at the end, i.e. it should be instead

<?php
$uri = $path === '<front>' ? 'base:/' : 'base:' . ltrim($path, '/');
?>

or another possible alternative:

<?php
$uri = $path === '<front>' ? 'base:/' : 'base:' . $path;
?>

What do you think?

It's also possible that it's actually not needed anymore. It seems test implementations don't struggle with this since release, so we could close this issue and reopen it in case there is an explicit need for it? Could still add the tests though.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

It's also possible that it's actually not needed anymore. It seems test implementations don't struggle with this since release, so we could close this issue and reopen it in case there is an explicit need for it? Could still add the tests though.

I'm inclined to agree with this and rescope this issue to just add the additional testcoverage.

dawehner’s picture

@borisson_
Sure, let's do that.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, more tests! Great work @dawehner. Thanks so much for picking this up.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -67,6 +67,18 @@ public function testGoTo() {
+  public function testDrupalGet() {
+    $this->drupalGet('test-page');
+    $this->assertSession()->statusCodeEquals(200);
+    $this->drupalGet('/test-page');
+    $this->assertSession()->statusCodeEquals(200);
+    $this->drupalGet('/test-page/');
+    $this->assertSession()->statusCodeEquals(200);
+  }

Is the URL going to be normalised? Should we add a $this->assertUrl() for each case too?

dawehner’s picture

It doesn't do normalisation, which is reflected in the interdiff.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @dawehner.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Credited @JeroenT for creating the issue.

Committed and pushed 9e9ee75ba4 to 8.6.x and 83ab546116 to 8.5.x. Thanks!

  • alexpott committed 9e9ee75 on 8.6.x
    Issue #2581557 by dawehner, mxh, xjm, sorabh.v6, JeroenT: Add ltrim($...

  • alexpott committed 83ab546 on 8.5.x
    Issue #2581557 by dawehner, mxh, xjm, sorabh.v6, JeroenT: Add ltrim($...

Status: Fixed » Closed (fixed)

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