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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php
// $Id$
/**
* @file
* Tests for RDF functionality.
*/
class RdfMappingHookTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF mapping hook',
'description' => 'Test hook_rdf_mapping().',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test', 'field_test');
// We need to trigger rdf_modules_installed() because
// hook_modules_installed() is not automatically invoked during testing.
rdf_modules_installed(array('rdf_test'));
}
/**
* Test that hook_rdf_mapping() correctly returns and processes mapping.
*/
function testMapping() {
// Test that the mapping is returned correctly by the hook.
$mapping = rdf_get_mapping('test_entity', 'test_bundle');
$this->assertIdentical($mapping['rdftype'], array('sioc:Post'), t('Mapping for rdftype is sioc:Post.'));
$this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), t('Mapping for title is dc:title.'));
$this->assertIdentical($mapping['created'], array(
'predicates' => array('dc:created'),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
), t('Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.'));
$this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator')), t('Mapping for uid is sioc:has_creator and dc:creator.'));
$mapping = rdf_get_mapping('test_entity', 'test_bundle_no_mapping');
$this->assertEqual($mapping, array(), t('Empty array returned when an entity type, bundle pair has no mapping.'));
}
}
class RdfMarkupTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDFa markup',
'description' => 'Test RDFa markup generation.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'field_test', 'rdf_test');
rdf_modules_installed(array('field_test', 'rdf_test'));
}
/**
* Test rdf_rdfa_attributes().
*/
function testDrupalRdfaAtributes() {
$date = 1252750327;
$isoDate = date('c', $date);
$expected_type = 'xsd:dateTime';
$expected_property = array('dc:created');
$expected_value = $isoDate;
$mapping = rdf_get_mapping('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['created'], $date);
$this->assertEqual($expected_type, $attributes['datatype']);
$this->assertEqual($expected_property, $attributes['property']);
$this->assertEqual($expected_value, $attributes['content']);
}
}
class RdfCrudTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF mapping CRUD functions',
'description' => 'Test the RDF mapping CRUD functions.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test');
}
/**
* Test inserting, loading, updating, and deleting RDF mappings.
*/
function testCRUD() {
$test_mapping = rdf_test_rdf_mapping();
// Verify loading of a default mapping.
$this->assertFalse(count(rdf_mapping_load('test_entity', 'test_bundle')), t('Default mapping was found.'));
// Verify saving a mapping.
$mapping = (array) $test_mapping;
rdf_mapping_save($mapping[0]);
$this->assertEqual($mapping[0]['mapping'], $test_mapping[0]['mapping'], t('Saved mapping equals default mapping.'));
$this->assertTrue(rdf_mapping_save($mapping[1]) === SAVED_NEW, t('Second mapping was inserted.'));
$this->assertEqual($mapping[1]['mapping'], rdf_mapping_load($test_mapping[1]['type'], $test_mapping[1]['bundle']), t('Second mapping equals default mapping.'));
// Verify loading of saved mapping.
$this->assertEqual($mapping[0]['mapping'], rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Saved mapping equals loaded default mapping.'));
// Verify updating of mapping.
$mapping[0]['mapping']['boofar'] = array(
'predicates' => array('foo:bar'),
);
$this->assertTrue(rdf_mapping_save($mapping[0]) === SAVED_UPDATED, t('Mapping was updated.'));
$this->assertEqual($mapping[0]['mapping'], rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Updated and loaded mapping are equal.'));
// Verify deleting of mapping.
$this->assertTrue(rdf_mapping_delete($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Mapping was deleted.'));
$this->assertFalse(rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Deleted mapping is no longer found.'));
}
}
class RdfMappingDefinitionTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF mapping definition functionality',
'description' => 'Test the different types of RDF mappings and ensure the proper RDFa markup in included in node pages.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test', 'blog');
// We need to trigger rdf_modules_installed() because
// hook_modules_installed() is not automatically invoked during testing.
rdf_modules_installed(array('rdf_test', 'node'));
// entity_info caches must be cleared during testing. This is done
// automatically during the manual installation.
cache_clear_all('entity_info', 'cache');
drupal_static_reset('entity_get_info');
}
/**
* Create a node of type blog and test whether the RDF mapping defined for
* this node type in rdf_test.module is used in the node page.
*/
function testAttributesInMarkup1() {
$node = $this->drupalCreateNode(array('type' => 'blog'));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw('typeof="sioct:Weblog"');
// Ensure the default bundle mapping for node is used. These attributes come
// from the node default bundle definition.
$this->assertRaw('property="dc:title"');
$this->assertRaw('property="dc:date dc:created"');
}
/**
* Create a content type and a node of type test_bundle_hook_install and test
* whether the RDF mapping defined in rdf_test.install is used.
*/
function testAttributesInMarkup2() {
$type = $this->drupalCreateContentType(array('type' => 'test_bundle_hook_install'));
$node = $this->drupalCreateNode(array('type' => 'test_bundle_hook_install'));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw('typeof="foo:mapping_install1 bar:mapping_install2"');
// Ensure the default bundle mapping for node is used. These attributes come
// from the node default bundle definition.
$this->assertRaw('property="dc:title"');
$this->assertRaw('property="dc:date dc:created"');
}
/**
* Create a random content type and node and ensure the default mapping for
* node is used.
*/
function testAttributesInMarkup3() {
$type = $this->drupalCreateContentType();
$node = $this->drupalCreateNode(array('type' => $type->type));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw('typeof="sioc:Item foaf:Document"');
// Ensure the default bundle mapping for node is used. These attributes come
// from the node default bundle definition.
$this->assertRaw('property="dc:title"');
$this->assertRaw('property="dc:date dc:created"');
}
}
|