View source
<?php
namespace Drupal\Tests\rdf\Kernel\Field;
use Drupal\entity_test\Entity\EntityTest;
class LinkFieldRdfaTest extends FieldRdfaTestBase {
protected $fieldType = 'link';
protected static $modules = [
'link',
'text',
];
protected function setUp() : void {
parent::setUp();
$this
->createTestField();
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping
->setFieldMapping($this->fieldName, [
'properties' => [
'schema:link',
],
])
->save();
}
public function testAllFormattersExternal() {
$this->testValue = 'http://test.me/foo/bar/neque/porro/quisquam/est/qui-dolorem?path=foo/bar/neque/porro/quisquam/est/qui-dolorem';
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->uri = $this->testValue;
$expected_rdf = [
'value' => $this->testValue,
'type' => 'uri',
];
$this
->runTestAllFormatters($expected_rdf, 'external');
}
public function testAllFormattersInternal() {
$this->testValue = 'admin';
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->uri = 'internal:/admin';
$expected_rdf = [
'value' => $this->uri . '/' . $this->testValue,
'type' => 'uri',
];
$this
->runTestAllFormatters($expected_rdf, 'internal');
}
public function testAllFormattersFront() {
$this->testValue = '/';
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->uri = 'internal:/';
$expected_rdf = [
'value' => $this->uri . '/',
'type' => 'uri',
];
$this
->runTestAllFormatters($expected_rdf, 'front');
}
public function runTestAllFormatters($expected_rdf, $type = NULL) {
$formatter = [
'type' => 'link',
'settings' => [
'trim_length' => 80,
'url_only' => FALSE,
'url_plain' => FALSE,
'rel' => '',
'target' => '',
],
];
$this
->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
$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);
$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);
$formatter = [
'type' => 'link_separate',
'settings' => [
'trim_length' => 40,
'rel' => 'nofollow',
'target' => '_blank',
],
];
$this
->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
$expected_rdf = [
'value' => $this->testValue,
'type' => 'literal',
];
$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);
$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);
}
}