3 namespace Drupal\Tests\rdf\Kernel\Field;
5 use Drupal\entity_test\Entity\EntityTest;
8 * Tests the placement of RDFa in link field formatters.
12 class LinkFieldRdfaTest extends FieldRdfaTestBase {
17 protected $fieldType = 'link';
22 public static $modules = ['link', 'text'];
27 protected function setUp() {
30 $this->createTestField();
33 $mapping = rdf_get_mapping('entity_test', 'entity_test');
34 $mapping->setFieldMapping($this->fieldName, [
35 'properties' => ['schema:link'],
41 * Tests all formatters with link to external page.
43 public function testAllFormattersExternal() {
44 // Set up test values.
45 $this->testValue = 'http://test.me/foo/bar/neque/porro/quisquam/est/qui-dolorem?path=foo/bar/neque/porro/quisquam/est/qui-dolorem';
46 $this->entity = EntityTest::create([]);
47 $this->entity->{$this->fieldName}->uri = $this->testValue;
49 // Set up the expected result.
51 'value' => $this->testValue,
55 $this->runTestAllFormatters($expected_rdf, 'external');
59 * Tests all formatters with link to internal page.
61 public function testAllFormattersInternal() {
62 // Set up test values.
63 $this->testValue = 'admin';
64 $this->entity = EntityTest::create([]);
65 $this->entity->{$this->fieldName}->uri = 'internal:/admin';
67 // Set up the expected result.
68 // AssertFormatterRdfa looks for a full path.
70 'value' => $this->uri . '/' . $this->testValue,
74 $this->runTestAllFormatters($expected_rdf, 'internal');
78 * Tests all formatters with link to frontpage.
80 public function testAllFormattersFront() {
81 // Set up test values.
82 $this->testValue = '/';
83 $this->entity = EntityTest::create([]);
84 $this->entity->{$this->fieldName}->uri = 'internal:/';
86 // Set up the expected result.
88 'value' => $this->uri . '/',
92 $this->runTestAllFormatters($expected_rdf, 'front');
96 * Helper function to test all link formatters.
98 public function runTestAllFormatters($expected_rdf, $type = NULL) {
100 // Test the link formatter: trim at 80, no other settings.
106 'url_plain' => FALSE,
111 $this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
113 // Test the link formatter: trim at 40, nofollow, new window.
119 'url_plain' => FALSE,
121 'target' => '_blank',
124 $this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
126 // Test the link formatter: trim at 40, URL only (not plaintext) nofollow,
133 'url_plain' => FALSE,
135 'target' => '_blank',
138 $this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
140 // Test the link_separate formatter: trim at 40, nofollow, new window.
142 'type' => 'link_separate',
146 'target' => '_blank',
149 $this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
151 // Change the expected value here to literal. When formatted as plaintext
152 // then the RDF is expecting a 'literal' not a 'uri'.
154 'value' => $this->testValue,
157 // Test the link formatter: trim at 20, url only (as plaintext.)
168 $this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
170 // Test the link formatter: do not trim, url only (as plaintext.)
181 $this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);