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