Improve test coverage for BlockTemplateSuggestionsUnitTest

Created on 27 December 2012, over 12 years ago
Updated 25 August 2025, 25 days ago

Posted by xjm

Problem/Motivation

This is a followup issue for #1535868: Convert all blocks into plugins β†’ .

  • BlockTemplateSuggestionsUnitTest tests the case where a block ID includes one hyphen and one colon, but not any other cases.
  • The test has been converted from UnitTestBase to WebTestBase.
  • Some prior test coverage is being removed:
    
    +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.phpundefined
    @@ -26,31 +33,23 @@ public static function getInfo() {
    -    // Define block delta with underscore to be preprocessed
    -    $block1 = new stdClass();
    -    $block1->module = 'block';
    -    $block1->delta = 'underscore_test';
    -    $block1->region = 'footer';
    -    $variables1 = array();
    -    $variables1['elements']['#block'] = $block1;
    -    $variables1['elements']['#children'] = '';
    -    template_preprocess_block($variables1);
    -    $this->assertEqual($variables1['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__underscore_test'), 'Found expected block suggestions for delta with underscore');
    -
    -    // Define block delta with hyphens to be preprocessed. Hyphens should be
    -    // replaced with underscores.
    -    $block2 = new stdClass();
    -    $block2->module = 'block';
    -    $block2->delta = 'hyphen-test';
    -    $block2->region = 'footer';
    -    $variables2 = array();
    -    $variables2['elements']['#block'] = $block2;
    -    $variables2['elements']['#children'] = '';
    ...
    -    $variables2['content_attributes']['class'][] = 'test-class';
    -    template_preprocess_block($variables2);
    -    $this->assertEqual($variables2['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__hyphen_test'), 'Hyphens (-) in block delta were replaced by underscore (_)');
    -    // Test that the default class and added class are available.
    -    $this->assertEqual($variables2['content_attributes']['class'], array('test-class', 'content'), 'Default .content class added to block content_attributes_array');
    +    $variables['content_attributes']['class'][] = 'test-class';
    +    template_preprocess_block($variables);
    +    $this->assertEqual($variables['theme_hook_suggestions'], array('block__footer', 'block__system', 'block__system_menu_block', 'block__system_menu_block__menu_admin'));
    +    $this->assertEqual($variables['content_attributes']['class'], array('test-class', 'content'), 'Default .content class added to block content_attributes_array');
    

Proposed resolution

  • Add test coverage for more template name variations, including for multiple derivatives.
  • Use DrupalUnitTestBase if possible.
  • Clarify the inline documentation for testBlockThemeHookSuggestions().
  • Add back the equivalents of the removed assertions.

Remaining tasks

Related issues

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

block.module

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024