Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Similarly to #2034975: Test RDFa output in email formatter and other fields, we need to verify whether the default placement of the RDFa markup on the field wrapper is sufficient for the number field, and we need to add tests.
Proposed resolution
The markup will have to be altered when there is a prefix, suffix, or when there is a thousand separator. The easiest way to know is to check in NumericFormatterBase::viewElements() if the output is different from the value, in which case we will add a content attribute in the same way as the link formatter.
Tests should cover those combinations.
Remaining tasks
patch
User interface changes
none
API changes
none
Comment | File | Size | Author |
---|---|---|---|
#42 | interdiff-2149257-42.txt | 986 bytes | lokapujya |
#42 | 2149257-42.patch | 10.81 KB | lokapujya |
#40 | interdiff-2149257-40.txt | 6.23 KB | lokapujya |
#40 | 2149257-40.patch | 10.84 KB | lokapujya |
#37 | interdiff-2149257-37.txt | 3.09 KB | lokapujya |
Comments
Comment #1
kay_v CreditAttribution: kay_v commentedusing text formatter as pattern...
Comment #2
kay_v CreditAttribution: kay_v commentedLooks like number field formatter is working correctly (see attached screenshot, which uses generic schema:number markup in article content type)
To reproduce in, say the jobposting content type, add mapping to:
sites/files/config_*/active/rdf.mapping.node.[content-type].yml
(replace [content type] above with the name of the content type on which you've added the field)
Example mapping for base salary (add to the bottom of the yml file):
field_number:
properties:
- 'schema:baseSalary'
Comment #3
kay_v CreditAttribution: kay_v commentedtesting just integer for now; needs also to test decimal and float
Comment #5
scor CreditAttribution: scor commentedComment #6
krlucas CreditAttribution: krlucas commentedPrevious patch was missing a closing bracket. Re-rolling.
Comment #7
krlucas CreditAttribution: krlucas commentedAdds tests for decimal and float as well.
Comment #8
krlucas CreditAttribution: krlucas commentedFix comment typos for float and decimal tests.
Comment #9
lokapujya8: 2149257-8-NumberFieldRdfaTest.patch queued for re-testing.
Comment #11
lokapujyaReroll and added testValue to the class. Also had to change the field types (removed 'number_').
Comment #12
scor CreditAttribution: scor commentedWe need to extend the tests to cover the case when there is a prefix or a suffix and also thousand separators. This will also require to add some logic in the viewElements methods, I think we can achieve this by pushing a @content attribute to the field template similar to #2188889: Support RDFa output in link field formatter.
Comment #13
lokapujyaRerolled and added some tests.
Plus added to the test setup because the display needs to be modified for the thousands separator. This part needs more work, and I'll post an interdiff later.
Comment #15
lokapujyaRerolled because getInfo() was removed from tests.
Comment #16
lokapujyaSame as 13, now including the interdiff.
Comment #18
lokapujyaRight now the display value (with prefixes, suffixes, and separator) shows up when viewing a node, but not in the test output.
Comment #19
lokapujyaWe are able to set the display mode settings with what we pass in the $formatter to assertFormatterRdfa(). However, the field instance settings need to be set differently, in the createTestField().
Comment #20
scor CreditAttribution: scor commentedComment #21
lokapujyaA little bit closer. This works and seems to test all the functionality. But the tests can be improved some more still.
Questions:
Would we prefer to have only one field and pass the settings to the base class?
Do we want to separate any of the test cases? Right now the separator, prefix, and suffix are all within one test.
Do we need to test that the content attribute does not show up?
Comment #23
lokapujyaEDIT: This wasn't the new patch.
Comment #25
lokapujyaThis is the version that passes the settings to the base class.
Comment #26
scor CreditAttribution: scor commentedno longer needed I believe, since you fixed the parent class method.
We're doing more than creating a mapping here. I would name this method createTestEntity and take the createTestField() out of it.
$field_settings should be called $field_instance_settings to be more accurate.
Comment #27
lokapujyaChanges from #26.
Comment #28
scor CreditAttribution: scor commentedurl_plain is irrelevant here.
Comment #29
lokapujyaFixed #28 and added some tests for float and integer with settings.
Comment #30
scor CreditAttribution: scor commentedCreates
Comment #31
lokapujyaJust posting this to show how I'm trying to do xpath.
Comment #32
lokapujyaUpdated to use xpath (without using the Drupal assertFieldByXpath() function because it uses getUrl(). See related issue.)
Comment #34
scor CreditAttribution: scor commentedLooks like #32 is only using the xpathContent() on the testFloatFormatter() test, is that intentional? Seems to me we should be using on pretty much all the tests to see whether the @content is there or not. It should be there when we expect the value to differ from the one in the HTML element, and it should check that it's not there when the values are the same, no?
Patch looks great otherwise, I really like how this issue is evolving!
Comment #35
lokapujyaComment #36
scor CreditAttribution: scor commentedLooks good, but I'd rather test for the presence of the content attribute period (regardless of the value is has).
In the positive case, I agree we should test the value of the content attribute. The comment needs to be fixed though, and the same applies to the other instances of the assertTrue() of the content attribute (comment is inaccurate).
Comment #37
lokapujyaGood points.
Added a test for no content attribute when the scale of a float changes.
Comment #38
scor CreditAttribution: scor commentedCould add a comment to give some context: Output the raw value in a content attribute if the text of the HTML element differs from the raw value (for example when a prefix is used)
"Parses"
the testvalue property is already set by the base test class, and we are setting it inside each test method, so I don't think it's needed here at all.
Looks good now, though we no longer use the :testValue in the XPath expression anymore, so it can be removed from the arguments. (same for all other negative tests).
I'm was surprised this passed and that we didn't have a content attribute with the scale setting, but this is because the scale is not exercised. The test value should include more than 5 digits after the ".". In which case there should be a content attribute.
Comment #39
lokapujya5. Scale is not exercised, but zeroes are added and we get no content attribute. Is that ok?
Comment #40
lokapujyaAll 5 points incorporated. Added the new test for a scale that is exercised and left the old one in.
Comment #41
scor CreditAttribution: scor commentedThese 2 if conditions could go on the same line, with the empty() being first. Otherwise the rest looks good.
Comment #42
lokapujyamerged if statements.
Comment #43
scor CreditAttribution: scor commentedThanks Jamie, great work as usual! Probably the most sophisticated field to test!
Comment #45
alexpottCommitted b55880f and pushed to 8.0.x. Thanks!
Fixed on commit.