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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scor’s picture

Issue summary: View changes
lokapujya’s picture

Status: Active » Needs review
FileSize
3.55 KB

Initial patch for just the formatter change and fixed the tests in \Drupal\rdf\Tests\Field\TextFieldRdfaTest.

Status: Needs review » Needs work

The last submitted patch, 2: 2203065-2.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
6.65 KB

Fixed the rest of the asserts().

lokapujya’s picture

Title: Ajust assertFormatterRdfa() parameters to allow for more advanced testing » Adjust assertFormatterRdfa() parameters to allow for more advanced testing
lokapujya’s picture

FileSize
7.24 KB
6.97 KB

Uploading progress.

scor’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php
    @@ -58,30 +58,31 @@ public function setUp() {
    +   *   An associative array describing the formatter to test and its settings containing:
    

    watch out for the > 80 character lines.

  2. +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php
    @@ -58,30 +58,31 @@ public function setUp() {
    +   * @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).
    

    ditto

  3. +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php
    @@ -58,30 +58,31 @@ public function setUp() {
    +    $defaultOptions = array('type' => 'literal');
    +    $expected_rdf_value = array_merge($defaultOptions, $expected_rdf_value);
    

    I would condense this into a one liner:
    $expected_rdf_value += array('type' => 'literal');

scor’s picture

Good 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()).

lokapujya’s picture

FileSize
7.4 KB

reroll.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
8.19 KB
2.72 KB

Applied suggestions in #7 and modified tests as mentioned in #8.

lokapujya’s picture

FileSize
8.19 KB

Fixed some whitespace issues.

The last submitted patch, 10: 2203065-10.patch, failed testing.

lokapujya’s picture

FileSize
8.19 KB

datatype should be all lower.

The last submitted patch, 11: 2203065-11.patch, failed testing.

scor’s picture

Status: Needs review » Needs work

This is good to go except for this minor documentation issue:

+++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php
@@ -58,34 +58,33 @@ public function setUp() {
+   *   - type: The type of RDF value, e.g. 'literal' for a string, or 'uri.

missing closing quote on uri.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
8.19 KB
787 bytes

Fixed.

scor’s picture

Status: Needs review » Reviewed & tested by the community

Perfect! 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

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2203065-16.patch, failed testing.

scor’s picture

Looks like this will have to be rerolled... there is a conflict in core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php

chrisfromredfin’s picture

FileSize
8.19 KB

Patch re-rolled. Incorporates new function signature with additional change for term's "getName()" method.

chrisfromredfin’s picture

Status: Needs work » Needs review

needs review

scor’s picture

and back to RTBC. actually I take that back, it no longer applies.

Status: Needs review » Needs work

The last submitted patch, 20: 2203065-20.patch, failed testing.

chrisfromredfin’s picture

Status: Needs work » Needs review
FileSize
8.19 KB

Re-rolled for latest email field.

Status: Needs review » Needs work

The last submitted patch, 24: 2203065-24.patch, failed testing.

scor’s picture

Status: Needs work » Reviewed & tested by the community

back to RTBC while it's green...

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2203065-24.patch, failed testing.

scor’s picture

Status: Needs work » Reviewed & tested by the community

The testbot is having some hiccups. back to RTBC.

scor’s picture

Priority: Normal » Major
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit afd8aee on 8.x by catch:
    Issue #2203065 by lokapujya, cwells: Adjust assertFormatterRdfa()...

Status: Fixed » Closed (fixed)

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