Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\rdf\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests the RDFa markup of Taxonomy terms.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group rdf
|
Chris@0
|
11 */
|
Chris@0
|
12 class TaxonomyAttributesTest extends TaxonomyTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to enable.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $modules = ['rdf', 'views'];
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Vocabulary created for testing purposes.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @var \Drupal\taxonomy\VocabularyInterface
|
Chris@0
|
25 */
|
Chris@0
|
26 protected $vocabulary;
|
Chris@0
|
27
|
Chris@0
|
28 protected function setUp() {
|
Chris@0
|
29 parent::setUp();
|
Chris@0
|
30
|
Chris@0
|
31 $this->vocabulary = $this->createVocabulary();
|
Chris@0
|
32
|
Chris@0
|
33 // RDF mapping - term bundle.
|
Chris@0
|
34 rdf_get_mapping('taxonomy_term', $this->vocabulary->id())
|
Chris@0
|
35 ->setBundleMapping(['types' => ['skos:Concept']])
|
Chris@0
|
36 ->setFieldMapping('name', [
|
Chris@0
|
37 'properties' => ['rdfs:label', 'skos:prefLabel'],
|
Chris@0
|
38 ])
|
Chris@0
|
39 ->save();
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 /**
|
Chris@0
|
43 * Creates a random term and ensures the RDF output is correct.
|
Chris@0
|
44 */
|
Chris@0
|
45 public function testTaxonomyTermRdfaAttributes() {
|
Chris@0
|
46 $term = $this->createTerm($this->vocabulary);
|
Chris@0
|
47 $term_uri = $term->url('canonical', ['absolute' => TRUE]);
|
Chris@0
|
48
|
Chris@0
|
49 // Parses the term's page and checks that the RDF output is correct.
|
Chris@0
|
50 $parser = new \EasyRdf_Parser_Rdfa();
|
Chris@0
|
51 $graph = new \EasyRdf_Graph();
|
Chris@0
|
52 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
|
Chris@0
|
53 $parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->id()), 'rdfa', $base_uri);
|
Chris@0
|
54
|
Chris@0
|
55 // Inspects RDF graph output.
|
Chris@0
|
56 // Term type.
|
Chris@0
|
57 $expected_value = [
|
Chris@0
|
58 'type' => 'uri',
|
Chris@0
|
59 'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
|
Chris@0
|
60 ];
|
Chris@0
|
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).');
|
Chris@0
|
62 // Term label.
|
Chris@0
|
63 $expected_value = [
|
Chris@0
|
64 'type' => 'literal',
|
Chris@0
|
65 'value' => $term->getName(),
|
Chris@0
|
66 'lang' => 'en',
|
Chris@0
|
67 ];
|
Chris@0
|
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).');
|
Chris@0
|
69 // Term label.
|
Chris@0
|
70 $expected_value = [
|
Chris@0
|
71 'type' => 'literal',
|
Chris@0
|
72 'value' => $term->getName(),
|
Chris@0
|
73 'lang' => 'en',
|
Chris@0
|
74 ];
|
Chris@0
|
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).');
|
Chris@0
|
76
|
Chris@0
|
77 // @todo Add test for term description once it is a field:
|
Chris@0
|
78 // https://www.drupal.org/node/569434.
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 }
|