Problem/Motivation

In the past, if we wanted to test the behavior of a hook function, then we needed to implement that hook inside of a "test module." Test modules are typically located in core/modules/*/tests/modules/ directories.

#3502432: Make hook testing with kernel tests very simple provided an alternative to creating test modules for Kernel tests. Now hooks may be created as functions directly in Kernel test classes. This reduces the amount of boilerplate necessary for testing hooks, couples the hook function tightly with its related test, and gives us an opportunity to remove some test modules from Core.

The WorkspaceAccessTestHooks class (core/modules/workspaces/tests/modules/workspace_access_test/src/Hook/WorkspaceAccessTestHooks.php) has a hook function that appears to only be used by a Kernel test. Move the hook function into its related test.

See the following for helpful information on making this change:

Proposed resolution

  • Search for the test class or classes that use the workspace_access_test module using any method you prefer, for example grep or an IDE's search.
  • Verify that the hook is only used by one or more Kernel tests. Comment if you believe this is not true.
  • Copy the hook function from the test module into the Kernel test class(es).
  • Delete the hook function. If the Hook class is empty, delete the entire class. If the test module has no other code, delete the entire module.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3581548

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

dcam created an issue. See original summary.

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

amateescu’s picture

Status: Active » Needs review

Since no one picked up this one... :)

dcam’s picture

Status: Needs review » Reviewed & tested by the community

The hook was copied accurately to the Kernel test.

The change from using the state service to keyValue is in line with changes that are happening to Core overall.

The workspace_access_test module has been deleted. I grepped Core for additional instances of the string "workspace_access_test". The only remaining ones are the keyValue set statements.

The test continues to pass after the change.

I don't think there's much else to say about this. LGTM.

  • catch committed 518a9a7a on 11.x
    task: #3581548 Move hooks from workspace_access_test into the Kernel...

  • catch committed 49e355fc on main
    task: #3581548 Move hooks from workspace_access_test into the Kernel...
catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and 11.x, thanks!

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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