View source
<?php
namespace Drupal\Tests\rdf\Functional;
use Drupal\Core\Url;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
class TaxonomyAttributesTest extends TaxonomyTestBase {
use RdfParsingTrait;
protected static $modules = [
'rdf',
'views',
];
protected $defaultTheme = 'stark';
protected $baseUri;
protected $vocabulary;
protected function setUp() : void {
parent::setUp();
$this->vocabulary = $this
->createVocabulary();
rdf_get_mapping('taxonomy_term', $this->vocabulary
->id())
->setBundleMapping([
'types' => [
'skos:Concept',
],
])
->setFieldMapping('name', [
'properties' => [
'rdfs:label',
'skos:prefLabel',
],
])
->save();
$this->baseUri = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString();
}
public function testTaxonomyTermRdfaAttributes() {
$term = $this
->createTerm($this->vocabulary);
$term_uri = $term
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->drupalGet($term
->toUrl());
$expected_value = [
'type' => 'uri',
'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $term_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
$expected_value = [
'type' => 'literal',
'value' => $term
->getName(),
'lang' => 'en',
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $term_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Term label found in RDF output (rdfs:label).');
$expected_value = [
'type' => 'literal',
'value' => $term
->getName(),
'lang' => 'en',
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $term_uri, 'http://www.w3.org/2004/02/skos/core#prefLabel', $expected_value), 'Term label found in RDF output (skos:prefLabel).');
}
}