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

Issue fork drupal-3393800

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

Issue summary: View changes

mstrelan’s picture

Issue summary: View changes
mstrelan’s picture

I'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.

mstrelan’s picture

Status: Active » Needs review
Issue tags: +Needs change record

Guess this might break some contrib tests.

mstrelan’s picture

Issue summary: View changes
mstrelan’s picture

Issue summary: View changes
acbramley’s picture

This 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

amateescu’s picture

Status: Needs review » Needs work

I 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 :)

mstrelan’s picture

Status: Needs work » Needs review
mstrelan’s picture

Issue tags: -Needs change record

Added change record

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

All 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.

quietone’s picture

Issue summary: View changes

I'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.

dww’s picture

Wow, 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.

dww’s picture

Issue tags: +Bug Smash Initiative

Thanks 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
.

  • larowlan committed 97bdbe88 on 11.x
    Issue #3393800 by mstrelan, dww, acbramley, amateescu, smustgrave,...

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 11.x

Published change record.

Nice to see this gotcha fixed, I know it has bitten me before.

  • larowlan committed ebdb093f on 11.x
    Revert "Issue #3393800 by mstrelan, dww, acbramley, amateescu,...
larowlan’s picture

Status: Fixed » Needs work

Sorry folks, I had to revert this - it caused fails in HEAD

https://git.drupalcode.org/project/drupal/-/pipelines/67196/test_report

Drupal\Tests\forum\Kernel\Migrate\d6\MigrateBlockTest::testBlockMigration
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mysql.test98741461path_alias' doesn't exist: SELECT 1 AS "expression"
FROM
"test98741461path_alias" "base_table"
WHERE ("base_table"."status" = :db_condition_placeholder_0) AND ("base_table"."path" LIKE :db_condition_placeholder_1 ESCAPE '\\')
LIMIT 1 OFFSET 0; Array
(
    [:db_condition_placeholder_0] => 1
    [:db_condition_placeholder_1] => /admin%
)
mstrelan’s picture

Status: Needs work » Needs review

It 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.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems update to MigrateBlockTest is all green.

  • larowlan committed b3710f94 on 11.x
    Issue #3393800 by mstrelan, smustgrave, dww, larowlan, acbramley,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Compared the two patches locally and the diff was as expected

diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
index d018716c62c..aef056bdccc 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
@@ -30,6 +30,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->installEntitySchema('path_alias');
 
     // Install the themes used for this test.
     $this->installEntitySchema('block_content');

Committed to 11.x, republished the change record

Status: Fixed » Closed (fixed)

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