Refactor file_download_link Kernel tests

Created on 22 March 2023, over 1 year ago
Updated 23 March 2023, over 1 year 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 over 1 year 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 over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024