-
Notifications
You must be signed in to change notification settings - Fork 2
/
rdfx.test
144 lines (126 loc) · 5.17 KB
/
rdfx.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
// $Id: $
/**
* Test the RDF serialization functionality for nodes.
*/
class RdfxNodeSerializationTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF serialization for Nodes',
'description' => 'Create a node and test its RDF serialization.',
'group' => 'RDFx',
);
}
function setUp() {
parent::setUp();
// Set default storage backend.
variable_set('field_storage_default', 'field_sql_storage');
// $field_name = drupal_strtolower('rdfx_text_test_field');
// $field = array('field_name' => $field_name, 'type' => 'test_field', 'cardinality' => 4);
// $field = field_create_field($field);
// $field_id = $field['id'];
// $instance = array(
// 'field_name' => $field_name,
// 'entity_type' => 'test_entity',
// 'bundle' => 'article',
// 'label' => $this->randomName() . '_label',
// 'description' => $this->randomName() . '_description',
// 'weight' => mt_rand(0, 127),
// 'settings' => array(
// 'test_instance_setting' => $this->randomName(),
// ),
// 'widget' => array(
// 'type' => 'test_field_widget',
// 'label' => 'Test Field',
// 'settings' => array(
// 'test_widget_setting' => $this->randomName(),
// )
// )
// );
// field_create_instance($this->instance);
$web_user = $this->drupalCreateUser(array('create article content', 'create page content'));
$this->drupalLogin($web_user);
}
/**
* Create a "Article" node and ensure it serialized properly.
*/
function testRdfxNodeCreation() {
// Create a node.
$edit = array();
$langcode = LANGUAGE_NONE;
$edit["title"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/article', $edit, t('Save'));
// Check that the Article has been created.
$this->assertRaw(t('!post %title has been created.', array('!post' => 'Article', '%title' => $edit["title"])), t('Article created.'));
// Check that the node exists in the database.
$node = $this->drupalGetNodeByTitle($edit["title"]);
$this->assertTrue($node, t('Node found in database.'));
// Expected base URI and graph URI.
$base_uri = url('', array('absolute' => TRUE));
$uri = url('node/' . $node->nid, array('absolute' => TRUE));
// Get the node as RDF.
$g = rdfx_build_rdf_node($node);
// Inspect the PHP object returned by ARC2.
// Test object class.
$this->assertTrue(get_class($g) == 'ARC2_Resource', t('Object is of type ARC2_Resource.'));
// Test base uri.
$this->assertTrue($g->base == $base_uri, t('Base uri set properly by ARC2.'));
// Test graph uri.
$this->assertTrue($g->uri == $uri, t('Graph uri set properly by ARC2.'));
// Test if core rdf namespaces are present.
// @todo move this into a dedicate test for namespaces.
$erroneous_core_ns = FALSE;
foreach(rdf_rdf_namespaces() as $prefix => $ns) {
if (!isset($g->ns[$prefix]) || $g->ns[$prefix] != $ns) {
$erroneous_core_ns = TRUE;
}
}
$this->assertFalse($erroneous_core_ns, t('Core RDF namespaces set properly by ARC2.'));
// Test RDF types in ARC2 RDF index.
$o = array (
'value'=> 'http://rdfs.org/sioc/ns#Item',
'type'=> 'uri',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']), t('sioc:Item type found in ARC2 index.'));
$o = array (
'value'=> 'http://xmlns.com/foaf/0.1/Document',
'type'=> 'uri',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']), t('foaf:Document type found in ARC2 index.'));
// Test title in ARC2 RDF index.
$o = array (
'value'=> $node->title,
'type'=> 'literal',
'datatype'=> '',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://purl.org/dc/terms/title']), t('dc:title value found in ARC2 index.'));
// Test date in ARC2 RDF index.
$o = array (
'value'=> date_iso8601($node->created),
'type'=> 'literal',
'datatype' => 'xsd:dateTime',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://purl.org/dc/terms/date']), t('dc:date value found in ARC2 index.'));
$o = array (
'value'=> date_iso8601($node->created),
'type'=> 'literal',
'datatype' => 'xsd:dateTime',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://purl.org/dc/terms/created']), t('dc:created value found in ARC2 index.'));
// Test creator (user) in ARC2 RDF index.
$expected_user_uri = url('user/' . $node->uid, array('absolute' => TRUE));
$o = array (
'value'=> $expected_user_uri,
'type'=> 'uri',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://rdfs.org/sioc/ns#has_creator']), t('sioc:has_creator value found in ARC2 index.'));
// Test comment_count in ARC2 RDF index.
$o = array (
'value'=> $node->comment_count,
'type'=> 'literal',
'datatype'=> 'xsd:integer',
);
$this->assertTrue(in_array($o, $g->index[$uri]['http://rdfs.org/sioc/ns#num_replies']), t('sioc:num_replies value found in ARC2 index.'));
}
}