Refactor file_download_link Kernel tests

Created on 22 March 2023, almost 2 years ago
Updated 23 March 2023, almost 2 years ago

Problem/Motivation

The Kernel tests are difficult to maintain. I should refactor them.

Steps to reproduce

Proposed resolution

An easy win would be to use data providers. I didn't know about data providers when I wrote these tests way back when.

That might be enough.

Remaining tasks

User interface changes

none

API changes

nope

Data model changes

I don't think so

πŸ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

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

Comments & Activities

  • Issue created by @danflanagan8
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    Here's a patch that refactors the kernel tests AND adds a tiny bit of new test coverage that ends up exposing a bug! Yay! The new test cases are token-less cases for when the token module is enabled. That's where the bug creeps in. Having a data provider makes adding cases soooo much easier.

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    Ah, darnit. My patch included the fix:

    +++ b/src/Plugin/Field/FieldFormatter/FileDownloadLink.php
    @@ -327,8 +328,9 @@ class FileDownloadLink extends FileFormatterBase implements ContainerFactoryPlug
    -        // Next line is important. See https://www.drupal.org/node/2528662.
    -        $bubbleable_metadata->applyTo($elements[$delta]);
    +        // Apply cacheability of tokens to render array.
    +        $bubbleable_metadata->merge(CacheableMetadata::createFromRenderArray($elements[$delta]))
    +          ->applyTo($elements[$delta]);
    

    I was previously overwriting the existing cacheable metadata rather than adding to it. Now it's fixed.

  • Status changed to Fixed almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024