Commit 8f21cc40 authored by webchick's avatar webchick

#493030 follow-up by sun: Clean-ups to RDF module.

parent 0fa300a6
......@@ -185,7 +185,7 @@ function blog_block_view($delta = '') {
}
/**
* Implementation of hook_rdf_mapping().
* Implements hook_rdf_mapping().
*/
function blog_rdf_mapping() {
return array(
......@@ -194,7 +194,7 @@ function blog_rdf_mapping() {
'bundle' => 'blog',
'mapping' => array(
'rdftype' => array('sioct:Weblog'),
)
),
),
);
}
}
......@@ -2496,7 +2496,7 @@ function comment_filter_format_delete($format, $fallback) {
}
/**
* Implementation of hook_rdf_mapping().
* Implements hook_rdf_mapping().
*/
function comment_rdf_mapping() {
return array(
......@@ -2505,7 +2505,7 @@ function comment_rdf_mapping() {
'bundle' => RDF_DEFAULT_BUNDLE,
'mapping' => array(
'rdftype' => array('sioct:Post'),
'title' => array(
'title' => array(
'predicates' => array('dc:title'),
),
'created' => array(
......@@ -2513,16 +2513,16 @@ function comment_rdf_mapping() {
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'body' => array(
'body' => array(
'predicates' => array('content:encoded'),
),
'pid' => array(
'pid' => array(
'predicates' => array('sioc:reply_of'),
),
'uid' => array(
'uid' => array(
'predicates' => array('sioc:has_creator'),
),
'name' => array(
'name' => array(
'predicates' => array('foaf:name'),
),
),
......
......@@ -865,8 +865,10 @@ class CommentRSSUnitTest extends CommentHelperCase {
}
}
class RdfaCommentTestCase extends CommentHelperCase {
/**
* Test RDFa markup for comments.
*/
class CommentRdfaTestCase extends CommentHelperCase {
public static function getInfo() {
return array(
'name' => 'RDFa comment markup',
......@@ -911,5 +913,4 @@ class RdfaCommentTestCase extends CommentHelperCase {
$comment_author = $this->xpath("//div[@typeof='sioct:Post']//*[contains(@property, 'foaf:name')]");
$this->assertEqual((string)$comment_author[0], $this->web_user->name);
}
}
......@@ -412,7 +412,7 @@ function forum_comment_update($comment) {
}
/**
* Implement forum_comment_unpublish() {
* Implements forum_comment_unpublish().
*/
function forum_comment_unpublish($comment) {
_forum_update_forum_index($comment->nid);
......@@ -1134,7 +1134,7 @@ function _forum_update_forum_index($nid) {
}
/**
* Implementation of hook_rdf_mapping().
* Implements hook_rdf_mapping().
*/
function forum_rdf_mapping() {
return array(
......@@ -1143,7 +1143,7 @@ function forum_rdf_mapping() {
'bundle' => 'forum',
'mapping' => array(
'rdftype' => array('sioct:Post', 'sioct:ForumTopic'),
'taxonomy_forums' => array(
'taxonomy_forums' => array(
'predicates' => array('sioc:has_container'),
'type' => 'rel',
),
......
......@@ -754,13 +754,7 @@ function node_type_set_defaults($info = array()) {
}
/**
* Define the default RDF mapping for the node entity type.
*
* These default mapping properties are used by rdf_save_mapping() to populate
* non-existing properties before they are saved to the database.
*
* @return
* A list of default mapping properties for the node entity type.
* Implements hook_rdf_mapping().
*/
function node_rdf_mapping() {
return array(
......@@ -769,7 +763,7 @@ function node_rdf_mapping() {
'bundle' => RDF_DEFAULT_BUNDLE,
'mapping' => array(
'rdftype' => array('sioc:Item', 'foaf:Document'),
'title' => array(
'title' => array(
'predicates' => array('dc:title'),
),
'created' => array(
......@@ -780,13 +774,13 @@ function node_rdf_mapping() {
'changed' => array(
'predicates' => array('dc:modified'),
),
'body' => array(
'body' => array(
'predicates' => array('content:encoded'),
),
'uid' => array(
'uid' => array(
'predicates' => array('sioc:has_creator'),
),
'name' => array(
'name' => array(
'predicates' => array('foaf:name'),
),
),
......
......@@ -12,30 +12,35 @@
*/
/**
* Allow modules to define RDF mappings for bundles.
* Allow modules to define RDF mappings for field bundles.
*
* Modules defining their own bundles can specify which RDF semantics should be
* used to annotate these bundles. These mappings are then used for automatic
* RDFa output in the HTML code.
* Modules defining their own field bundles can specify which RDF semantics
* should be used to annotate these bundles. These mappings are then used for
* automatic RDFa output in the HTML code.
*
* @return
* An array of mapping structures. Each mapping has three mandatory keys:
* - type: The name of an entity type.
* - bundle: The name of a bundle.
* - mapping: The mapping structure which applies to the entity type, bundle
* pair. A mapping structure is an array with keys corresponding to
* existing field instances in the bundle. Each field is then described in
* terms of RDF mapping. 'predicates' is an array of RDF predicates which
* describe the relation between the bundle (subject in RDF) and the value of
* the field (object in RDF), this value being either some text, another
* bundle or a URL in general. 'datatype' and 'callback' are used in RDFa to
* format data so that it's readable by machine: a typical example is a date
* which can be written in many different formats but should be translated
* into a uniform format for machine comsumption. 'type' is a string used to
* determine the type of RDFa markup which will be used in the final HTML
* output, depending on whether the RDF object is a literal text or another
* RDF resource. The 'rdftype' key is a special case which is used to define
* the type of the instance, its value shoud be an array of RDF classes.
* A list of mapping structures, where each mapping is an associative array:
* - type: The name of an entity type, e.g. 'node' or 'comment'.
* - bundle: The name of the bundle, e.g. 'blog', or RDF_DEFAULT_BUNDLE for
* default mappings.
* - mapping: The mapping structure which applies to the entity type and
* bundle. A mapping structure is an array with keys corresponding to
* existing field instances in the bundle. Each field is then described in
* terms of RDF mapping:
* - predicates: An array of RDF predicates which describe the relation
* between the bundle (RDF subject) and the value of the field (RDF
* object). This value is either some text, another bundle or a URL in
* general.
* - datatype: Is used along with 'callback' to format data so that it is
* readable by machine. A typical example is a date which can be written
* in many different formats but should be translated into a uniform
* format for machine comsumption.
* - callback: A function name to invoke for 'datatype'.
* - type: A string used to determine the type of RDFa markup which will be
* used in the final HTML output, depending on whether the RDF object is a
* literal text or another RDF resource.
* - rdftype: A special property used to define the type of the instance.
* Its value shoud be an array of RDF classes.
*/
function hook_rdf_mapping() {
return array(
......@@ -44,7 +49,7 @@ function hook_rdf_mapping() {
'bundle' => 'blog',
'mapping' => array(
'rdftype' => array('sioct:Weblog'),
'title' => array(
'title' => array(
'predicates' => array('dc:title'),
),
'created' => array(
......@@ -52,17 +57,17 @@ function hook_rdf_mapping() {
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'body' => array(
'body' => array(
'predicates' => array('content:encoded'),
),
'uid' => array(
'uid' => array(
'predicates' => array('sioc:has_creator'),
'type' => 'rel',
'type' => 'rel',
),
'name' => array(
'name' => array(
'predicates' => array('foaf:name'),
),
)
),
),
);
}
......
......@@ -43,8 +43,8 @@ function rdf_schema() {
* Implements hook_install().
*/
function rdf_install() {
// The installer does not trigger hook_modules_installed() so it needs to
// triggered programmatically on the modules which defined RDF mappings.
// The installer does not trigger hook_modules_installed(), so it needs to be
// triggered manually for modules defining RDF mappings.
$modules = module_implements('rdf_mapping');
rdf_modules_installed($modules);
}
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Tests for RDF functionality.
*/
class RdfMappingHookTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
......@@ -52,7 +57,7 @@ class RdfMarkupTestCase extends DrupalWebTestCase {
}
/**
* Test drupal_rdfa_attributes().
* Test rdf_rdfa_attributes().
*/
function testDrupalRdfaAtributes() {
$date = 1252750327;
......@@ -63,7 +68,7 @@ class RdfMarkupTestCase extends DrupalWebTestCase {
$expected_value = $isoDate;
$mapping = rdf_get_mapping('test_entity', 'test_bundle');
$attributes = drupal_rdfa_attributes($mapping['created'], $date);
$attributes = rdf_rdfa_attributes($mapping['created'], $date);
$this->assertEqual($expected_type, $attributes['datatype']);
$this->assertEqual($expected_property, $attributes['property']);
......@@ -85,42 +90,36 @@ class RdfCrudTestCase extends DrupalWebTestCase {
parent::setUp('rdf', 'rdf_test');
}
function testCreateReadUpdateWrite() {
/**
* Test inserting, loading, updating, and deleting RDF mappings.
*/
function testCRUD() {
$test_mapping = rdf_test_rdf_mapping();
$this->assertTrue(is_array(rdf_read_mapping('test_entity', 'test_bundle')));
$this->assertEqual(count(rdf_read_mapping('test_entity', 'test_bundle')), 0);
$this->assertEqual(
rdf_create_mapping('test_entity', 'test_bundle', $test_mapping[0]['mapping']),
$test_mapping[0]['mapping']
);
// Verify loading of a default mapping.
$this->assertFalse(count(rdf_mapping_load('test_entity', 'test_bundle')), t('Default mapping was found.'));
try {
rdf_create_mapping('test_entity', 'test_bundle', $test_mapping[0]['mapping']);
$this->fail('No Exception thrown when attempting to insert the same mapping another time.');
}
catch (Exception $e) {
$this->pass('Exception thrown when attempting to insert the same mapping another time.');
}
$this->assertEqual($test_mapping[0]['mapping'],
rdf_read_mapping('test_entity', 'test_bundle'));
$this->assertTrue(rdf_update_mapping('test_entity', 'test_bundle',
$test_mapping[1]['mapping']));
$this->assertEqual($test_mapping[1]['mapping'],
rdf_read_mapping('test_entity', 'test_bundle'));
$this->assertTrue(rdf_delete_mapping('test_entity', 'test_bundle'));
$this->assertFalse(rdf_read_mapping('test_entity', 'test_bundle'));
}
// 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.'));
function testSaveMapping() {
$test_mapping = rdf_test_rdf_mapping();
rdf_save_mapping($test_mapping[0]);
// 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.'));
$this->assertEqual($test_mapping[0]['mapping'],
rdf_read_mapping('test_entity', 'test_bundle'));
}
// 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 {
......@@ -156,7 +155,6 @@ class RdfMappingDefinitionTestCase extends DrupalWebTestCase {
// from the node default bundle definition.
$this->assertRaw('property="dc:title"');
$this->assertRaw('property="dc:date dc:created"');
}
/**
......
......@@ -21,6 +21,6 @@ function rdf_test_install() {
);
foreach ($rdf_mappings as $rdf_mapping) {
rdf_save_mapping($rdf_mapping);
rdf_mapping_save($rdf_mapping);
}
}
......@@ -3,16 +3,15 @@
/**
* @file
* Dummy module implementing RDF related hooks to test API interaction with
* the RDF module.
* Test API interaction with the RDF module.
*/
/**
* Implementation of hook_rdf_mapping().
* Implements hook_rdf_mapping().
*/
function rdf_test_rdf_mapping() {
return array(
0 => array(
array(
'type' => 'test_entity',
'bundle' => 'test_bundle',
'mapping' => array(
......@@ -33,12 +32,12 @@ function rdf_test_rdf_mapping() {
),
),
),
1 => array(
array(
'type' => 'node',
'bundle' => 'blog',
'mapping' => array(
'rdftype' => array('sioct:Weblog'),
)
),
),
);
}
......@@ -183,9 +183,8 @@ function default_install() {
),
),
);
foreach ($rdf_mappings as $rdf_mapping) {
rdf_save_mapping($rdf_mapping);
rdf_mapping_save($rdf_mapping);
}
// Default page to not be promoted and have comments disabled.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment