danielebarchiesi@0
|
1 <?php
|
danielebarchiesi@0
|
2
|
danielebarchiesi@0
|
3 /**
|
danielebarchiesi@0
|
4 * @file
|
danielebarchiesi@0
|
5 * Tests for rdf.module.
|
danielebarchiesi@0
|
6 */
|
danielebarchiesi@0
|
7
|
danielebarchiesi@0
|
8 class RdfMappingHookTestCase extends DrupalWebTestCase {
|
danielebarchiesi@0
|
9 public static function getInfo() {
|
danielebarchiesi@0
|
10 return array(
|
danielebarchiesi@0
|
11 'name' => 'RDF mapping hook',
|
danielebarchiesi@0
|
12 'description' => 'Test hook_rdf_mapping().',
|
danielebarchiesi@0
|
13 'group' => 'RDF',
|
danielebarchiesi@0
|
14 );
|
danielebarchiesi@0
|
15 }
|
danielebarchiesi@0
|
16
|
danielebarchiesi@0
|
17 function setUp() {
|
danielebarchiesi@0
|
18 parent::setUp('rdf', 'rdf_test', 'field_test');
|
danielebarchiesi@0
|
19 }
|
danielebarchiesi@0
|
20
|
danielebarchiesi@0
|
21 /**
|
danielebarchiesi@0
|
22 * Test that hook_rdf_mapping() correctly returns and processes mapping.
|
danielebarchiesi@0
|
23 */
|
danielebarchiesi@0
|
24 function testMapping() {
|
danielebarchiesi@0
|
25 // Test that the mapping is returned correctly by the hook.
|
danielebarchiesi@0
|
26 $mapping = rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
27 $this->assertIdentical($mapping['rdftype'], array('sioc:Post'), 'Mapping for rdftype is sioc:Post.');
|
danielebarchiesi@0
|
28 $this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), 'Mapping for title is dc:title.');
|
danielebarchiesi@0
|
29 $this->assertIdentical($mapping['created'], array(
|
danielebarchiesi@0
|
30 'predicates' => array('dc:created'),
|
danielebarchiesi@0
|
31 'datatype' => 'xsd:dateTime',
|
danielebarchiesi@0
|
32 'callback' => 'date_iso8601',
|
danielebarchiesi@0
|
33 ), t('Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.'));
|
danielebarchiesi@0
|
34 $this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), 'Mapping for uid is sioc:has_creator and dc:creator, and type is rel.');
|
danielebarchiesi@0
|
35
|
danielebarchiesi@0
|
36 $mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping');
|
danielebarchiesi@0
|
37 $this->assertEqual($mapping, array(), 'Empty array returned when an entity type, bundle pair has no mapping.');
|
danielebarchiesi@0
|
38 }
|
danielebarchiesi@0
|
39 }
|
danielebarchiesi@0
|
40
|
danielebarchiesi@0
|
41 /**
|
danielebarchiesi@0
|
42 * Test RDFa markup generation.
|
danielebarchiesi@0
|
43 */
|
danielebarchiesi@0
|
44 class RdfRdfaMarkupTestCase extends DrupalWebTestCase {
|
danielebarchiesi@0
|
45 public static function getInfo() {
|
danielebarchiesi@0
|
46 return array(
|
danielebarchiesi@0
|
47 'name' => 'RDFa markup',
|
danielebarchiesi@0
|
48 'description' => 'Test RDFa markup generation.',
|
danielebarchiesi@0
|
49 'group' => 'RDF',
|
danielebarchiesi@0
|
50 );
|
danielebarchiesi@0
|
51 }
|
danielebarchiesi@0
|
52
|
danielebarchiesi@0
|
53 function setUp() {
|
danielebarchiesi@0
|
54 parent::setUp('rdf', 'field_test', 'rdf_test');
|
danielebarchiesi@0
|
55 }
|
danielebarchiesi@0
|
56
|
danielebarchiesi@0
|
57 /**
|
danielebarchiesi@0
|
58 * Test rdf_rdfa_attributes().
|
danielebarchiesi@0
|
59 */
|
danielebarchiesi@0
|
60 function testDrupalRdfaAttributes() {
|
danielebarchiesi@0
|
61 // Same value as the one in the HTML tag (no callback function).
|
danielebarchiesi@0
|
62 $expected_attributes = array(
|
danielebarchiesi@0
|
63 'property' => array('dc:title'),
|
danielebarchiesi@0
|
64 );
|
danielebarchiesi@0
|
65 $mapping = rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
66 $attributes = rdf_rdfa_attributes($mapping['title']);
|
danielebarchiesi@0
|
67 ksort($expected_attributes);
|
danielebarchiesi@0
|
68 ksort($attributes);
|
danielebarchiesi@0
|
69 $this->assertEqual($expected_attributes, $attributes);
|
danielebarchiesi@0
|
70
|
danielebarchiesi@0
|
71 // Value different from the one in the HTML tag (callback function).
|
danielebarchiesi@0
|
72 $date = 1252750327;
|
danielebarchiesi@0
|
73 $isoDate = date('c', $date);
|
danielebarchiesi@0
|
74 $expected_attributes = array(
|
danielebarchiesi@0
|
75 'datatype' => 'xsd:dateTime',
|
danielebarchiesi@0
|
76 'property' => array('dc:created'),
|
danielebarchiesi@0
|
77 'content' => $isoDate,
|
danielebarchiesi@0
|
78 );
|
danielebarchiesi@0
|
79 $mapping = rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
80 $attributes = rdf_rdfa_attributes($mapping['created'], $date);
|
danielebarchiesi@0
|
81 ksort($expected_attributes);
|
danielebarchiesi@0
|
82 ksort($attributes);
|
danielebarchiesi@0
|
83 $this->assertEqual($expected_attributes, $attributes);
|
danielebarchiesi@0
|
84
|
danielebarchiesi@0
|
85 // Same value as the one in the HTML tag with datatype.
|
danielebarchiesi@0
|
86 $expected_attributes = array(
|
danielebarchiesi@0
|
87 'datatype' => 'foo:bar1type',
|
danielebarchiesi@0
|
88 'property' => array('foo:bar1'),
|
danielebarchiesi@0
|
89 );
|
danielebarchiesi@0
|
90 $mapping = rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
91 $attributes = rdf_rdfa_attributes($mapping['foobar1']);
|
danielebarchiesi@0
|
92 ksort($expected_attributes);
|
danielebarchiesi@0
|
93 ksort($attributes);
|
danielebarchiesi@0
|
94 $this->assertEqual($expected_attributes, $attributes);
|
danielebarchiesi@0
|
95
|
danielebarchiesi@0
|
96 // ObjectProperty mapping (rel).
|
danielebarchiesi@0
|
97 $expected_attributes = array(
|
danielebarchiesi@0
|
98 'rel' => array('sioc:has_creator', 'dc:creator'),
|
danielebarchiesi@0
|
99 );
|
danielebarchiesi@0
|
100 $mapping = rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
101 $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']);
|
danielebarchiesi@0
|
102 ksort($expected_attributes);
|
danielebarchiesi@0
|
103 ksort($attributes);
|
danielebarchiesi@0
|
104 $this->assertEqual($expected_attributes, $attributes);
|
danielebarchiesi@0
|
105
|
danielebarchiesi@0
|
106 // Inverse ObjectProperty mapping (rev).
|
danielebarchiesi@0
|
107 $expected_attributes = array(
|
danielebarchiesi@0
|
108 'rev' => array('sioc:reply_of'),
|
danielebarchiesi@0
|
109 );
|
danielebarchiesi@0
|
110 $mapping = rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
111 $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']);
|
danielebarchiesi@0
|
112 ksort($expected_attributes);
|
danielebarchiesi@0
|
113 ksort($attributes);
|
danielebarchiesi@0
|
114 $this->assertEqual($expected_attributes, $attributes);
|
danielebarchiesi@0
|
115 }
|
danielebarchiesi@0
|
116
|
danielebarchiesi@0
|
117 /**
|
danielebarchiesi@0
|
118 * Ensure that file fields have the correct resource as the object in RDFa
|
danielebarchiesi@0
|
119 * when displayed as a teaser.
|
danielebarchiesi@0
|
120 */
|
danielebarchiesi@0
|
121 function testAttributesInMarkupFile() {
|
danielebarchiesi@0
|
122 // Create a user to post the image.
|
danielebarchiesi@0
|
123 $admin_user = $this->drupalCreateUser(array('edit own article content', 'revert revisions', 'administer content types'));
|
danielebarchiesi@0
|
124 $this->drupalLogin($admin_user);
|
danielebarchiesi@0
|
125
|
danielebarchiesi@0
|
126 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
127 $bundle_name = "article";
|
danielebarchiesi@0
|
128
|
danielebarchiesi@0
|
129 $field_name = 'file_test';
|
danielebarchiesi@0
|
130 $field = array(
|
danielebarchiesi@0
|
131 'field_name' => $field_name,
|
danielebarchiesi@0
|
132 'type' => 'file',
|
danielebarchiesi@0
|
133 );
|
danielebarchiesi@0
|
134 field_create_field($field);
|
danielebarchiesi@0
|
135 $instance = array(
|
danielebarchiesi@0
|
136 'field_name' => $field_name,
|
danielebarchiesi@0
|
137 'entity_type' => 'node',
|
danielebarchiesi@0
|
138 'bundle' => $bundle_name,
|
danielebarchiesi@0
|
139 'display' => array(
|
danielebarchiesi@0
|
140 'teaser' => array(
|
danielebarchiesi@0
|
141 'type' => 'file_default',
|
danielebarchiesi@0
|
142 ),
|
danielebarchiesi@0
|
143 ),
|
danielebarchiesi@0
|
144 );
|
danielebarchiesi@0
|
145 field_create_instance($instance);
|
danielebarchiesi@0
|
146
|
danielebarchiesi@0
|
147 // Set the RDF mapping for the new field.
|
danielebarchiesi@0
|
148 $rdf_mapping = rdf_mapping_load('node', $bundle_name);
|
danielebarchiesi@0
|
149 $rdf_mapping += array($field_name => array('predicates' => array('rdfs:seeAlso'), 'type' => 'rel'));
|
danielebarchiesi@0
|
150 $rdf_mapping_save = array('mapping' => $rdf_mapping, 'type' => 'node', 'bundle' => $bundle_name);
|
danielebarchiesi@0
|
151 rdf_mapping_save($rdf_mapping_save);
|
danielebarchiesi@0
|
152
|
danielebarchiesi@0
|
153 // Get the test file that simpletest provides.
|
danielebarchiesi@0
|
154 $file = current($this->drupalGetTestFiles('text'));
|
danielebarchiesi@0
|
155
|
danielebarchiesi@0
|
156 // Prepare image variables.
|
danielebarchiesi@0
|
157 $image_field = "field_image";
|
danielebarchiesi@0
|
158 // Get the test image that simpletest provides.
|
danielebarchiesi@0
|
159 $image = current($this->drupalGetTestFiles('image'));
|
danielebarchiesi@0
|
160
|
danielebarchiesi@0
|
161 // Create an array for drupalPost with the field names as the keys and
|
danielebarchiesi@0
|
162 // the URIs for the test files as the values.
|
danielebarchiesi@0
|
163 $edit = array("files[" . $field_name . "_" . $langcode . "_0]" => drupal_realpath($file->uri),
|
danielebarchiesi@0
|
164 "files[" . $image_field . "_" . $langcode . "_0]" => drupal_realpath($image->uri));
|
danielebarchiesi@0
|
165
|
danielebarchiesi@0
|
166 // Create node and save, then edit node to upload files.
|
danielebarchiesi@0
|
167 $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
168 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
danielebarchiesi@0
|
169
|
danielebarchiesi@0
|
170 // Get filenames and nid for comparison with HTML output.
|
danielebarchiesi@0
|
171 $file_filename = $file->filename;
|
danielebarchiesi@0
|
172 $image_filename = $image->filename;
|
danielebarchiesi@0
|
173 $nid = $node->nid;
|
danielebarchiesi@0
|
174 // Navigate to front page, where node is displayed in teaser form.
|
danielebarchiesi@0
|
175 $this->drupalGet('node');
|
danielebarchiesi@0
|
176
|
danielebarchiesi@0
|
177 // We only check to make sure that the resource attribute contains '.txt'
|
danielebarchiesi@0
|
178 // instead of the full file name because the filename is altered on upload.
|
danielebarchiesi@0
|
179 $file_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, ".txt")]', array(
|
danielebarchiesi@0
|
180 ':node-uri' => 'node/' . $nid,
|
danielebarchiesi@0
|
181 ));
|
danielebarchiesi@0
|
182 $this->assertTrue(!empty($file_rel), "Attribute 'rel' set on file field. Attribute 'resource' is also set.");
|
danielebarchiesi@0
|
183 $image_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, :image)]//img[contains(@typeof, "foaf:Image")]', array(
|
danielebarchiesi@0
|
184 ':node-uri' => 'node/' . $nid,
|
danielebarchiesi@0
|
185 ':image' => $image_filename,
|
danielebarchiesi@0
|
186 ));
|
danielebarchiesi@0
|
187
|
danielebarchiesi@0
|
188 $this->assertTrue(!empty($image_rel), "Attribute 'rel' set on image field. Attribute 'resource' is also set.");
|
danielebarchiesi@0
|
189
|
danielebarchiesi@0
|
190 // Edits the node to add tags.
|
danielebarchiesi@0
|
191 $tag1 = $this->randomName(8);
|
danielebarchiesi@0
|
192 $tag2 = $this->randomName(8);
|
danielebarchiesi@0
|
193 $edit = array();
|
danielebarchiesi@0
|
194 $edit['field_tags[' . LANGUAGE_NONE . ']'] = "$tag1, $tag2";
|
danielebarchiesi@0
|
195 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
danielebarchiesi@0
|
196 // Ensures the RDFa markup for the relationship between the node and its
|
danielebarchiesi@0
|
197 // tags is correct.
|
danielebarchiesi@0
|
198 $term_rdfa_meta = $this->xpath('//div[@about=:node-url and contains(@typeof, "sioc:Item") and contains(@typeof, "foaf:Document")]//ul[@class="links"]/li[@rel="dc:subject"]/a[@typeof="skos:Concept" and @datatype="" and text()=:term-name]', array(
|
danielebarchiesi@0
|
199 ':node-url' => url('node/' . $node->nid),
|
danielebarchiesi@0
|
200 ':term-name' => $tag1,
|
danielebarchiesi@0
|
201 ));
|
danielebarchiesi@0
|
202 $this->assertTrue(!empty($term_rdfa_meta), 'Property dc:subject is present for the tag1 field item.');
|
danielebarchiesi@0
|
203 $term_rdfa_meta = $this->xpath('//div[@about=:node-url and contains(@typeof, "sioc:Item") and contains(@typeof, "foaf:Document")]//ul[@class="links"]/li[@rel="dc:subject"]/a[@typeof="skos:Concept" and @datatype="" and text()=:term-name]', array(
|
danielebarchiesi@0
|
204 ':node-url' => url('node/' . $node->nid),
|
danielebarchiesi@0
|
205 ':term-name' => $tag2,
|
danielebarchiesi@0
|
206 ));
|
danielebarchiesi@0
|
207 $this->assertTrue(!empty($term_rdfa_meta), 'Property dc:subject is present for the tag2 field item.');
|
danielebarchiesi@0
|
208 }
|
danielebarchiesi@0
|
209 }
|
danielebarchiesi@0
|
210
|
danielebarchiesi@0
|
211 class RdfCrudTestCase extends DrupalWebTestCase {
|
danielebarchiesi@0
|
212 public static function getInfo() {
|
danielebarchiesi@0
|
213 return array(
|
danielebarchiesi@0
|
214 'name' => 'RDF mapping CRUD functions',
|
danielebarchiesi@0
|
215 'description' => 'Test the RDF mapping CRUD functions.',
|
danielebarchiesi@0
|
216 'group' => 'RDF',
|
danielebarchiesi@0
|
217 );
|
danielebarchiesi@0
|
218 }
|
danielebarchiesi@0
|
219
|
danielebarchiesi@0
|
220 function setUp() {
|
danielebarchiesi@0
|
221 parent::setUp('rdf', 'rdf_test');
|
danielebarchiesi@0
|
222 }
|
danielebarchiesi@0
|
223
|
danielebarchiesi@0
|
224 /**
|
danielebarchiesi@0
|
225 * Test inserting, loading, updating, and deleting RDF mappings.
|
danielebarchiesi@0
|
226 */
|
danielebarchiesi@0
|
227 function testCRUD() {
|
danielebarchiesi@0
|
228 // Verify loading of a default mapping.
|
danielebarchiesi@0
|
229 $mapping = _rdf_mapping_load('test_entity', 'test_bundle');
|
danielebarchiesi@0
|
230 $this->assertTrue(count($mapping), 'Default mapping was found.');
|
danielebarchiesi@0
|
231
|
danielebarchiesi@0
|
232 // Verify saving a mapping.
|
danielebarchiesi@0
|
233 $mapping = array(
|
danielebarchiesi@0
|
234 'type' => 'crud_test_entity',
|
danielebarchiesi@0
|
235 'bundle' => 'crud_test_bundle',
|
danielebarchiesi@0
|
236 'mapping' => array(
|
danielebarchiesi@0
|
237 'rdftype' => array('sioc:Post'),
|
danielebarchiesi@0
|
238 'title' => array(
|
danielebarchiesi@0
|
239 'predicates' => array('dc:title'),
|
danielebarchiesi@0
|
240 ),
|
danielebarchiesi@0
|
241 'uid' => array(
|
danielebarchiesi@0
|
242 'predicates' => array('sioc:has_creator', 'dc:creator'),
|
danielebarchiesi@0
|
243 'type' => 'rel',
|
danielebarchiesi@0
|
244 ),
|
danielebarchiesi@0
|
245 ),
|
danielebarchiesi@0
|
246 );
|
danielebarchiesi@0
|
247 $this->assertTrue(rdf_mapping_save($mapping) === SAVED_NEW, 'Mapping was saved.');
|
danielebarchiesi@0
|
248
|
danielebarchiesi@0
|
249 // Read the raw record from the {rdf_mapping} table.
|
danielebarchiesi@0
|
250 $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
|
danielebarchiesi@0
|
251 $stored_mapping = $result->fetchAssoc();
|
danielebarchiesi@0
|
252 $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
|
danielebarchiesi@0
|
253 $this->assertEqual($mapping, $stored_mapping, 'Mapping was stored properly in the {rdf_mapping} table.');
|
danielebarchiesi@0
|
254
|
danielebarchiesi@0
|
255 // Verify loading of saved mapping.
|
danielebarchiesi@0
|
256 $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Saved mapping loaded successfully.');
|
danielebarchiesi@0
|
257
|
danielebarchiesi@0
|
258 // Verify updating of mapping.
|
danielebarchiesi@0
|
259 $mapping['mapping']['title'] = array(
|
danielebarchiesi@0
|
260 'predicates' => array('dc2:bar2'),
|
danielebarchiesi@0
|
261 );
|
danielebarchiesi@0
|
262 $this->assertTrue(rdf_mapping_save($mapping) === SAVED_UPDATED, 'Mapping was updated.');
|
danielebarchiesi@0
|
263
|
danielebarchiesi@0
|
264 // Read the raw record from the {rdf_mapping} table.
|
danielebarchiesi@0
|
265 $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
|
danielebarchiesi@0
|
266 $stored_mapping = $result->fetchAssoc();
|
danielebarchiesi@0
|
267 $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
|
danielebarchiesi@0
|
268 $this->assertEqual($mapping, $stored_mapping, 'Updated mapping was stored properly in the {rdf_mapping} table.');
|
danielebarchiesi@0
|
269
|
danielebarchiesi@0
|
270 // Verify loading of saved mapping.
|
danielebarchiesi@0
|
271 $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Saved mapping loaded successfully.');
|
danielebarchiesi@0
|
272
|
danielebarchiesi@0
|
273 // Verify deleting of mapping.
|
danielebarchiesi@0
|
274 $this->assertTrue(rdf_mapping_delete($mapping['type'], $mapping['bundle']), 'Mapping was deleted.');
|
danielebarchiesi@0
|
275 $this->assertFalse(_rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Deleted mapping is no longer found in the database.');
|
danielebarchiesi@0
|
276 }
|
danielebarchiesi@0
|
277 }
|
danielebarchiesi@0
|
278
|
danielebarchiesi@0
|
279 class RdfMappingDefinitionTestCase extends TaxonomyWebTestCase {
|
danielebarchiesi@0
|
280 public static function getInfo() {
|
danielebarchiesi@0
|
281 return array(
|
danielebarchiesi@0
|
282 'name' => 'RDF mapping definition functionality',
|
danielebarchiesi@0
|
283 'description' => 'Test the different types of RDF mappings and ensure the proper RDFa markup in included in nodes and user profile pages.',
|
danielebarchiesi@0
|
284 'group' => 'RDF',
|
danielebarchiesi@0
|
285 );
|
danielebarchiesi@0
|
286 }
|
danielebarchiesi@0
|
287
|
danielebarchiesi@0
|
288 function setUp() {
|
danielebarchiesi@0
|
289 parent::setUp('rdf', 'rdf_test', 'blog');
|
danielebarchiesi@0
|
290 }
|
danielebarchiesi@0
|
291
|
danielebarchiesi@0
|
292 /**
|
danielebarchiesi@0
|
293 * Create a node of type blog and test whether the RDF mapping defined for
|
danielebarchiesi@0
|
294 * this node type in rdf_test.module is used in the node page.
|
danielebarchiesi@0
|
295 */
|
danielebarchiesi@0
|
296 function testAttributesInMarkup1() {
|
danielebarchiesi@0
|
297 $node = $this->drupalCreateNode(array('type' => 'blog'));
|
danielebarchiesi@0
|
298 $isoDate = date('c', $node->changed);
|
danielebarchiesi@0
|
299 $url = url('node/' . $node->nid);
|
danielebarchiesi@0
|
300 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
301
|
danielebarchiesi@0
|
302 // Ensure the default bundle mapping for node is used. These attributes come
|
danielebarchiesi@0
|
303 // from the node default bundle definition.
|
danielebarchiesi@0
|
304 $blog_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
|
danielebarchiesi@0
|
305 $blog_meta = $this->xpath("//div[(@about='$url') and (@typeof='sioct:Weblog')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']");
|
danielebarchiesi@0
|
306 $this->assertTrue(!empty($blog_title), 'Property dc:title is present in meta tag.');
|
danielebarchiesi@0
|
307 $this->assertTrue(!empty($blog_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
|
danielebarchiesi@0
|
308 }
|
danielebarchiesi@0
|
309
|
danielebarchiesi@0
|
310 /**
|
danielebarchiesi@0
|
311 * Create a content type and a node of type test_bundle_hook_install and test
|
danielebarchiesi@0
|
312 * whether the RDF mapping defined in rdf_test.install is used.
|
danielebarchiesi@0
|
313 */
|
danielebarchiesi@0
|
314 function testAttributesInMarkup2() {
|
danielebarchiesi@0
|
315 $type = $this->drupalCreateContentType(array('type' => 'test_bundle_hook_install'));
|
danielebarchiesi@0
|
316 $node = $this->drupalCreateNode(array('type' => 'test_bundle_hook_install'));
|
danielebarchiesi@0
|
317 $isoDate = date('c', $node->changed);
|
danielebarchiesi@0
|
318 $url = url('node/' . $node->nid);
|
danielebarchiesi@0
|
319 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
320
|
danielebarchiesi@0
|
321 // Ensure the mapping defined in rdf_module.test is used.
|
danielebarchiesi@0
|
322 $test_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
|
danielebarchiesi@0
|
323 $test_bundle_meta = $this->xpath("//div[(@about='$url') and contains(@typeof, 'foo:mapping_install1') and contains(@typeof, 'bar:mapping_install2')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']");
|
danielebarchiesi@0
|
324 $this->assertTrue(!empty($test_bundle_title), 'Property dc:title is present in meta tag.');
|
danielebarchiesi@0
|
325 $this->assertTrue(!empty($test_bundle_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
|
danielebarchiesi@0
|
326 }
|
danielebarchiesi@0
|
327
|
danielebarchiesi@0
|
328 /**
|
danielebarchiesi@0
|
329 * Create a random content type and node and ensure the default mapping for
|
danielebarchiesi@0
|
330 * node is used.
|
danielebarchiesi@0
|
331 */
|
danielebarchiesi@0
|
332 function testAttributesInMarkup3() {
|
danielebarchiesi@0
|
333 $type = $this->drupalCreateContentType();
|
danielebarchiesi@0
|
334 $node = $this->drupalCreateNode(array('type' => $type->type));
|
danielebarchiesi@0
|
335 $isoDate = date('c', $node->changed);
|
danielebarchiesi@0
|
336 $url = url('node/' . $node->nid);
|
danielebarchiesi@0
|
337 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
338
|
danielebarchiesi@0
|
339 // Ensure the default bundle mapping for node is used. These attributes come
|
danielebarchiesi@0
|
340 // from the node default bundle definition.
|
danielebarchiesi@0
|
341 $random_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
|
danielebarchiesi@0
|
342 $random_bundle_meta = $this->xpath("//div[(@about='$url') and contains(@typeof, 'sioc:Item') and contains(@typeof, 'foaf:Document')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']");
|
danielebarchiesi@0
|
343 $this->assertTrue(!empty($random_bundle_title), 'Property dc:title is present in meta tag.');
|
danielebarchiesi@0
|
344 $this->assertTrue(!empty($random_bundle_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
|
danielebarchiesi@0
|
345 }
|
danielebarchiesi@0
|
346
|
danielebarchiesi@0
|
347 /**
|
danielebarchiesi@0
|
348 * Create a random user and ensure the default mapping for user is used.
|
danielebarchiesi@0
|
349 */
|
danielebarchiesi@0
|
350 function testUserAttributesInMarkup() {
|
danielebarchiesi@0
|
351 // Create two users, one with access to user profiles.
|
danielebarchiesi@0
|
352 $user1 = $this->drupalCreateUser(array('access user profiles'));
|
danielebarchiesi@0
|
353 $user2 = $this->drupalCreateUser();
|
danielebarchiesi@0
|
354 $username = $user2->name;
|
danielebarchiesi@0
|
355 $this->drupalLogin($user1);
|
danielebarchiesi@0
|
356 // Browse to the user profile page.
|
danielebarchiesi@0
|
357 $this->drupalGet('user/' . $user2->uid);
|
danielebarchiesi@0
|
358 // Ensure the default bundle mapping for user is used on the user profile
|
danielebarchiesi@0
|
359 // page. These attributes come from the user default bundle definition.
|
danielebarchiesi@0
|
360 $account_uri = url('user/' . $user2->uid);
|
danielebarchiesi@0
|
361 $person_uri = url('user/' . $user2->uid, array('fragment' => 'me'));
|
danielebarchiesi@0
|
362
|
danielebarchiesi@0
|
363 $user2_profile_about = $this->xpath('//div[@class="profile" and @typeof="sioc:UserAccount" and @about=:account-uri]', array(
|
danielebarchiesi@0
|
364 ':account-uri' => $account_uri,
|
danielebarchiesi@0
|
365 ));
|
danielebarchiesi@0
|
366 $this->assertTrue(!empty($user2_profile_about), 'RDFa markup found on user profile page');
|
danielebarchiesi@0
|
367
|
danielebarchiesi@0
|
368 $user_account_holder = $this->xpath('//meta[contains(@typeof, "foaf:Person") and @about=:person-uri and @resource=:account-uri and contains(@rel, "foaf:account")]', array(
|
danielebarchiesi@0
|
369 ':person-uri' => $person_uri,
|
danielebarchiesi@0
|
370 ':account-uri' => $account_uri,
|
danielebarchiesi@0
|
371 ));
|
danielebarchiesi@0
|
372 $this->assertTrue(!empty($user_account_holder), 'URI created for account holder and username set on sioc:UserAccount.');
|
danielebarchiesi@0
|
373
|
danielebarchiesi@0
|
374 $user_username = $this->xpath('//meta[@about=:account-uri and contains(@property, "foaf:name") and @content=:username]', array(
|
danielebarchiesi@0
|
375 ':account-uri' => $account_uri,
|
danielebarchiesi@0
|
376 ':username' => $username,
|
danielebarchiesi@0
|
377 ));
|
danielebarchiesi@0
|
378 $this->assertTrue(!empty($user_username), 'foaf:name set on username.');
|
danielebarchiesi@0
|
379
|
danielebarchiesi@0
|
380 // User 2 creates node.
|
danielebarchiesi@0
|
381 $this->drupalLogin($user2);
|
danielebarchiesi@0
|
382 $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
383 $this->drupalLogin($user1);
|
danielebarchiesi@0
|
384 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
385 // Ensures the default bundle mapping for user is used on the Authored By
|
danielebarchiesi@0
|
386 // information on the node.
|
danielebarchiesi@0
|
387 $author_about = $this->xpath('//a[@typeof="sioc:UserAccount" and @about=:account-uri and @property="foaf:name" and @datatype="" and contains(@xml:lang, "")]', array(
|
danielebarchiesi@0
|
388 ':account-uri' => $account_uri,
|
danielebarchiesi@0
|
389 ));
|
danielebarchiesi@0
|
390 $this->assertTrue(!empty($author_about), 'RDFa markup found on author information on post. xml:lang on username is set to empty string.');
|
danielebarchiesi@0
|
391 }
|
danielebarchiesi@0
|
392
|
danielebarchiesi@0
|
393 /**
|
danielebarchiesi@0
|
394 * Creates a random term and ensures the right RDFa markup is used.
|
danielebarchiesi@0
|
395 */
|
danielebarchiesi@0
|
396 function testTaxonomyTermRdfaAttributes() {
|
danielebarchiesi@0
|
397 $vocabulary = $this->createVocabulary();
|
danielebarchiesi@0
|
398 $term = $this->createTerm($vocabulary);
|
danielebarchiesi@0
|
399
|
danielebarchiesi@0
|
400 // Views the term and checks that the RDFa markup is correct.
|
danielebarchiesi@0
|
401 $this->drupalGet('taxonomy/term/' . $term->tid);
|
danielebarchiesi@0
|
402 $term_url = url('taxonomy/term/' . $term->tid);
|
danielebarchiesi@0
|
403 $term_name = $term->name;
|
danielebarchiesi@0
|
404 $term_rdfa_meta = $this->xpath('//meta[@typeof="skos:Concept" and @about=:term-url and contains(@property, "rdfs:label") and contains(@property, "skos:prefLabel") and @content=:term-name]', array(
|
danielebarchiesi@0
|
405 ':term-url' => $term_url,
|
danielebarchiesi@0
|
406 ':term-name' => $term_name,
|
danielebarchiesi@0
|
407 ));
|
danielebarchiesi@0
|
408 $this->assertTrue(!empty($term_rdfa_meta), 'RDFa markup found on term page.');
|
danielebarchiesi@0
|
409 }
|
danielebarchiesi@0
|
410 }
|
danielebarchiesi@0
|
411
|
danielebarchiesi@0
|
412 class RdfCommentAttributesTestCase extends CommentHelperCase {
|
danielebarchiesi@0
|
413
|
danielebarchiesi@0
|
414 public static function getInfo() {
|
danielebarchiesi@0
|
415 return array(
|
danielebarchiesi@0
|
416 'name' => 'RDF comment mapping',
|
danielebarchiesi@0
|
417 'description' => 'Tests the RDFa markup of comments.',
|
danielebarchiesi@0
|
418 'group' => 'RDF',
|
danielebarchiesi@0
|
419 );
|
danielebarchiesi@0
|
420 }
|
danielebarchiesi@0
|
421
|
danielebarchiesi@0
|
422 public function setUp() {
|
danielebarchiesi@0
|
423 parent::setUp('comment', 'rdf', 'rdf_test');
|
danielebarchiesi@0
|
424
|
danielebarchiesi@0
|
425 $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions', 'administer blocks'));
|
danielebarchiesi@0
|
426 $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'access user profiles'));
|
danielebarchiesi@0
|
427
|
danielebarchiesi@0
|
428 // Enables anonymous user comments.
|
danielebarchiesi@0
|
429 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
430 'access comments' => TRUE,
|
danielebarchiesi@0
|
431 'post comments' => TRUE,
|
danielebarchiesi@0
|
432 'skip comment approval' => TRUE,
|
danielebarchiesi@0
|
433 ));
|
danielebarchiesi@0
|
434 // Allows anonymous to leave their contact information.
|
danielebarchiesi@0
|
435 $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
|
danielebarchiesi@0
|
436 $this->setCommentPreview(DRUPAL_OPTIONAL);
|
danielebarchiesi@0
|
437 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
438 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
439 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
440
|
danielebarchiesi@0
|
441 // Creates the nodes on which the test comments will be posted.
|
danielebarchiesi@0
|
442 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
443 $this->node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
444 $this->node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
445 $this->drupalLogout();
|
danielebarchiesi@0
|
446 }
|
danielebarchiesi@0
|
447
|
danielebarchiesi@0
|
448 /**
|
danielebarchiesi@0
|
449 * Tests the presence of the RDFa markup for the number of comments.
|
danielebarchiesi@0
|
450 */
|
danielebarchiesi@0
|
451 public function testNumberOfCommentsRdfaMarkup() {
|
danielebarchiesi@0
|
452 // Posts 2 comments as a registered user.
|
danielebarchiesi@0
|
453 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
454 $this->postComment($this->node1, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
455 $this->postComment($this->node1, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
456
|
danielebarchiesi@0
|
457 // Tests number of comments in teaser view.
|
danielebarchiesi@0
|
458 $this->drupalGet('node');
|
danielebarchiesi@0
|
459 $comment_count_teaser = $this->xpath('//div[contains(@typeof, "sioc:Item")]//li[contains(@class, "comment-comments")]/a[contains(@property, "sioc:num_replies") and contains(@content, "2") and @datatype="xsd:integer"]');
|
danielebarchiesi@0
|
460 $this->assertTrue(!empty($comment_count_teaser), 'RDFa markup for the number of comments found on teaser view.');
|
danielebarchiesi@0
|
461 $comment_count_link = $this->xpath('//div[@about=:url]//a[contains(@property, "sioc:num_replies") and @rel=""]', array(':url' => url("node/{$this->node1->nid}")));
|
danielebarchiesi@0
|
462 $this->assertTrue(!empty($comment_count_link), 'Empty rel attribute found in comment count link.');
|
danielebarchiesi@0
|
463
|
danielebarchiesi@0
|
464 // Tests number of comments in full node view.
|
danielebarchiesi@0
|
465 $this->drupalGet('node/' . $this->node1->nid);
|
danielebarchiesi@0
|
466 $node_url = url('node/' . $this->node1->nid);
|
danielebarchiesi@0
|
467 $comment_count_teaser = $this->xpath('/html/head/meta[@about=:node-url and @property="sioc:num_replies" and @content="2" and @datatype="xsd:integer"]', array(':node-url' => $node_url));
|
danielebarchiesi@0
|
468 $this->assertTrue(!empty($comment_count_teaser), 'RDFa markup for the number of comments found on full node view.');
|
danielebarchiesi@0
|
469 }
|
danielebarchiesi@0
|
470
|
danielebarchiesi@0
|
471 /**
|
danielebarchiesi@0
|
472 * Tests the presence of the RDFa markup for the title, date and author and
|
danielebarchiesi@0
|
473 * homepage on registered users and anonymous comments.
|
danielebarchiesi@0
|
474 */
|
danielebarchiesi@0
|
475 public function testCommentRdfaMarkup() {
|
danielebarchiesi@0
|
476
|
danielebarchiesi@0
|
477 // Posts comment #1 as a registered user.
|
danielebarchiesi@0
|
478 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
479 $comment1_subject = $this->randomName();
|
danielebarchiesi@0
|
480 $comment1_body = $this->randomName();
|
danielebarchiesi@0
|
481 $comment1 = $this->postComment($this->node1, $comment1_body, $comment1_subject);
|
danielebarchiesi@0
|
482
|
danielebarchiesi@0
|
483 // Tests comment #1 with access to the user profile.
|
danielebarchiesi@0
|
484 $this->drupalGet('node/' . $this->node1->nid);
|
danielebarchiesi@0
|
485 $this->_testBasicCommentRdfaMarkup($comment1);
|
danielebarchiesi@0
|
486
|
danielebarchiesi@0
|
487 // Tests comment #1 with no access to the user profile (as anonymous user).
|
danielebarchiesi@0
|
488 $this->drupalLogout();
|
danielebarchiesi@0
|
489 $this->drupalGet('node/' . $this->node1->nid);
|
danielebarchiesi@0
|
490 $this->_testBasicCommentRdfaMarkup($comment1);
|
danielebarchiesi@0
|
491
|
danielebarchiesi@0
|
492 // Posts comment #2 as anonymous user.
|
danielebarchiesi@0
|
493 $comment2_subject = $this->randomName();
|
danielebarchiesi@0
|
494 $comment2_body = $this->randomName();
|
danielebarchiesi@0
|
495 $anonymous_user = array();
|
danielebarchiesi@0
|
496 $anonymous_user['name'] = $this->randomName();
|
danielebarchiesi@0
|
497 $anonymous_user['mail'] = 'tester@simpletest.org';
|
danielebarchiesi@0
|
498 $anonymous_user['homepage'] = 'http://example.org/';
|
danielebarchiesi@0
|
499 $comment2 = $this->postComment($this->node2, $comment2_body, $comment2_subject, $anonymous_user);
|
danielebarchiesi@0
|
500 $this->drupalGet('node/' . $this->node2->nid);
|
danielebarchiesi@0
|
501
|
danielebarchiesi@0
|
502 // Tests comment #2 as anonymous user.
|
danielebarchiesi@0
|
503 $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
|
danielebarchiesi@0
|
504 // Tests the RDFa markup for the homepage (specific to anonymous comments).
|
danielebarchiesi@0
|
505 $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[contains(@class, "username") and @typeof="sioc:UserAccount" and @property="foaf:name" and @datatype="" and @href="http://example.org/" and contains(@rel, "foaf:page")]');
|
danielebarchiesi@0
|
506 $this->assertTrue(!empty($comment_homepage), 'RDFa markup for the homepage of anonymous user found.');
|
danielebarchiesi@0
|
507 // There should be no about attribute on anonymous comments.
|
danielebarchiesi@0
|
508 $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]');
|
danielebarchiesi@0
|
509 $this->assertTrue(empty($comment_homepage), 'No about attribute is present on anonymous user comment.');
|
danielebarchiesi@0
|
510
|
danielebarchiesi@0
|
511 // Tests comment #2 as logged in user.
|
danielebarchiesi@0
|
512 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
513 $this->drupalGet('node/' . $this->node2->nid);
|
danielebarchiesi@0
|
514 $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
|
danielebarchiesi@0
|
515 // Tests the RDFa markup for the homepage (specific to anonymous comments).
|
danielebarchiesi@0
|
516 $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[contains(@class, "username") and @typeof="sioc:UserAccount" and @property="foaf:name" and @datatype="" and @href="http://example.org/" and contains(@rel, "foaf:page")]');
|
danielebarchiesi@0
|
517 $this->assertTrue(!empty($comment_homepage), "RDFa markup for the homepage of anonymous user found.");
|
danielebarchiesi@0
|
518 // There should be no about attribute on anonymous comments.
|
danielebarchiesi@0
|
519 $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]');
|
danielebarchiesi@0
|
520 $this->assertTrue(empty($comment_homepage), "No about attribute is present on anonymous user comment.");
|
danielebarchiesi@0
|
521 }
|
danielebarchiesi@0
|
522
|
danielebarchiesi@0
|
523 /**
|
danielebarchiesi@0
|
524 * Test RDF comment replies.
|
danielebarchiesi@0
|
525 */
|
danielebarchiesi@0
|
526 public function testCommentReplyOfRdfaMarkup() {
|
danielebarchiesi@0
|
527 // Posts comment #1 as a registered user.
|
danielebarchiesi@0
|
528 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
529 $comments[] = $this->postComment($this->node1, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
530
|
danielebarchiesi@0
|
531 // Tests the reply_of relationship of a first level comment.
|
danielebarchiesi@0
|
532 $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=1]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
|
danielebarchiesi@0
|
533 $this->assertEqual(1, count($result), 'RDFa markup referring to the node is present.');
|
danielebarchiesi@0
|
534 $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=1]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1')));
|
danielebarchiesi@0
|
535 $this->assertFalse($result, 'No RDFa markup referring to the comment itself is present.');
|
danielebarchiesi@0
|
536
|
danielebarchiesi@0
|
537 // Posts a reply to the first comment.
|
danielebarchiesi@0
|
538 $this->drupalGet('comment/reply/' . $this->node1->nid . '/' . $comments[0]->id);
|
danielebarchiesi@0
|
539 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
540
|
danielebarchiesi@0
|
541 // Tests the reply_of relationship of a second level comment.
|
danielebarchiesi@0
|
542 $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
|
danielebarchiesi@0
|
543 $this->assertEqual(1, count($result), 'RDFa markup referring to the node is present.');
|
danielebarchiesi@0
|
544 $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1', array('fragment' => 'comment-1'))));
|
danielebarchiesi@0
|
545 $this->assertEqual(1, count($result), 'RDFa markup referring to the parent comment is present.');
|
danielebarchiesi@0
|
546 $comments = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]");
|
danielebarchiesi@0
|
547 }
|
danielebarchiesi@0
|
548
|
danielebarchiesi@0
|
549 /**
|
danielebarchiesi@0
|
550 * Helper function for testCommentRdfaMarkup().
|
danielebarchiesi@0
|
551 *
|
danielebarchiesi@0
|
552 * Tests the current page for basic comment RDFa markup.
|
danielebarchiesi@0
|
553 *
|
danielebarchiesi@0
|
554 * @param $comment
|
danielebarchiesi@0
|
555 * Comment object.
|
danielebarchiesi@0
|
556 * @param $account
|
danielebarchiesi@0
|
557 * An array containing information about an anonymous user.
|
danielebarchiesi@0
|
558 */
|
danielebarchiesi@0
|
559 function _testBasicCommentRdfaMarkup($comment, $account = array()) {
|
danielebarchiesi@0
|
560 $comment_container = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]');
|
danielebarchiesi@0
|
561 $this->assertTrue(!empty($comment_container), "Comment RDF type for comment found.");
|
danielebarchiesi@0
|
562 $comment_title = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//h3[@property="dc:title"]');
|
danielebarchiesi@0
|
563 $this->assertEqual((string)$comment_title[0]->a, $comment->subject, "RDFa markup for the comment title found.");
|
danielebarchiesi@0
|
564 $comment_date = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//*[contains(@property, "dc:date") and contains(@property, "dc:created")]');
|
danielebarchiesi@0
|
565 $this->assertTrue(!empty($comment_date), "RDFa markup for the date of the comment found.");
|
danielebarchiesi@0
|
566 // The author tag can be either a or span
|
danielebarchiesi@0
|
567 $comment_author = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/*[contains(@class, "username") and @typeof="sioc:UserAccount" and @property="foaf:name" and @datatype=""]');
|
danielebarchiesi@0
|
568 $name = empty($account["name"]) ? $this->web_user->name : $account["name"] . " (not verified)";
|
danielebarchiesi@0
|
569 $this->assertEqual((string)$comment_author[0], $name, "RDFa markup for the comment author found.");
|
danielebarchiesi@0
|
570 $comment_body = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//div[@class="content"]//div[contains(@class, "comment-body")]//div[@property="content:encoded"]');
|
danielebarchiesi@0
|
571 $this->assertEqual((string)$comment_body[0]->p, $comment->comment, "RDFa markup for the comment body found.");
|
danielebarchiesi@0
|
572 }
|
danielebarchiesi@0
|
573 }
|
danielebarchiesi@0
|
574
|
danielebarchiesi@0
|
575 class RdfTrackerAttributesTestCase extends DrupalWebTestCase {
|
danielebarchiesi@0
|
576 public static function getInfo() {
|
danielebarchiesi@0
|
577 return array(
|
danielebarchiesi@0
|
578 'name' => 'RDF tracker page mapping',
|
danielebarchiesi@0
|
579 'description' => 'Test the mapping for the tracker page and ensure the proper RDFa markup in included.',
|
danielebarchiesi@0
|
580 'group' => 'RDF',
|
danielebarchiesi@0
|
581 );
|
danielebarchiesi@0
|
582 }
|
danielebarchiesi@0
|
583
|
danielebarchiesi@0
|
584 function setUp() {
|
danielebarchiesi@0
|
585 parent::setUp('rdf', 'rdf_test', 'tracker');
|
danielebarchiesi@0
|
586 // Enable anonymous posting of content.
|
danielebarchiesi@0
|
587 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
588 'create article content' => TRUE,
|
danielebarchiesi@0
|
589 'access comments' => TRUE,
|
danielebarchiesi@0
|
590 'post comments' => TRUE,
|
danielebarchiesi@0
|
591 'skip comment approval' => TRUE,
|
danielebarchiesi@0
|
592 ));
|
danielebarchiesi@0
|
593 }
|
danielebarchiesi@0
|
594
|
danielebarchiesi@0
|
595 /**
|
danielebarchiesi@0
|
596 * Create nodes as both admin and anonymous user and test for correct RDFa
|
danielebarchiesi@0
|
597 * markup on the tracker page for those nodes and their comments.
|
danielebarchiesi@0
|
598 */
|
danielebarchiesi@0
|
599 function testAttributesInTracker() {
|
danielebarchiesi@0
|
600 // Create node as anonymous user.
|
danielebarchiesi@0
|
601 $node_anon = $this->drupalCreateNode(array('type' => 'article', 'uid' => 0));
|
danielebarchiesi@0
|
602 // Create node as admin user.
|
danielebarchiesi@0
|
603 $node_admin = $this->drupalCreateNode(array('type' => 'article', 'uid' => 1));
|
danielebarchiesi@0
|
604
|
danielebarchiesi@0
|
605 // Pass both the anonymously posted node and the administrator posted node
|
danielebarchiesi@0
|
606 // through to test for the RDF attributes.
|
danielebarchiesi@0
|
607 $this->_testBasicTrackerRdfaMarkup($node_anon);
|
danielebarchiesi@0
|
608 $this->_testBasicTrackerRdfaMarkup($node_admin);
|
danielebarchiesi@0
|
609
|
danielebarchiesi@0
|
610 }
|
danielebarchiesi@0
|
611
|
danielebarchiesi@0
|
612 /**
|
danielebarchiesi@0
|
613 * Helper function for testAttributesInTracker().
|
danielebarchiesi@0
|
614 *
|
danielebarchiesi@0
|
615 * Tests the tracker page for RDFa markup.
|
danielebarchiesi@0
|
616 *
|
danielebarchiesi@0
|
617 * @param $node
|
danielebarchiesi@0
|
618 * The node just created.
|
danielebarchiesi@0
|
619 */
|
danielebarchiesi@0
|
620 function _testBasicTrackerRdfaMarkup($node) {
|
danielebarchiesi@0
|
621 $url = url('node/' . $node->nid);
|
danielebarchiesi@0
|
622
|
danielebarchiesi@0
|
623 $user = ($node->uid == 0) ? 'Anonymous user' : 'Registered user';
|
danielebarchiesi@0
|
624
|
danielebarchiesi@0
|
625 // Navigate to tracker page.
|
danielebarchiesi@0
|
626 $this->drupalGet('tracker');
|
danielebarchiesi@0
|
627
|
danielebarchiesi@0
|
628 // Tests whether the about property is applied. This is implicit in the
|
danielebarchiesi@0
|
629 // success of the following tests, but making it explicit will make
|
danielebarchiesi@0
|
630 // debugging easier in case of failure.
|
danielebarchiesi@0
|
631 $tracker_about = $this->xpath('//tr[@about=:url]', array(':url' => $url));
|
danielebarchiesi@0
|
632 $this->assertTrue(!empty($tracker_about), format_string('About attribute found on table row for @user content.', array('@user'=> $user)));
|
danielebarchiesi@0
|
633
|
danielebarchiesi@0
|
634 // Tests whether the title has the correct property attribute.
|
danielebarchiesi@0
|
635 $tracker_title = $this->xpath('//tr[@about=:url]/td[@property="dc:title" and @datatype=""]', array(':url' => $url));
|
danielebarchiesi@0
|
636 $this->assertTrue(!empty($tracker_title), format_string('Title property attribute found on @user content.', array('@user'=> $user)));
|
danielebarchiesi@0
|
637
|
danielebarchiesi@0
|
638 // Tests whether the relationship between the content and user has been set.
|
danielebarchiesi@0
|
639 $tracker_user = $this->xpath('//tr[@about=:url]//td[contains(@rel, "sioc:has_creator")]//*[contains(@typeof, "sioc:UserAccount") and contains(@property, "foaf:name")]', array(':url' => $url));
|
danielebarchiesi@0
|
640 $this->assertTrue(!empty($tracker_user), format_string('Typeof and name property attributes found on @user.', array('@user'=> $user)));
|
danielebarchiesi@0
|
641 // There should be an about attribute on logged in users and no about
|
danielebarchiesi@0
|
642 // attribute for anonymous users.
|
danielebarchiesi@0
|
643 $tracker_user = $this->xpath('//tr[@about=:url]//td[@rel="sioc:has_creator"]/*[@about]', array(':url' => $url));
|
danielebarchiesi@0
|
644 if ($node->uid == 0) {
|
danielebarchiesi@0
|
645 $this->assertTrue(empty($tracker_user), format_string('No about attribute is present on @user.', array('@user'=> $user)));
|
danielebarchiesi@0
|
646 }
|
danielebarchiesi@0
|
647 elseif ($node->uid > 0) {
|
danielebarchiesi@0
|
648 $this->assertTrue(!empty($tracker_user), format_string('About attribute is present on @user.', array('@user'=> $user)));
|
danielebarchiesi@0
|
649 }
|
danielebarchiesi@0
|
650
|
danielebarchiesi@0
|
651 // Tests whether the property has been set for number of comments.
|
danielebarchiesi@0
|
652 $tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "0") and @datatype="xsd:integer"]', array(':url' => $url));
|
danielebarchiesi@0
|
653 $this->assertTrue($tracker_replies, format_string('Num replies property and content attributes found on @user content.', array('@user'=> $user)));
|
danielebarchiesi@0
|
654
|
danielebarchiesi@0
|
655 // Tests that the appropriate RDFa markup to annotate the latest activity
|
danielebarchiesi@0
|
656 // date has been added to the tracker output before comments have been
|
danielebarchiesi@0
|
657 // posted, meaning the latest activity reflects changes to the node itself.
|
danielebarchiesi@0
|
658 $isoDate = date('c', $node->changed);
|
danielebarchiesi@0
|
659 $tracker_activity = $this->xpath('//tr[@about=:url]//td[contains(@property, "dc:modified") and contains(@property, "sioc:last_activity_date") and contains(@datatype, "xsd:dateTime") and @content=:date]', array(':url' => $url, ':date' => $isoDate));
|
danielebarchiesi@0
|
660 $this->assertTrue(!empty($tracker_activity), format_string('Latest activity date and changed properties found when there are no comments on @user content. Latest activity date content is correct.', array('@user'=> $user)));
|
danielebarchiesi@0
|
661
|
danielebarchiesi@0
|
662 // Tests that the appropriate RDFa markup to annotate the latest activity
|
danielebarchiesi@0
|
663 // date has been added to the tracker output after a comment is posted.
|
danielebarchiesi@0
|
664 $comment = array(
|
danielebarchiesi@0
|
665 'subject' => $this->randomName(),
|
danielebarchiesi@0
|
666 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(),
|
danielebarchiesi@0
|
667 );
|
danielebarchiesi@0
|
668 $this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
|
danielebarchiesi@0
|
669 $this->drupalGet('tracker');
|
danielebarchiesi@0
|
670
|
danielebarchiesi@0
|
671 // Tests whether the property has been set for number of comments.
|
danielebarchiesi@0
|
672 $tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "1") and @datatype="xsd:integer"]', array(':url' => $url));
|
danielebarchiesi@0
|
673 $this->assertTrue($tracker_replies, format_string('Num replies property and content attributes found on @user content.', array('@user'=> $user)));
|
danielebarchiesi@0
|
674
|
danielebarchiesi@0
|
675 // Need to query database directly to obtain last_activity_date because
|
danielebarchiesi@0
|
676 // it cannot be accessed via node_load().
|
danielebarchiesi@0
|
677 $result = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid));
|
danielebarchiesi@0
|
678 foreach ($result as $node) {
|
danielebarchiesi@0
|
679 $expected_last_activity_date = $node->changed;
|
danielebarchiesi@0
|
680 }
|
danielebarchiesi@0
|
681 $isoDate = date('c', $expected_last_activity_date);
|
danielebarchiesi@0
|
682 $tracker_activity = $this->xpath('//tr[@about=:url]//td[@property="sioc:last_activity_date" and @datatype="xsd:dateTime" and @content=:date]', array(':url' => $url, ':date' => $isoDate));
|
danielebarchiesi@0
|
683 $this->assertTrue(!empty($tracker_activity), format_string('Latest activity date found when there are comments on @user content. Latest activity date content is correct.', array('@user'=> $user)));
|
danielebarchiesi@0
|
684 }
|
danielebarchiesi@0
|
685 }
|
danielebarchiesi@0
|
686
|
danielebarchiesi@0
|
687 /**
|
danielebarchiesi@0
|
688 * Tests for RDF namespaces declaration with hook_rdf_namespaces().
|
danielebarchiesi@0
|
689 */
|
danielebarchiesi@0
|
690 class RdfGetRdfNamespacesTestCase extends DrupalWebTestCase {
|
danielebarchiesi@0
|
691 public static function getInfo() {
|
danielebarchiesi@0
|
692 return array(
|
danielebarchiesi@0
|
693 'name' => 'RDF namespaces',
|
danielebarchiesi@0
|
694 'description' => 'Test hook_rdf_namespaces() and ensure only "safe" namespaces are returned.',
|
danielebarchiesi@0
|
695 'group' => 'RDF',
|
danielebarchiesi@0
|
696 );
|
danielebarchiesi@0
|
697 }
|
danielebarchiesi@0
|
698
|
danielebarchiesi@0
|
699 function setUp() {
|
danielebarchiesi@0
|
700 parent::setUp('rdf', 'rdf_test');
|
danielebarchiesi@0
|
701 }
|
danielebarchiesi@0
|
702
|
danielebarchiesi@0
|
703 /**
|
danielebarchiesi@0
|
704 * Test getting RDF namesapces.
|
danielebarchiesi@0
|
705 */
|
danielebarchiesi@0
|
706 function testGetRdfNamespaces() {
|
danielebarchiesi@0
|
707 // Get all RDF namespaces.
|
danielebarchiesi@0
|
708 $ns = rdf_get_namespaces();
|
danielebarchiesi@0
|
709
|
danielebarchiesi@0
|
710 $this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.');
|
danielebarchiesi@0
|
711 $this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.');
|
danielebarchiesi@0
|
712 $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.');
|
danielebarchiesi@0
|
713 $this->assertTrue(!isset($ns['dc']), 'A prefix with conflicting namespaces is discarded.');
|
danielebarchiesi@0
|
714 }
|
danielebarchiesi@0
|
715 }
|