diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module index 59dc541f9163a0a20c13a9bc029db0c57f1f05c0..aa7653d182e8715672561be748ac27229c762c23 100644 --- a/modules/rdf/rdf.module +++ b/modules/rdf/rdf.module @@ -236,14 +236,13 @@ function rdf_rdfa_attributes($mapping, $data = NULL) { // literal text. case 'property': $attributes['property'] = $mapping['predicates']; - if (isset($mapping['callback']) && isset($data)) { + // Convert $data to a specific format as per the callback function. + if (isset($data) && isset($mapping['callback']) && function_exists($mapping['callback'])) { $callback = $mapping['callback']; - if (function_exists($callback)) { - $attributes['content'] = $callback($data); - } - if (isset($mapping['datatype'])) { - $attributes['datatype'] = $mapping['datatype']; - } + $attributes['content'] = $callback($data); + } + if (isset($mapping['datatype'])) { + $attributes['datatype'] = $mapping['datatype']; } break; } diff --git a/modules/rdf/rdf.test b/modules/rdf/rdf.test index 15c47000bb2cf692b93560d177a12a3e01c47fd4..4b5ea2f5d008d01f563bdb6d8de7094fde551098 100644 --- a/modules/rdf/rdf.test +++ b/modules/rdf/rdf.test @@ -35,7 +35,7 @@ class RdfMappingHookTestCase extends DrupalWebTestCase { '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.')); + $this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), t('Mapping for uid is sioc:has_creator and dc:creator, and type is rel.')); $mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping'); $this->assertEqual($mapping, array(), t('Empty array returned when an entity type, bundle pair has no mapping.')); @@ -60,19 +60,60 @@ class RdfMarkupTestCase extends DrupalWebTestCase { * Test rdf_rdfa_attributes(). */ function testDrupalRdfaAtributes() { + // Same value as the one in the HTML tag (no callback function). + $expected_attributes = array( + 'property' => array('dc:title'), + ); + $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $attributes = rdf_rdfa_attributes($mapping['title']); + ksort($expected_attributes); + ksort($attributes); + $this->assertEqual($expected_attributes, $attributes); + + // Value different from the one in the HTML tag (callback function). $date = 1252750327; $isoDate = date('c', $date); - - $expected_type = 'xsd:dateTime'; - $expected_property = array('dc:created'); - $expected_value = $isoDate; - + $expected_attributes = array( + 'datatype' => 'xsd:dateTime', + 'property' => array('dc:created'), + 'content' => $isoDate, + ); $mapping = rdf_mapping_load('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']); + ksort($expected_attributes); + ksort($attributes); + $this->assertEqual($expected_attributes, $attributes); + + // Same value as the one in the HTML tag with datatype. + $expected_attributes = array( + 'datatype' => 'foo:bar1type', + 'property' => array('foo:bar1'), + ); + $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $attributes = rdf_rdfa_attributes($mapping['foobar1']); + ksort($expected_attributes); + ksort($attributes); + $this->assertEqual($expected_attributes, $attributes); + + // ObjectProperty mapping (rel). + $expected_attributes = array( + 'rel' => array('sioc:has_creator', 'dc:creator'), + ); + $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']); + ksort($expected_attributes); + ksort($attributes); + $this->assertEqual($expected_attributes, $attributes); + + // Inverse ObjectProperty mapping (rev). + $expected_attributes = array( + 'rev' => array('sioc:reply_of'), + ); + $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']); + ksort($expected_attributes); + ksort($attributes); + $this->assertEqual($expected_attributes, $attributes); } } diff --git a/modules/rdf/tests/rdf_test.module b/modules/rdf/tests/rdf_test.module index 46144951b15c16da5b83ff4a88573bd713fa679c..dedd2fd802f330b6d5f78c6353b01fc582159b43 100644 --- a/modules/rdf/tests/rdf_test.module +++ b/modules/rdf/tests/rdf_test.module @@ -26,10 +26,23 @@ function rdf_test_rdf_mapping() { ), 'uid' => array( 'predicates' => array('sioc:has_creator', 'dc:creator'), + 'type' => 'rel', ), 'foobar' => array( 'predicates' => array('foo:bar'), ), + 'foobar1' => array( + 'datatype' => 'foo:bar1type', + 'predicates' => array('foo:bar1'), + ), + 'foobar_objproperty1' => array( + 'predicates' => array('sioc:has_creator', 'dc:creator'), + 'type' => 'rel', + ), + 'foobar_objproperty2' => array( + 'predicates' => array('sioc:reply_of'), + 'type' => 'rev', + ), ), ), array(