Problem/Motivation

Using this as a parent class for tests gets this error:

> Drupal\Component\Plugin\Exception\PluginNotFoundException: The "user" entity type does not exist.

Probably due to things like this:

      'user_name' => [
        'id' => 'user_name',
        'label' => 'User name',
        'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock',
        'context_definitions' => [
          'user' => EntityContextDefinition::fromEntityTypeId('user')->setLabel('User'),
        ],
      ],

Steps to reproduce

Proposed resolution

Add user module to the class's module dependencies.

I'm not sure if the user entity schema needs to be installed too.

Remaining tasks

  • Find classes deriving from PluginTestBase
  • Remove "user" module from dependencies
  • Needs Review

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3546496

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

joachim created an issue. See original summary.

vinaygawade made their first commit to this issue’s fork.

shayaanmiyy’s picture

Assigned: Unassigned » shayaanmiyy

shayaanmiyy’s picture

Assigned: shayaanmiyy » Unassigned
Issue summary: View changes
Status: Active » Needs review

The issue occurs because PluginTestBase uses plugins that depend on the user and node entity types, but these modules were not declared in $modules. Adding 'user' and 'node' to the $modules array fixes the PluginNotFoundException and allows all kernel tests to pass.

smustgrave’s picture

Status: Needs review » Needs work

Instead of adding to the pluginTestBase think user should be added as a dependency to the test module calling it plugin_test. Not sure if we need node.

joachim’s picture

Status: Needs work » Needs review

> ser should be added as a dependency to the test module calling it plugin_test

That won't work -- kernel tests don't install module dependencies.

We need node because:

> 'node' => EntityContextDefinition::fromEntityTypeId('node')->setLabel('Node'),

smustgrave’s picture

Eh will leave for others maybe this just needs to be refactored to not rely on user or node

joachim’s picture

Status: Needs review » Reviewed & tested by the community

I think the problem is rather than it's not actually a test base class -- the name is misleading and should be changed.

Only 3 test classes inherit from it, and it's to do with testing things that core modules do. Therefore the dependencies on user and node are fine.

So I'd say we fix this, and then file a follow-up to rename the class to something clearer and fix its misleading docs too (' * Base class for Plugin API unit tests.' !!!)

mstrelan’s picture

Status: Reviewed & tested by the community » Needs work

If we're going with this approach of installing the modules in the base class then we should remove the $modules property from the child classes.

lostcarpark’s picture

Issue summary: View changes
Issue tags: +Vienna2025

The Drupal Contribution Mentoring team is triaging issues for DrupalCon Vienna 2025, and we are reserving this issue for Mentored Contribution during the event.

After October 17, this issue returns to being open to all. Thanks!

I performed Novice Triage on this issue. I am leaving the Novice tag on this issue because removing user module as dependency of child classes is a straightforward novice task.

michael.j.gleeson’s picture

We are attempting to solve this at first time contrib day
@michael.j.gleeson, @jberghammer and @manuel-ranzmeir and @lostcarpark mentoring

michael.j.gleeson’s picture

Status: Needs work » Needs review

Removed user and node dependency from child test files:

  • core/tests/Drupal/KernelTests/Core/Plugin/DerivativeTest.php
  • core/tests/Drupal/KernelTests/Core/Plugin/FactoryTest.php
  • core/tests/Drupal/KernelTests/Core/Plugin/InspectionTest.php

Has warnings with PHP unit tests for PHP 8.5, but not relevant to change.

@antojose and @lostcarpark helped.

lostcarpark’s picture

Status: Needs review » Reviewed & tested by the community

I have reviewed this change, and I believe it has been carried out according to Drupal coding standards.

I have verified the tests pass with this change.

As the change is exclusively to test code, I don't believe manual testing is relevant here.

I'm moving to RTBC.

xjm’s picture

I checked the base class and confirmed that it does indeed have secret dependencies on both Node and User. I also confirmed that the three tests updated in the patch are its only descendents. Nice find!

xjm’s picture

The diff is not applying, so I attempted a rebase through the UI.

xjm’s picture

I think @ranzinator2000 is the d.o username for @manuel-ranzmeir and have updated the contribution record accordingly. Please let me know if this is not correct!

xjm’s picture

Issue tags: +Needs followup
xjm’s picture

Issue tags: -Needs followup

  • xjm committed ac972449 on 11.x
    Issue #3546496 by joachim, shayaanmiyy, mstrelan, lostcarpark, michael.j...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 11.x, and cherry-picked to 11.2.x as a patch-safe test bug fix. Thanks everyone, and thanks for participating in the DrupalCon Vienna contribution sprint!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

lostcarpark’s picture

I think @ranzinator2000 is the d.o username for @manuel-ranzmeir and have updated the contribution record accordingly. Please let me know if this is not correct!

Yes, that's correct. I think one of my learnings from this contribution day is to get each person helping with an issue to post a comment, rather than one comment with all the usernames.

  • xjm committed d915b612 on 11.2.x
    Issue #3546496 by joachim, shayaanmiyy, mstrelan, lostcarpark, michael.j...

Status: Fixed » Closed (fixed)

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