Mercurial > hg > isophonics-drupal-site
comparison core/modules/rdf/tests/src/Functional/TaxonomyAttributesTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\rdf\Functional; | |
4 | |
5 use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase; | |
6 | |
7 /** | |
8 * Tests the RDFa markup of Taxonomy terms. | |
9 * | |
10 * @group rdf | |
11 */ | |
12 class TaxonomyAttributesTest extends TaxonomyTestBase { | |
13 | |
14 /** | |
15 * Modules to enable. | |
16 * | |
17 * @var array | |
18 */ | |
19 public static $modules = ['rdf', 'views']; | |
20 | |
21 /** | |
22 * Vocabulary created for testing purposes. | |
23 * | |
24 * @var \Drupal\taxonomy\VocabularyInterface | |
25 */ | |
26 protected $vocabulary; | |
27 | |
28 protected function setUp() { | |
29 parent::setUp(); | |
30 | |
31 $this->vocabulary = $this->createVocabulary(); | |
32 | |
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'], | |
38 ]) | |
39 ->save(); | |
40 } | |
41 | |
42 /** | |
43 * Creates a random term and ensures the RDF output is correct. | |
44 */ | |
45 public function testTaxonomyTermRdfaAttributes() { | |
46 $term = $this->createTerm($this->vocabulary); | |
47 $term_uri = $term->url('canonical', ['absolute' => TRUE]); | |
48 | |
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); | |
54 | |
55 // Inspects RDF graph output. | |
56 // Term type. | |
57 $expected_value = [ | |
58 'type' => 'uri', | |
59 'value' => 'http://www.w3.org/2004/02/skos/core#Concept', | |
60 ]; | |
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).'); | |
62 // Term label. | |
63 $expected_value = [ | |
64 'type' => 'literal', | |
65 'value' => $term->getName(), | |
66 'lang' => 'en', | |
67 ]; | |
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).'); | |
69 // Term label. | |
70 $expected_value = [ | |
71 'type' => 'literal', | |
72 'value' => $term->getName(), | |
73 'lang' => 'en', | |
74 ]; | |
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).'); | |
76 | |
77 // @todo Add test for term description once it is a field: | |
78 // https://www.drupal.org/node/569434. | |
79 } | |
80 | |
81 } |