summaryrefslogtreecommitdiff
path: root/modules/rdf
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-04-22 21:41:09 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-04-22 21:41:09 +0000
commitcca6d06c01e377975e8625b6743d069e08b38684 (patch)
tree77eda58d8cbf06a52125399f5c586c30988a902c /modules/rdf
parent164b9a3268e20c7e9ee792009ea5ee803f592bd4 (diff)
downloadbrdo-cca6d06c01e377975e8625b6743d069e08b38684.tar.gz
brdo-cca6d06c01e377975e8625b6743d069e08b38684.tar.bz2
#721082 by scor, linclark: Fixed Prevent conflicting namespaces and move hook_rdf_namespaces() invocation into rdf.module.
Diffstat (limited to 'modules/rdf')
-rw-r--r--modules/rdf/rdf.module26
-rw-r--r--modules/rdf/rdf.test37
-rw-r--r--modules/rdf/tests/rdf_test.module11
3 files changed, 72 insertions, 2 deletions
diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module
index b7d5b4884..4602fae17 100644
--- a/modules/rdf/rdf.module
+++ b/modules/rdf/rdf.module
@@ -92,6 +92,32 @@ function rdf_rdf_namespaces() {
}
/**
+ * Returns an array of RDF namespaces defined via hook_rdf_namespaces().
+ */
+function rdf_get_namespaces() {
+ $rdf_namespaces = module_invoke_all('rdf_namespaces');
+ // module_invoke_all() uses array_merge_recursive() which might return nested
+ // arrays if several modules redefine the same prefix multiple times.
+ // We need to ensure the array of namespaces is flat and only contains
+ // strings as URIs.
+ foreach ($rdf_namespaces as $prefix => $uri) {
+ if (is_array($uri)) {
+ if (count(array_unique($uri)) == 1) {
+ // All namespaces declared for this prefix are the same, merge them all
+ // into a single namespace.
+ $rdf_namespaces[$prefix] = $uri[0];
+ }
+ else {
+ // There are conflicting namespaces for this prefix, do not include it
+ // in order to avoid asserting any inaccurate RDF statement.
+ unset($rdf_namespaces[$prefix]);
+ }
+ }
+ }
+ return $rdf_namespaces;
+}
+
+/**
* Returns the mapping for attributes of a given type/bundle pair.
*
* @param $type
diff --git a/modules/rdf/rdf.test b/modules/rdf/rdf.test
index 64f6fbd7a..127f6a40e 100644
--- a/modules/rdf/rdf.test
+++ b/modules/rdf/rdf.test
@@ -39,7 +39,10 @@ class RdfMappingHookTestCase extends DrupalWebTestCase {
}
}
-class RdfMarkupTestCase extends DrupalWebTestCase {
+/**
+ * Test RDFa markup generation.
+ */
+class RdfRdfaMarkupTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDFa markup',
@@ -55,7 +58,7 @@ class RdfMarkupTestCase extends DrupalWebTestCase {
/**
* Test rdf_rdfa_attributes().
*/
- function testDrupalRdfaAtributes() {
+ function testDrupalRdfaAttributes() {
// Same value as the one in the HTML tag (no callback function).
$expected_attributes = array(
'property' => array('dc:title'),
@@ -525,3 +528,33 @@ class RdfTrackerAttributesTestCase extends DrupalWebTestCase {
$this->assertTrue(!empty($tracker_activity), t('Latest activity date found when there are comments on @user content. Latest activity date content is correct.', array('@user'=> $user)));
}
}
+
+/**
+ * Tests for RDF namespaces declaration with hook_rdf_namespaces().
+ */
+class RdfGetRdfNamespacesTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDF namespaces',
+ 'description' => 'Test hook_rdf_namespaces() and ensure only "safe" namespaces are returned.',
+ 'group' => 'RDF',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('rdf', 'rdf_test');
+ }
+
+ /**
+ * Test getting RDF namesapces.
+ */
+ function testGetRdfNamespaces() {
+ // Get all RDF namespaces.
+ $ns = rdf_get_namespaces();
+
+ $this->assertEqual($ns['owl'], 'http://www.w3.org/2002/07/owl#', t('A prefix declared once is included.'));
+ $this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', t('The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'));
+ $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', t('Two prefixes can be assigned the same namespace.'));
+ $this->assertTrue(!isset($ns['dc']), t('A prefix with conflicting namespaces is discarded.'));
+ }
+}
diff --git a/modules/rdf/tests/rdf_test.module b/modules/rdf/tests/rdf_test.module
index dedd2fd80..0c8c3b2a1 100644
--- a/modules/rdf/tests/rdf_test.module
+++ b/modules/rdf/tests/rdf_test.module
@@ -54,3 +54,14 @@ function rdf_test_rdf_mapping() {
),
);
}
+
+/**
+ * Implements hook_rdf_namespaces().
+ */
+function rdf_test_rdf_namespaces() {
+ return array(
+ 'dc' => 'http://purl.org/conflicting/namespace',
+ 'foaf' => 'http://xmlns.com/foaf/0.1/',
+ 'foaf1' => 'http://xmlns.com/foaf/0.1/',
+ );
+}