Support from Acquia helps fund testing for Drupal Acquia logo

Comments

claudiu.cristea’s picture

FileSize
2.39 KB

Here's a test demonstrating this bug. Should be red showing that instance passes but field not.

claudiu.cristea’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2060003-1.patch, failed testing.

yched’s picture

Title: Wrong value for image field getFieldSetting('default_image') » wrong return value for Field::getFieldSetting() when setting appears in both field and instance
Component: image.module » field system
Priority: Normal » Major
Status: Needs work » Needs review
FileSize
1.11 KB
3.09 KB

Indeed, Field::getSetting() looks wrong.
It should first look if the setting is present in the actual settings of the field, then fetch a 'default field-level value', then fetch a 'default instance-level value'.

claudiu.cristea’s picture

Hmm. We should test getFieldSettings() too. Not very sure but as I remember it fails there too.

yched’s picture

Title: wrong return value for Field::getFieldSetting() when setting appears in both field and instance » wrong precedence in Field::getFieldSetting[s]() when setting appears in both field and instance
FileSize
1.58 KB
3.55 KB

Actually, getFieldSettings() will have the same logic issue.
Interdiff is against #1, contains the whole fix.

claudiu.cristea’s picture

Ah! Crossposting :)

Yes, let's add getFieldSettings() to tests too and provide a failure patch also to prove all scenarios.

claudiu.cristea’s picture

Title: wrong precedence in Field::getFieldSetting[s]() when setting appears in both field and instance » Wrong precedence in Field::getFieldSetting[s]() when setting appears in both field and instance
FileSize
5.2 KB
2.74 KB
3.55 KB

Here is an updated test, extend to Field::getFieldSettings().

The patch 2060003-8-fail.patch should be red, 2060003-8-pass.patch green. Interdiff against #1 only for tests.

claudiu.cristea’s picture

FileSize
64 bytes

Removed trailing spaces only from 2060003-8-pass.patch.

claudiu.cristea’s picture

FileSize
5.18 KB

Sorry :)

yched’s picture

Not sure about <code>tags in simpletest messages :-)
The grammar seems a bit off too:
"Article image field instance default equals expected file ID of @fid, returned @returned by FieldInstance::getFieldSetting('default_image')"
-> "Article setting returned by FieldInstance::getFieldSetting(): @returned; expected: @fid" ?

claudiu.cristea’s picture

FileSize
3.28 KB
4.66 KB

OK.

Status: Needs review » Needs work

The last submitted patch, 2060003-12.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.62 KB
5.01 KB

Messed up format_string() arguments :)

claudiu.cristea’s picture

Turned green and looks good. This is blocking #2015697: Convert field type to typed data plugin for file and image modules -- any takers for review and/or rtbc?

Berdir’s picture

+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.phpundefined
@@ -52,7 +52,40 @@ function testDefaultImages() {
+      format_string('Article setting returned by FieldInstance::getFieldSetting(): @returned; expected: @fid.', $args)

I'm not sure how useful these assertion messages are. the expected/returned values are printed by the default output too.

The advantage of leaving it out would be that you could write the assertEqual() arguments on a single line and avoid any arguments about multiline function arguments... ;)

+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.phpundefined
@@ -52,7 +52,40 @@ function testDefaultImages() {
+    // Test also FieldInstance::getFieldSetting().
...
+    // Test also Field::getFieldSettings().

Nitpick: I think this reads more fluent if you write Also test FieldInstance::getFieldSettings(). Not sure if this should use the full namespace.

claudiu.cristea’s picture

FileSize
3.05 KB
4.02 KB

I'm not sure how useful these assertion messages are. the expected/returned values are printed by the default output too.

Yes. Thinking that we'll drop them in the future when moving to phpunit let's drop them here too.

claudiu.cristea’s picture

OK. Turned green :)

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Lovely. I think this is good, test is much more readable like this IMHO.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

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

claudiu.cristea’s picture

Status: Closed (fixed) » Active

IMO, we need to explain somehow what's happen if the filed setting and instance setting share the same name. I expect getFieldSettings() to magically return the right value in the given context. I think we need one of these:

  1. Re-think the fileld vs. instance settings. For example disallow same name to be shared between field and instance?
  2. OR

  3. "Heavy" document the usage of getFieldSettings() to avoid name collision in usage.

Should we open a followup?

EDIT (added): See #2015697-31: Convert field type to typed data plugin for file and image modules for details.

yched’s picture

@claudiu.cristea: OK, I opened #2074217: Reconsider support for field-level & instance-level settings with the same name ? for discussion - and copied over the reasons why I think that is a non-issue ;-)

claudiu.cristea’s picture

Status: Active » Closed (fixed)

Then let's close this.

claudiu.cristea’s picture

Issue summary: View changes

Link to correct issue