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
Comments
Comment #3
shayaanmiyy commentedComment #5
shayaanmiyy commentedThe 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.
Comment #6
smustgrave commentedInstead 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.
Comment #7
joachim commented> 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'),
Comment #8
smustgrave commentedEh will leave for others maybe this just needs to be refactored to not rely on user or node
Comment #9
joachim commentedI 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.' !!!)
Comment #10
mstrelan commentedIf we're going with this approach of installing the modules in the base class then we should remove the
$modulesproperty from the child classes.Comment #11
lostcarpark commentedThe 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.
Comment #12
michael.j.gleeson commentedWe are attempting to solve this at first time contrib day
@michael.j.gleeson, @jberghammer and @manuel-ranzmeir and @lostcarpark mentoring
Comment #13
michael.j.gleeson commentedRemoved user and node dependency from child test files:
Has warnings with PHP unit tests for PHP 8.5, but not relevant to change.
@antojose and @lostcarpark helped.
Comment #14
lostcarpark commentedI 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.
Comment #15
xjmI 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!
Comment #16
xjmThe diff is not applying, so I attempted a rebase through the UI.
Comment #17
xjmI 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!
Comment #18
xjmComment #19
xjmCreated the followup: #3553195: PluginTestBase is not actually a "base class for plugin API unit tests"
Comment #20
xjmComment #22
xjmCommitted 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!
Comment #25
lostcarpark commentedYes, 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.