Problem/Motivation

EntityResourceTestBase::getUrl() returns a URL, but BrowserTestBase::getUrl() (which the former overrides) returns a string.

Proposed resolution

Rename EntityResourceTestBase::getUrl() to EntityResourceTestBase::getResourceUrl(). To keep them in sync also rename EntityResourceTestBase::getPostUrl() to EntityResourceTestBase::getResourcePostUrl()

CommentFileSizeAuthor
#4 2869415-4.patch7.39 KBwim leers

Comments

tstoeckler created an issue. See original summary.

wim leers’s picture

Title: EntityResourceTestBase::getUrl() overrides BrowserTestBase::getUrl() » EntityResourceTestBase::getUrl() overrides BrowserTestBase::getUrl(), yet offers different functionality
Related issues: +#2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method

Darn — I/we totally missed that in #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method! Great find!

EntityResourceTestBase has:

  1. getUrl() (Gets an entity resource's GET/PATCH/DELETE URL.)
  2. getPostUrl() (Gets an entity resource's POST URL.)

I propose we change this to:

  1. getResourceUrl()
  2. getResourcePostUrl()
tstoeckler’s picture

Issue summary: View changes

Yes, that would make a lot of sense, I think.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new7.39 KB

Hrm, the comment says Gets an entity resource's GET/PATCH/DELETE URL.. It doesn't say resource. It says entity resource.

So, I think this is better:

  1. getEntityResourceUrl()
  2. getEntityResourcePostUrl()
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1 for naming things different if its doing different things.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

I agree the renames make sense. Do contrib test depend on the existing functionality? After all the renames effect protected methods.

dawehner’s picture

@Gábor Hojtsy raised a fair point. Let's keep the old functions around ... at least for BC reasons with some @trigger_error() code.

dawehner’s picture

Status: Needs review » Needs work
wim leers’s picture

Status: Needs work » Reviewed & tested by the community

Quoting https://www.drupal.org/core/d8-bc-policy:

The contents of automated tests provided by core modules are never considered part of the API. While the testing framework itself may be treated as an API individual test classes are always internal.

We're continuously updating (Entity)ResourceTestBase as we improve its test coverage.

Furthermore, 99% of the calls to the affected methods happen in test(Get|Post|Patch|Delete), which are provided by EntityResourceTestBase, which means that 99% of contrib modules' test coverage will not actually be affected.

99% of contrib module tests will look like e.g. \Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase and \Drupal\Tests\rest\Functional\EntityResource\Node\NodeJsonBasicAuthTest: with zero calls to the affected methods!

gábor hojtsy’s picture

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

All right. I asked for second opinions from other committers and the conclusion between @alexpott, @catch and @xjm was that this is a tricky place because it is a method override in a test. So it cannot be marked deprecated because the parent is not deprecated. However it works differently from the parent, which should not have been done in the first place. Also not backporting the change would be tricky because contributed modules would need to somehow be both compatible with the different testing API in 8.3.x and 8.4.x.

So the conclusion was to make this jump and if there are contributed modules who end up being affected, that is expected to be minimal disruption.

Thanks all!

wim leers’s picture

Thanks for your due diligence. I'm glad we arrived at this sane solution :)

And thanks again to @tstoeckler for noticing this in the first place!

Status: Fixed » Closed (fixed)

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