Problem/Motivation
In #2336597: Convert path aliases to full featured entities we added a BC layer to kernel tests that removes path_processor_inbound and path_processor_outbound tags from the path_alias.path_processor definition. This is a great source of confusion when writing kernel tests that rely on path aliases.
Steps to reproduce
Write a kernel test as per the MR that boils down to this:
EntityTest::create(['id' => 1])->save();
$this->createPathAlias('/entity_test/1', '/entity-alias');
$entity = EntityTest::load(1);
$this->assertSame('/entity-alias', $entity->toUrl()->toString());
Watch it fail.
Remove this from KernelTestBase::register
if ($container->hasDefinition('path_alias.path_processor')) {
// The alias-based processor requires the path_alias entity schema to be
// installed, so we prevent it from being registered to the path processor
// manager. We do this by removing the tags that the compiler pass looks
// for. This means that the URL generator can safely be used within tests.
$container->getDefinition('path_alias.path_processor')
->clearTag('path_processor_inbound')
->clearTag('path_processor_outbound');
}
Watch it pass.
Proposed resolution
Remove code that disabled path processing, ensure tests that use path alias install its schema.
See #10 for the history.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
mstrelan commentedComment #4
mstrelan commentedComment #5
mstrelan commentedI'm not entirely convinced the BC layer I referred to is in fact for BC, I haven't done enough git archaeology. It seems to me there are a number of kernel tests that are installing path_alias module and just expecting it to work without installing the entity schema. Most of these come from views. Maybe we can fix that up here, let's see what breaks.
Comment #6
mstrelan commentedGuess this might break some contrib tests.
Comment #7
mstrelan commentedComment #8
mstrelan commentedComment #9
acbramley commentedThis would be a great improvement and remove a massive WTF when testing this stuff! Changes overall look great and love the addition of alias test coverage <3
Comment #10
amateescu commentedI did some thorough git archeology and the code block that this issue wants to remove from
KernelTestBase::register()is there since the KernelTestBase class was added to core, #2336597: Convert path aliases to full featured entities just updated the comment inside that condition.Also looked through the history of #3007661: Modernize the path alias system, and figured out that #3084983: Move all the code related to path aliases to a new (required) "path_alias" module and a couple of its followups are the issues that made the current MR possible. Additionally, the changes from this MR should help a lot with #3096092: Make "path_alias" module optional, so +1 on the smaller scope :)
Comment #11
mstrelan commentedComment #12
mstrelan commentedAdded change record
Comment #13
smustgrave commentedAll threads have been resolved and change makes sense.
Only concern is should there be a BC layer as this could break kernel tests in 10.2 right? But not sure since this is the test side.
Comment #14
quietone commentedI'm triaging RTBC issues. I read the IS and the comments here and in the MR. I didn't find any unanswered questions or other work to do.
Of special note is the git research done in #10. I noted that in the Issue Summary.
Leaving at RTBC.
Comment #15
dwwWow, I just stumbled upon this while working on #2418369: Internal URL handling (language prefixes, base://, ...). I couldn't understand what I was doing wrong. 😅 Happy to report that the patch from the MR got my kernel tests doing what I expected again. I'll try to closely review ASAP.
Comment #16
dwwThanks for the git archeology in #10, @amateescu, very helpful!
MR looks great. No complaints. All the changes look good and necessary. +1 to this change!
CR mostly looked great, although I added 1 line to the before example (for outbound path processing, too). No other complaints there.
Summary and title all look good.
I could imagine disruption if there are existing kernel tests in the wild (contrib / custom) that were relying on the broken behavior. But those are broken tests, so I think the disruption is a good idea. Hopefully the release managers agree. 😅
Thanks again!
-Derek
p.s. Crediting @mstrelan for the code, and the rest of us for reviews
.
Comment #19
larowlanCommitted to 11.x
Published change record.
Nice to see this gotcha fixed, I know it has bitten me before.
Comment #21
larowlanSorry folks, I had to revert this - it caused fails in HEAD
https://git.drupalcode.org/project/drupal/-/pipelines/67196/test_report
Comment #22
mstrelan commentedIt seems MigrateBlockTest was cloned to forum module in #3371219: Remove forum from block migration tests
I have applied the same fix to the version in forum that was applied to block.
Comment #24
smustgrave commentedSeems update to MigrateBlockTest is all green.
Comment #26
larowlanCompared the two patches locally and the diff was as expected
Committed to 11.x, republished the change record