You are here

public function LinkFieldRdfaTest::runTestAllFormatters in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\LinkFieldRdfaTest::runTestAllFormatters()
  2. 10 core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\LinkFieldRdfaTest::runTestAllFormatters()

Helper function to test all link formatters.

3 calls to LinkFieldRdfaTest::runTestAllFormatters()
LinkFieldRdfaTest::testAllFormattersExternal in core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php
Tests all formatters with link to external page.
LinkFieldRdfaTest::testAllFormattersFront in core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php
Tests all formatters with link to frontpage.
LinkFieldRdfaTest::testAllFormattersInternal in core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php
Tests all formatters with link to internal page.

File

core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php, line 98

Class

LinkFieldRdfaTest
Tests the placement of RDFa in link field formatters.

Namespace

Drupal\Tests\rdf\Kernel\Field

Code

public function runTestAllFormatters($expected_rdf, $type = NULL) {

  // Test the link formatter: trim at 80, no other settings.
  $formatter = [
    'type' => 'link',
    'settings' => [
      'trim_length' => 80,
      'url_only' => FALSE,
      'url_plain' => FALSE,
      'rel' => '',
      'target' => '',
    ],
  ];
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);

  // Test the link formatter: trim at 40, nofollow, new window.
  $formatter = [
    'type' => 'link',
    'settings' => [
      'trim_length' => 40,
      'url_only' => FALSE,
      'url_plain' => FALSE,
      'rel' => 'nofollow',
      'target' => '_blank',
    ],
  ];
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);

  // Test the link formatter: trim at 40, URL only (not plaintext) nofollow,
  // new window.
  $formatter = [
    'type' => 'link',
    'settings' => [
      'trim_length' => 40,
      'url_only' => TRUE,
      'url_plain' => FALSE,
      'rel' => 'nofollow',
      'target' => '_blank',
    ],
  ];
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);

  // Test the link_separate formatter: trim at 40, nofollow, new window.
  $formatter = [
    'type' => 'link_separate',
    'settings' => [
      'trim_length' => 40,
      'rel' => 'nofollow',
      'target' => '_blank',
    ],
  ];
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);

  // Change the expected value here to literal. When formatted as plaintext
  // then the RDF is expecting a 'literal' not a 'uri'.
  $expected_rdf = [
    'value' => $this->testValue,
    'type' => 'literal',
  ];

  // Test the link formatter: trim at 20, url only (as plaintext.)
  $formatter = [
    'type' => 'link',
    'settings' => [
      'trim_length' => 20,
      'url_only' => TRUE,
      'url_plain' => TRUE,
      'rel' => '0',
      'target' => '0',
    ],
  ];
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);

  // Test the link formatter: do not trim, url only (as plaintext.)
  $formatter = [
    'type' => 'link',
    'settings' => [
      'trim_length' => 0,
      'url_only' => TRUE,
      'url_plain' => TRUE,
      'rel' => '0',
      'target' => '0',
    ],
  ];
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
}