Mercurial > hg > isophonics-drupal-site
comparison core/modules/rdf/tests/src/Functional/NodeAttributesTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\rdf\Functional; | |
4 | |
5 use Drupal\node\Tests\NodeTestBase; | |
6 | |
7 /** | |
8 * Tests the RDFa markup of Nodes. | |
9 * | |
10 * @group rdf | |
11 */ | |
12 class NodeAttributesTest extends NodeTestBase { | |
13 | |
14 /** | |
15 * Modules to enable. | |
16 * | |
17 * @var array | |
18 */ | |
19 public static $modules = ['rdf']; | |
20 | |
21 protected function setUp() { | |
22 parent::setUp(); | |
23 | |
24 rdf_get_mapping('node', 'article') | |
25 ->setBundleMapping([ | |
26 'types' => ['sioc:Item', 'foaf:Document'], | |
27 ]) | |
28 ->setFieldMapping('title', [ | |
29 'properties' => ['dc:title'], | |
30 ]) | |
31 ->setFieldMapping('created', [ | |
32 'properties' => ['dc:date', 'dc:created'], | |
33 'datatype' => 'xsd:dateTime', | |
34 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], | |
35 ]) | |
36 ->save(); | |
37 } | |
38 | |
39 /** | |
40 * Creates a node of type article and tests its RDFa markup. | |
41 */ | |
42 public function testNodeAttributes() { | |
43 // Create node with single quotation mark title to ensure it does not get | |
44 // escaped more than once. | |
45 $node = $this->drupalCreateNode([ | |
46 'type' => 'article', | |
47 'title' => $this->randomMachineName(8) . "'", | |
48 ]); | |
49 | |
50 $node_uri = $node->url('canonical', ['absolute' => TRUE]); | |
51 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]); | |
52 | |
53 // Parses front page where the node is displayed in its teaser form. | |
54 $parser = new \EasyRdf_Parser_Rdfa(); | |
55 $graph = new \EasyRdf_Graph(); | |
56 $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri); | |
57 | |
58 // Inspects RDF graph output. | |
59 // Node type. | |
60 $expected_value = [ | |
61 'type' => 'uri', | |
62 'value' => 'http://rdfs.org/sioc/ns#Item', | |
63 ]; | |
64 $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (sioc:Item).'); | |
65 // Node type. | |
66 $expected_value = [ | |
67 'type' => 'uri', | |
68 'value' => 'http://xmlns.com/foaf/0.1/Document', | |
69 ]; | |
70 $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (foaf:Document).'); | |
71 // Node title. | |
72 $expected_value = [ | |
73 'type' => 'literal', | |
74 'value' => $node->getTitle(), | |
75 'lang' => 'en', | |
76 ]; | |
77 $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).'); | |
78 // Node date (date format must be UTC). | |
79 $expected_value = [ | |
80 'type' => 'literal', | |
81 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'), | |
82 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime', | |
83 ]; | |
84 $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).'); | |
85 // Node date (date format must be UTC). | |
86 $expected_value = [ | |
87 'type' => 'literal', | |
88 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'), | |
89 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime', | |
90 ]; | |
91 $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).'); | |
92 } | |
93 | |
94 } |