You are here

class TelephoneFieldRdfaTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Kernel/Field/TelephoneFieldRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\TelephoneFieldRdfaTest
  2. 9 core/modules/rdf/tests/src/Kernel/Field/TelephoneFieldRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\TelephoneFieldRdfaTest

Tests RDFa output by telephone field formatters.

@group rdf

Hierarchy

Expanded class hierarchy of TelephoneFieldRdfaTest

File

core/modules/rdf/tests/src/Kernel/Field/TelephoneFieldRdfaTest.php, line 12

Namespace

Drupal\Tests\rdf\Kernel\Field
View source
class TelephoneFieldRdfaTest extends FieldRdfaTestBase {

  /**
   * A test value for the telephone field.
   *
   * @var string
   */
  protected $testValue;

  /**
   * {@inheritdoc}
   */
  protected $fieldType = 'telephone';

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'telephone',
    'text',
  ];
  protected function setUp() : void {
    parent::setUp();
    $this
      ->createTestField();

    // Add the mapping.
    $mapping = rdf_get_mapping('entity_test', 'entity_test');
    $mapping
      ->setFieldMapping($this->fieldName, [
      'properties' => [
        'schema:telephone',
      ],
    ])
      ->save();

    // Set up test values.
    $this->testValue = '555-555-5555';
    $this->entity = EntityTest::create([]);
    $this->entity->{$this->fieldName}->value = $this->testValue;
  }

  /**
   * Tests the field formatters.
   */
  public function testAllFormatters() {

    // Tests the plain formatter.
    $this
      ->assertFormatterRdfa([
      'type' => 'string',
    ], 'http://schema.org/telephone', [
      'value' => $this->testValue,
    ]);

    // Tests the telephone link formatter.
    $this
      ->assertFormatterRdfa([
      'type' => 'telephone_link',
    ], 'http://schema.org/telephone', [
      'value' => 'tel:' . $this->testValue,
      'type' => 'uri',
    ]);
    $formatter = [
      'type' => 'telephone_link',
      'settings' => [
        'title' => 'Contact us',
      ],
    ];
    $expected_rdf_value = [
      'value' => 'tel:' . $this->testValue,
      'type' => 'uri',
    ];

    // Tests the telephone link formatter with custom title.
    $this
      ->assertFormatterRdfa($formatter, 'http://schema.org/telephone', $expected_rdf_value);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldRdfaTestBase::$debug protected property TRUE if verbose debugging is enabled.
FieldRdfaTestBase::$entity protected property The entity to render for testing.
FieldRdfaTestBase::$fieldName protected property The name of the field to create for testing.
FieldRdfaTestBase::$uri protected property The URI to identify the entity.
FieldRdfaTestBase::assertFormatterRdfa protected function Helper function to test the formatter's RDFa.
FieldRdfaTestBase::createTestField protected function Creates the field for testing.
FieldRdfaTestBase::getAbsoluteUri protected function Gets the absolute URI of an entity.
FieldRdfaTestBase::parseContent protected function Parses a content and return the html element.
FieldRdfaTestBase::xpathContent protected function Performs an xpath search on a certain content.
RdfParsingTrait::getElementByRdfTypeCount protected function Counts the number of resources of the provided type.
RdfParsingTrait::getElementRdfType protected function Gets type of RDF Element.
RdfParsingTrait::hasRdfChildProperty protected function Checks if a html document contains a resource with a given property value.
RdfParsingTrait::hasRdfProperty protected function Checks if a html document contains a resource with a given property value.
RdfParsingTrait::rdfElementIsBlankNode protected function Checks if RDF Node property is blank.
TelephoneFieldRdfaTest::$fieldType protected property The machine name of the field type to test. Overrides FieldRdfaTestBase::$fieldType
TelephoneFieldRdfaTest::$modules protected static property Modules to enable. Overrides FieldRdfaTestBase::$modules
TelephoneFieldRdfaTest::$testValue protected property A test value for the telephone field. Overrides FieldRdfaTestBase::$testValue
TelephoneFieldRdfaTest::setUp protected function
TelephoneFieldRdfaTest::testAllFormatters public function Tests the field formatters.