3 namespace Drupal\Tests\rdf\Functional;
5 use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
8 * Tests the RDFa markup of Taxonomy terms.
12 class TaxonomyAttributesTest extends TaxonomyTestBase {
19 public static $modules = ['rdf', 'views'];
22 * Vocabulary created for testing purposes.
24 * @var \Drupal\taxonomy\VocabularyInterface
26 protected $vocabulary;
28 protected function setUp() {
31 $this->vocabulary = $this->createVocabulary();
33 // RDF mapping - term bundle.
34 rdf_get_mapping('taxonomy_term', $this->vocabulary->id())
35 ->setBundleMapping(['types' => ['skos:Concept']])
36 ->setFieldMapping('name', [
37 'properties' => ['rdfs:label', 'skos:prefLabel'],
43 * Creates a random term and ensures the RDF output is correct.
45 public function testTaxonomyTermRdfaAttributes() {
46 $term = $this->createTerm($this->vocabulary);
47 $term_uri = $term->url('canonical', ['absolute' => TRUE]);
49 // Parses the term's page and checks that the RDF output is correct.
50 $parser = new \EasyRdf_Parser_Rdfa();
51 $graph = new \EasyRdf_Graph();
52 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
53 $parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->id()), 'rdfa', $base_uri);
55 // Inspects RDF graph output.
59 'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
61 $this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
65 'value' => $term->getName(),
68 $this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Term label found in RDF output (rdfs:label).');
72 'value' => $term->getName(),
75 $this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2004/02/skos/core#prefLabel', $expected_value), 'Term label found in RDF output (skos:prefLabel).');
77 // @todo Add test for term description once it is a field:
78 // https://www.drupal.org/node/569434.