Problem/Motivation
\Drupal\Tests\Core\Entity\EntityUrlTest is currently structured in a way that is hard to extend it and hard to provide coverage for link templates other than edit-form.
Note: All method references below refer to methods of \Drupal\Core\Entity\Entity.
This is problematic because there are a number of issues that want to expand the test coverage of entity URL handling:
- #2751835: Entity::urlRouteParameters() is broken for add-page and add-form link templates
- #2542834-45: Menu item translation : breadcrumb displays (twice) "add" that have no sense
- #2751583: Entity::urlRouteParameters() calls getRevisionId() for non-revisionable entities
Proposed resolution
This issue turns it into a proper unit test with 100% code coverage of ::toUrl(), ::urlRouteParmeters(), ::linkTemplates(), ::urlInfo(), ::url(), and ::hasLinkTemplate().
It does thorough "blackbox" testing of ::toUrl() (and by extension ::urlRouteParmeters() and ::linkTemplates()). To test ::urlInfo() and ::url() (and by extension ::hasLinkTemplate()), which are (deprecated) wrappers of ::toUrl(), it mocks ::toUrl() itself, and tests that the calls are properly wired up.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 2751395-12-entity-url-test.patch | 28.97 KB | tstoeckler |
Comments
Comment #2
tstoecklerHere we go.
Comment #3
tstoecklerComment #4
tstoecklerComment #5
tstoecklerComment #6
tstoecklerComment #7
tstoecklerComment #8
dawehnerIt is amazing how much more readable your new tests are. On top of that it adds test coverage and provides the points you outlined in the issue summary.
Here are just a few small remarks
Note: Since https://thephp.cc/news/2016/02/questioning-phpunit-best-practices the annotation seems not longer be the right way to use here
One tricky I learned recently from someone: Not use TRUE/FALSE in providers but rather simply introduce named constants like
static::DEFAULT_REVISIONandstatic::NON_DEFAULT_REVISIONto improve readability. What do you think about it?Is there a reason you didn't included the language into the assertUrl method? It seems to just make sense to add it as an additional optional parameter at the end. Many of the great test methods you wrote use it now.
Comment #9
tstoecklerComment #10
tstoecklerThanks for the great review!
1. Done, yeah I hope @expectedException dies a
slowfast! and horrible death.2. I've never heard of that, but I love it. Done. Note that I used
@var trueand@var falseinstead of@var boolfor the docs because that is consistent with our usage of@param \Some\Object|falseelsewhere.3. Great point! Done. This actually increased test coverage a little bit, because we now assert the language option in the URI callback case.
Comment #12
tstoecklerSorry that was pure laziness/arrogance on my part of not running the test locally. :-/
Comment #13
dawehnerDon't you feel bad about the global climate change caused by that ?
Comment #14
alexpottCommitted c244dc4 and pushed to 8.1.x and 8.2.x. Thanks!