Reduce dependency on block.module in tests

Created on 16 May 2025, 17 days ago

Problem/Motivation

Theres quite a lot of use of the \Drupal\Tests\BrowserTestBase::drupalPlaceBlock from \Drupal\Tests\block\Traits\BlockCreationTrait in tests. Each use of this method requires the block.module to be installed, along with Block config, its associated schema. Bringing in block.module cause the \Drupal\block\Plugin\DisplayVariant\BlockPageVariant display variant to engage.

There are many usages of drupalPlaceBlock with typical navigation blocks such as:

  • \Drupal\Core\Block\Plugin\Block\PageTitleBlock page_title_block
  • \Drupal\Core\Menu\Plugin\Block\LocalTasksBlock local_tasks_block
  • \Drupal\Core\Menu\Plugin\Block\LocalActionsBlock local_actions_block
  • \Drupal\system\Plugin\Block\SystemBreadcrumbBlock system_breadcrumb_block

Each of which is either defined in core, or uses services fundamentally defined by core.

It would make sense to reduce the dependency on block.module, in tests which do not have a dependency on the specific rendering of BlockPageVariant and specifically \Drupal\block\Entity\Block configuration entities.

Proposed resolution

We're able to implement a simple test module in core implementing a variant which programmatically outputs the typical build/render-arrays of the above navigation blocks.

Doing this will remove the dependency on Block, so there's less to go wrong, less setup, and potential performance improvements.

Remaining tasks

Discuss, implement.

User interface changes

None.

Introduced terminology

None.

API changes

New module.
Tweaks to tests, which may break tests extending core tests. (not covered by BC?)

Data model changes

None.

Release notes snippet

Maybe.

📌 Task
Status

Active

Version

11.0 🔥

Component

phpunit

Created by

🇦🇺Australia dpi Perth, Australia

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

Comments & Activities

Production build 0.71.5 2024