diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-14 06:31:45 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-14 06:31:45 +0000 |
commit | 2162877c177a3e41f8fe79bb3a234479ec066993 (patch) | |
tree | b1833946448c8b8d0177e6a27bddfb435aa590bb | |
parent | 811be8f77f021b4662899e253a9a6a1b46441c64 (diff) | |
download | brdo-2162877c177a3e41f8fe79bb3a234479ec066993.tar.gz brdo-2162877c177a3e41f8fe79bb3a234479ec066993.tar.bz2 |
#642122 by scor and Stefan Freudenberg: Allow for RDFa datatype attribute without callback function.
-rw-r--r-- | modules/rdf/rdf.module | 13 | ||||
-rw-r--r-- | modules/rdf/rdf.test | 61 | ||||
-rw-r--r-- | modules/rdf/tests/rdf_test.module | 13 |
3 files changed, 70 insertions, 17 deletions
diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module index 59dc541f9..aa7653d18 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 15c47000b..4b5ea2f5d 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 46144951b..dedd2fd80 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( |