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