Many kernel tests depend on super user status

Created on 10 October 2024, 2 months ago

Problem/Motivation

Many of the module's kernel tests depend on super user logic, as proven by the fact they fail if this is disabled.

It's quite possible that this dependency is unintentional, and so the tests may not be testing what they should. The first user created in any kernel test is a super user, and so passes all access checks, regardless of what permission are specified when creating the user.

Steps to reproduce

Set protected bool $usesSuperUserAccessPolicy = FALSE; in RegistrationKernelTestBase

Observe the following failures:

1) Drupal\Tests\registration_admin_overrides\Kernel\Plugin\Validation\Constraint\RegistrationConstraintTest::testRegistrationConstraintRegression
Failed asserting that 1 matches expected 0.
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:95
/builds/issue/registration-3464498/modules/registration_admin_overrides/tests/src/Kernel/Plugin/Validation/Constraint/RegistrationConstraintTest.php:222
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
2) Drupal\Tests\registration_admin_overrides\Kernel\Plugin\Validation\Constraint\RegistrationConstraintTest::testRegistrationConstraintWithOverrides
Failed asserting that 1 matches expected 0.
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:95
/builds/issue/registration-3464498/modules/registration_admin_overrides/tests/src/Kernel/Plugin/Validation/Constraint/RegistrationConstraintTest.php:291
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
3) Drupal\Tests\registration_waitlist\Kernel\RegistrationWaitListStateTransitionAccessTest::testWaitlistStateTransitionAccess
Failed asserting that false is true.
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56
/builds/issue/registration-3464498/modules/registration_waitlist/tests/src/Kernel/RegistrationWaitListStateTransitionAccessTest.php:141
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
4) Drupal\Tests\registration_workflow\Kernel\RegistrationWorkflowStateTransitionTest::testWorkflowStateTransitions
Failed asserting that an array has the key 'hold'.
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56
/builds/issue/registration-3464498/modules/registration_workflow/tests/src/Kernel/RegistrationWorkflowStateTransitionTest.php:53
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
5) Drupal\Tests\registration\Kernel\Plugin\Field\Formatter\RegistrationHostEntityFormatterTest::testRegistrationHostEntityFormatter
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'My event'
+''
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:95
/builds/issue/registration-3464498/tests/src/Kernel/Plugin/Field/Formatter/RegistrationHostEntityFormatterTest.php:37
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
6) Drupal\Tests\registration\Kernel\Plugin\Field\Formatter\RegistrationIdFormatterTest::testRegistrationIdFormatter
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<a href="/registration/1" hreflang="en">1</a>'
+'1'
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:95
/builds/issue/registration-3464498/tests/src/Kernel/Plugin/Field/Formatter/RegistrationIdFormatterTest.php:31
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
7) Drupal\Tests\registration\Kernel\Plugin\Validation\Constraint\RegistrationConstraintTest::testRegistrationConstraint
Failed asserting that 1 matches expected 0.
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:95
/builds/issue/registration-3464498/tests/src/Kernel/Plugin/Validation/Constraint/RegistrationConstraintTest.php:213
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
8) Drupal\Tests\registration\Kernel\RegistrationManagerTest::testRegistrationManager
Failed asserting that an array has the key 'registration_registrant_type_anon'.
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:56
/builds/issue/registration-3464498/tests/src/Kernel/RegistrationManagerTest.php:93
/builds/issue/registration-3464498/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
FAILURES!

Proposed resolution

Set protected bool $usesSuperUserAccessPolicy = FALSE; in RegistrationKernelTestBase.
Fix test failures.
Test logic is clearer if user permissions are specified explicitly rather than depending on the first user created being the super user.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

3.3

Component

Registration Core

Created by

πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024