Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables

File : core/modules/file/src/Tests/FileFieldRSSContentTest.php

$field_settings declared 2 times. Might be it replaced by field_storage_settings.

  /**
   * Tests RSS enclosure formatter display for RSS feeds.
   */
  function testFileFieldRSSContent() {
    $node_storage = $this->container->get('entity.manager')->getStorage('node');
    $field_name = strtolower($this->randomMachineName());
    $type_name = 'article';
    $field_settings = array(
      'display_field' => '1',
      'display_default' => '1',
    );
    $field_settings = array(
      'description_field' => '1',
    );
................
................
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

krknth created an issue. See original summary.

krknth’s picture

Status: Active » Needs review
FileSize
633 bytes

Attached patch

krknth’s picture

Assigned: krknth » Unassigned
krknth’s picture

Component: other » file system
krknth’s picture

Assigned: Unassigned » krknth
Status: Needs review » Needs work

These is $field_storage_settings field not $field_settings field. I guess

krknth’s picture

Title: Remove unused local variable $field_settings from core/modules/file/src/Tests/FileFieldRSSContentTest.php » Replace $field_settings by $field_storage_settings from core/modules/file/src/Tests/FileFieldRSSContentTest.php
Issue tags: -Novice, -Less code
FileSize
1.11 KB

New patch attached

Replaced $field_settings by $field_storage_settings

krknth’s picture

Assigned: krknth » Unassigned
Status: Needs work » Needs review
krknth’s picture

Issue summary: View changes
krknth’s picture

Issue tags: +Novice, +Less code
dawehner’s picture

Component: file system » file.module
Status: Needs review » Reviewed & tested by the community

Checked in core/modules/file/config/schema/file.schema.yml:61 that these settings are on the storage level

xjm’s picture

Title: Replace $field_settings by $field_storage_settings from core/modules/file/src/Tests/FileFieldRSSContentTest.php » Remove unneeded settings in core/modules/file/src/Tests/FileFieldRSSContentTest.php
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
FileSize
48.74 KB

Indeed, what's in HEAD is clearly a mistake. Attached screenshot shows these as storage settings in the UI.

The bug where the field settings get overwritten and used for both parameters was introduced after we renamed "field" to "field storage" and "instance" to "field" (which still confuses me to this day), in #2312093: Rename FieldInstanceConfig to FieldConfig. Just a small oops in that patch.

However, I found myself wondering why we were overriding the default settings here if it had no effect. The test was originally added in #666412: Regression: RSS feed enclosure support lost from core, and it appears that it sets display settings just from being copied from FileFieldDisplayTest. Looking at FileFieldTestBase::createFileField(), the last three arguments are optional.

So I think the best fix for this test is actually to completely remove the field, field storage, and widget settings, and just do $this->createFileField($field_name, 'node', $type_name). That will truly be less code. :)

krknth’s picture

Status: Needs work » Needs review
FileSize
1013 bytes
959 bytes

Updated as per @xjm

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Less code it is!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed e01619a and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed ec96369 on 8.1.x
    Issue #2598178 by krknth, xjm: Remove unneeded settings in core/modules/...

  • alexpott committed e01619a on
    Issue #2598178 by krknth, xjm: Remove unneeded settings in core/modules/...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.