It's all in the title.

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

mably created an issue. See original summary.

mably’s picture

Title: Convert all hooks to OOP format » Convert all hooks to OOP format and add tests

  • mably committed 52b08b9d on 2.x
    task: #3574197 Convert all hooks to OOP format and add tests
    
    By: mably
    
mably’s picture

Status: Active » Fixed

OOP hooks conversion

Converted procedural hook implementations to OOP format:

  • Created src/Hook/ReadingProgressBarHooks.php with #[Hook('help')] and #[Hook('theme')] attributes
  • Updated reading_progress_bar.module to delegate to the hook class via #[LegacyHook] for Drupal 10.6 backward compatibility
  • Registered the hook class as a service in reading_progress_bar.services.yml

Test coverage

Added two test files covering the block plugin and rendered output:

Kernel test — ReadingProgressBarBlockTest (4 tests)

Tests the block plugin in isolation via plugin.manager.block:

  • testDefaultConfiguration — Verifies all 8 default config values match ReadingProgressBarConstants
  • testBlockForm — Asserts form structure: field #types (textfield, color, checkbox, number), #default_values, and #states visibility rule on the background_color field
  • testBlockSubmit — Sets custom values via FormState, calls blockSubmit(), asserts getConfiguration() reflects submitted values
  • testBuildWithDefaultConfig — Asserts render array structure: #theme, #attached library, Attribute object with classes (reading-progress-bar, hidden), aria-hidden, data attributes, and inline CSS with transparent background

Functional test — ReadingProgressBarTest (3 tests)

Full browser tests for block rendering and configuration:

  • testBlockRendering — Visits front page, asserts rendered <progress> element with correct CSS classes, aria-hidden, value="0", data attributes, and inline CSS variables in sibling <style> tag
  • testBlockConfigurationForm — Submits custom values via the block config UI, revisits and asserts all saved values persist
  • testBlockRenderingWithCustomConfig — Saves custom config (including non-transparent background) via UI, visits front page, asserts custom CSS values and data attributes in rendered output

No overlap between the two files — kernel tests cover the plugin API/render array level, functional tests cover the browser/HTML rendering level.

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.