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 telephone field, and we need to add tests.

Proposed resolution

Try the telephone field to see what markup is generated. Add a test.

Remaining tasks

User interface changes

none

API changes

none

Comments

lokapujya’s picture

Assigned: Unassigned » lokapujya
Status: Active » Needs review
StatusFileSize
new1.87 KB

Basic implementation of telephone field formatter test. Working with Kay @rdfcodesprint.

lokapujya’s picture

For manual testing, the field mapping needs to be created manually by editing the rdf.mapping.node.[content type].yml file by copying a field mapping (last 3 lines of the file) and changing the schema.

scor’s picture

We should step down in the telephone field formatter because the value of the link can be changed in the field formatter settings, here is an example:

<div data-edit-field-id="node/1/field_tel/en/full" class="field field-node--field-tel field-name-field-tel field-type-telephone field-label-above edit-processed edit-field">
  <div class="field-label">tel</div>
  <div class="field-items">
    <div class="field-item" property="schema:telephone">
      <a href="tel:90880398434">Call me maybe</a>
    </div>
  </div>
</div>

In this case, if you paste this markup in the RDFa play tool and look at the raw data tab, you will see that the string "Call me maybe" is extracted, not the telephone value. This is because RDFa parsing will extract the text inside the div element. This is easy to solve by placing the property attribute in the a element. This is similar to how taxonomy's LinkFormatter.php does it.

lokapujya’s picture

StatusFileSize
new4.27 KB
new954 bytes

Combined the asserts into one test.

lokapujya’s picture

This code handles the issue scor mentioned in #3:

      if (!empty($item->_attributes)) {
        $element[$delta]['#options'] += array('attributes' => array());
        $element[$delta]['#options']['attributes'] += $item->_attributes;
        // Unset field item attributes since they have been included in the
        // formatter output and should not be rendered in the field template.
        unset($item->_attributes);
      }

We still need a test for this.

lokapujya’s picture

Status: Needs review » Needs work
StatusFileSize
new5.34 KB
new1.08 KB
lokapujya’s picture

I need to fix the last patch, since some of the email formatter code got mixed in.

Also, I'm reading this issue: #1778122: Enable modules to inject attributes into field formatters, so that RDF attributes get output to better understand how to set up the test the attributes issue from comment #3.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new2.91 KB

Fixed up the patch.

I think we need a test that asserts that rdf reads the number from the href and not the value from the div ("Call me maybe.") I am not sure how we would set the title for the telephone field in a test. I think it can be done in the entity_create() or by setting $this->entity->{$this->fieldName}->title?

    // Set up test values.
    $this->testValue = '555-555-5555';
    $this->entity = entity_create('entity_test', array());
    $this->entity->{$this->fieldName}->value = $this->testValue;

Status: Needs review » Needs work

The last submitted patch, 9: 2188877-9.patch, failed testing.

scor’s picture

The test failed because now that we've moved the property attribute inside the a HTML element, we're extracting a link in the RDFa. The expected value (which will need to be adjusted) is the content of the href attribute (tel:123) and the 4th argument of assertFormatterRdfa() will have to be set to 'uri' (the default is literal aka string).

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new787 bytes
new2.93 KB

Implemented the suggestion in #11.

scor’s picture

Here is an example similar to what we have to do (taken from another test in core):

    entity_get_display('entity_test', 'entity_test', 'default')
      ->setComponent($field_name, array(
        'label' => 'above',
        'type' => $formatter_type,
        'settings' => $formatter_settings
      ))
      ->save();

Here I believe we just need to set $formatter_settings to be something like array('title' => 'Contact us'). Since we need to be able to do that we will have to change the signature of assertFormatterRdfa so that formatter is not longer just the machine name of the formatter to test (string), but an array describing the formatter like above: type and settings (we don't really care about the label).

I've created an issue to take care of that: #2203065: Adjust assertFormatterRdfa() parameters to allow for more advanced testing.

You can view how the settings of the field formatters are composed in entity.view_display.node.article.default.yml. I believe all you have to specify is for the field formatter settings to include a 'title' key set to your string, e.g. "Contact us".

This is the caller code:

    $formatter = array(
      'type' => 'telephone_link',
      'settings' => array('title' => 'Contact us'),
    );
    $this->assertFormatterRdfa($formatter, 'http://schema.org/telephone', 'tel:' . $this->testValue, 'uri');
lokapujya’s picture

I created a test that passes. But, do I need to use datatype? I have it commented out below.

<?php
   $formatter = array(
      'type' => 'telephone_link',
      'settings' => array('title' => 'Contact us'),
    );
    $expected_rdf_value = array(
      'value' => 'tel:' . $this->testValue,
      'type' => 'uri',
      /*'datatype' => 'schema:telephone',*/
    );
    // Tests the telephone link formatter with custom title.
    $this->assertFormatterRdfa($formatter, 'http://schema.org/telephone', $expected_rdf_value);
?>
scor’s picture

Status: Needs review » Needs work

I created a test that passes. But, do I need to use datatype? I have it commented out below.

No, in the case of the telephone field formatter, we won't need to use datatype because the expected value will not have a datatype. We will need the datatype for the date field issue only (note that the date field issue is RTBC at the moment as it implements a workaround for #2203065: Adjust assertFormatterRdfa() parameters to allow for more advanced testing - we will update the date field code in #2203065 once the date field patch is committed).

lokapujya’s picture

StatusFileSize
new3.39 KB
new1.38 KB

Added a test and rerolled for the updated assertFormatterRdfa().

lokapujya’s picture

Status: Needs work » Needs review
scor’s picture

Status: Needs review » Reviewed & tested by the community

Good job @lokapujya! This builds on top of #2203065: Adjust assertFormatterRdfa() parameters to allow for more advanced testing and is good to go...

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 85392bf and pushed to 8.x. Thanks!

diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TelephoneFieldRdfaTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TelephoneFieldRdfaTest.php
index 0ab144f..32d6825 100644
--- a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TelephoneFieldRdfaTest.php
+++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TelephoneFieldRdfaTest.php
@@ -6,14 +6,19 @@
 
 namespace Drupal\rdf\Tests\Field;
 
-use Drupal\rdf\Tests\Field\FieldRdfaTestBase;
-
 /**
  * Tests the placement of RDFa in telephone field formatters.
  */
 class TelephoneFieldRdfaTest extends FieldRdfaTestBase {
 
   /**
+   * A test value for the telephone field.
+   *
+   * @var string
+   */
+  protected $testValue;
+
+  /**
    * {@inheritdoc}
    */
   protected $fieldType = 'telephone';

Fixed during commit. The use is unnecessary since the classes are in the same namespace. Class properties shouldn't really be declared dynamically.

  • Commit 85392bf on 8.x by alexpott:
    Issue #2188877 by lokapujya | scor: Support RDFa output in telephone...

Status: Fixed » Closed (fixed)

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