Updated: Comment #N
Problem/Motivation
#2139551: Support RDFa output in date formatter and #2188877: Support RDFa output in telephone field formatter have identified use cases that where not thought of when first creating assertFormatterRdfa(). When testing field formatters output, we need more than just the field formatter machine name to set up the right field formatter (e.g. we sometimes need the formatter settings like in the case of the telephone test). Additionally, we not only need the expected value and the expected value type (literal or uri), but we also need the datatype in the case of date.
Current signature:
/**
* Helper function to test the formatter's RDFa.
*
* @param string $formatter
* The machine name of the formatter to test.
* @param string $property
* The property that should be found.
* @param string $value
* The expected value of the property.
* @param string $object_type
* The object's type, either 'uri' or 'literal'.
*/
protected function assertFormatterRdfa($formatter, $property, $value, $object_type = 'literal') {
Proposed resolution
/**
* Helper function to test the formatter's RDFa.
*
* @param array $formatter
* An associative array describing the formatter to test and its settings containing:
* - type: The machine name of the field formatter to test.
* - settings: The settings of the field formatter to test.
* @param string $property
* The property that should be found.
* @param array $expected_rdf_value
* An associative array describing the expected value of the property containing:
* - value: The actual value of the string or URI.
* - type: The type of RDF value, e.g. 'literal' for a string, or 'uri. Defaults to 'literal'.
* - datatype: (optional) The datatype of the value (e.g. xsd:dateTime).
*/
protected function assertFormatterRdfa($formatter, $property, $expected_rdf_value) {
$formatter becomes an array. $value is renamed to $expected_rdf_value, and $object_type disappears because it's folded into $expected_rdf_value.
For example, the following line:
$this->assertFormatterRdfa('text_plain', 'http://schema.org/telephone', $this->testValue);
would become:
$this->assertFormatterRdfa(array('type' => 'text_plain'), 'http://schema.org/telephone', array('value' => $this->testValue));
or another equivalent of writing it is:
$formatter = array('type' => 'text_plain');
$expected_rdf_value = array('value' => $this->testValue);
$this->assertFormatterRdfa($formatter, 'http://schema.org/telephone', $expected_rdf_value);
Remaining tasks
write a patch
User interface changes
none
API changes
I don't think that self-contained test helper methods are consider as API changes, given that only the RDF module is using it, and it's very specific to RDFa parsing.
Comment | File | Size | Author |
---|---|---|---|
#24 | 2203065-24.patch | 8.19 KB | chrisfromredfin |
#20 | 2203065-20.patch | 8.19 KB | chrisfromredfin |
#16 | interdiff.txt | 787 bytes | lokapujya |
#16 | 2203065-16.patch | 8.19 KB | lokapujya |
Comments
Comment #1
scor CreditAttribution: scor commentedComment #2
lokapujyaInitial patch for just the formatter change and fixed the tests in \Drupal\rdf\Tests\Field\TextFieldRdfaTest.
Comment #4
lokapujyaFixed the rest of the asserts().
Comment #5
lokapujyaComment #6
lokapujyaUploading progress.
Comment #7
scor CreditAttribution: scor commentedwatch out for the > 80 character lines.
ditto
I would condense this into a one liner:
$expected_rdf_value += array('type' => 'literal');
Comment #8
scor CreditAttribution: scor commentedGood news! #2139551: Support RDFa output in date formatter was committed, so this patch will need to update the tests for date as well (including removing the work-around that was implemented for the datatype in assertFormatterRdfa()).
Comment #9
lokapujyareroll.
Comment #10
lokapujyaApplied suggestions in #7 and modified tests as mentioned in #8.
Comment #11
lokapujyaFixed some whitespace issues.
Comment #13
lokapujyadatatype should be all lower.
Comment #15
scor CreditAttribution: scor commentedThis is good to go except for this minor documentation issue:
missing closing quote on uri.
Comment #16
lokapujyaFixed.
Comment #17
scor CreditAttribution: scor commentedPerfect! thanks Jamie for your work on this patch :)
The following issues are relying on this patch and will get unblocked as soon as it gets committed:
- #2188889: Support RDFa output in link field formatter
- #2188877: Support RDFa output in telephone field formatter
Comment #19
scor CreditAttribution: scor commentedLooks like this will have to be rerolled... there is a conflict in core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php
Comment #20
chrisfromredfinPatch re-rolled. Incorporates new function signature with additional change for term's "getName()" method.
Comment #21
chrisfromredfinneeds review
Comment #22
scor CreditAttribution: scor commentedand back to RTBC.actually I take that back, it no longer applies.Comment #24
chrisfromredfinRe-rolled for latest email field.
Comment #26
scor CreditAttribution: scor commentedback to RTBC while it's green...
Comment #28
scor CreditAttribution: scor commentedThe testbot is having some hiccups. back to RTBC.
Comment #29
scor CreditAttribution: scor commentedbumping to major given that it's blocking 2 other RDF issues: #2188889: Support RDFa output in link field formatter and #2188877: Support RDFa output in telephone field formatter.
Comment #30
catchCommitted/pushed to 8.x, thanks!