summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/rdf
diff options
context:
space:
mode:
Diffstat (limited to 'kolab.org/www/drupal-7.26/modules/rdf')
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/rdf.api.php106
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/rdf.info12
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/rdf.install49
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/rdf.module878
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/rdf.test720
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.info12
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.install25
-rw-r--r--kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.module66
8 files changed, 1868 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/rdf.api.php b/kolab.org/www/drupal-7.26/modules/rdf/rdf.api.php
new file mode 100644
index 0000000..691f7ef
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/rdf.api.php
@@ -0,0 +1,106 @@
+<?php
+
+/**
+ * @file
+ * Hooks provided by the RDF module.
+ */
+
+/**
+ * @addtogroup hooks
+ * @{
+ */
+
+/**
+ * Allow modules to define RDF mappings for field bundles.
+ *
+ * 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
+ * A list of mapping structures, where each mapping is an associative array:
+ * - type: The name of an entity type (e.g., 'node', 'comment', and so on.)
+ * - bundle: The name of the bundle (e.g., 'page', '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 the 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 URI in
+ * general.
+ * - datatype: Is used along with 'callback' to format data so that it is
+ * readable by machines. A typical example is a date which can be written
+ * in many different formats but should be translated into a uniform
+ * format for machine consumption.
+ * - 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 should be an array of RDF classes.
+ *
+ * @ingroup rdf
+ */
+function hook_rdf_mapping() {
+ return array(
+ array(
+ 'type' => 'node',
+ 'bundle' => 'blog',
+ 'mapping' => array(
+ 'rdftype' => array('sioct:Weblog'),
+ 'title' => array(
+ 'predicates' => array('dc:title'),
+ ),
+ 'created' => array(
+ 'predicates' => array('dc:date', 'dc:created'),
+ 'datatype' => 'xsd:dateTime',
+ 'callback' => 'date_iso8601',
+ ),
+ 'body' => array(
+ 'predicates' => array('content:encoded'),
+ ),
+ 'uid' => array(
+ 'predicates' => array('sioc:has_creator'),
+ 'type' => 'rel',
+ ),
+ 'name' => array(
+ 'predicates' => array('foaf:name'),
+ ),
+ ),
+ ),
+ );
+}
+
+/**
+ * Allow modules to define namespaces for RDF mappings.
+ *
+ * Many common namespace prefixes are defined in rdf_rdf_namespaces(). However,
+ * if a module implements hook_rdf_mapping() and uses a prefix that is not
+ * defined in rdf_rdf_namespaces(), this hook should be used to define the new
+ * namespace prefix.
+ *
+ * @return
+ * An associative array of namespaces where the key is the namespace prefix
+ * and the value is the namespace URI.
+ *
+ * @ingroup rdf
+ */
+function hook_rdf_namespaces() {
+ return array(
+ 'content' => 'http://purl.org/rss/1.0/modules/content/',
+ 'dc' => 'http://purl.org/dc/terms/',
+ 'foaf' => 'http://xmlns.com/foaf/0.1/',
+ 'og' => 'http://ogp.me/ns#',
+ 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+ 'sioc' => 'http://rdfs.org/sioc/ns#',
+ 'sioct' => 'http://rdfs.org/sioc/types#',
+ 'skos' => 'http://www.w3.org/2004/02/skos/core#',
+ 'xsd' => 'http://www.w3.org/2001/XMLSchema#',
+ );
+}
+
+/**
+ * @} End of "addtogroup hooks".
+ */
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/rdf.info b/kolab.org/www/drupal-7.26/modules/rdf/rdf.info
new file mode 100644
index 0000000..ef16a42
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/rdf.info
@@ -0,0 +1,12 @@
+name = RDF
+description = Enriches your content with metadata to let other applications (e.g. search engines, aggregators) better understand its relationships and attributes.
+package = Core
+version = VERSION
+core = 7.x
+files[] = rdf.test
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/rdf.install b/kolab.org/www/drupal-7.26/modules/rdf/rdf.install
new file mode 100644
index 0000000..10d3f8d
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/rdf.install
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the rdf module.
+ */
+
+/**
+ * Implements hook_schema().
+ */
+function rdf_schema() {
+ $schema['rdf_mapping'] = array(
+ 'description' => 'Stores custom RDF mappings for user defined content types or overriden module-defined mappings',
+ 'fields' => array(
+ 'type' => array(
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'description' => 'The name of the entity type a mapping applies to (node, user, comment, etc.).',
+ ),
+ 'bundle' => array(
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => TRUE,
+ 'description' => 'The name of the bundle a mapping applies to.',
+ ),
+ 'mapping' => array(
+ 'description' => 'The serialized mapping of the bundle type and fields to RDF terms.',
+ 'type' => 'blob',
+ 'not null' => FALSE,
+ 'size' => 'big',
+ 'serialize' => TRUE,
+ ),
+ ),
+ 'primary key' => array('type', 'bundle'),
+ );
+
+ return $schema;
+}
+
+/**
+ * Implements hook_install().
+ */
+function rdf_install() {
+ // Collect any RDF mappings that were declared by modules installed before
+ // this one.
+ $modules = module_implements('rdf_mapping');
+ rdf_modules_installed($modules);
+}
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/rdf.module b/kolab.org/www/drupal-7.26/modules/rdf/rdf.module
new file mode 100644
index 0000000..877b598
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/rdf.module
@@ -0,0 +1,878 @@
+<?php
+
+/**
+ * @file
+ * Enables semantically enriched output for Drupal sites in the form of RDFa.
+ */
+
+/**
+ * Implements hook_help().
+ */
+function rdf_help($path, $arg) {
+ switch ($path) {
+ case 'admin/help#rdf':
+ $output = '';
+ $output .= '<h3>' . t('About') . '</h3>';
+ $output .= '<p>' . t('The RDF module enriches your content with metadata to let other applications (e.g., search engines, aggregators, and so on) better understand its relationships and attributes. This semantically enriched, machine-readable output for Drupal sites uses the <a href="@rdfa">RDFa specification</a> which allows RDF data to be embedded in HTML markup. Other modules can define mappings of their data to RDF terms, and the RDF module makes this RDF data available to the theme. The core Drupal modules define RDF mappings for their data model, and the core Drupal themes output this RDF metadata information along with the human-readable visual information. For more information, see the online handbook entry for <a href="@rdf">RDF module</a>.', array('@rdfa' => 'http://www.w3.org/TR/xhtml-rdfa-primer/', '@rdf' => 'http://drupal.org/documentation/modules/rdf')) . '</p>';
+ return $output;
+ }
+}
+
+/**
+ * @defgroup rdf RDF Mapping API
+ * @{
+ * Functions to describe entities and bundles in RDF.
+ *
+ * The RDF module introduces RDF and RDFa to Drupal. RDF is a W3C standard to
+ * describe structured data. RDF can be serialized as RDFa in XHTML attributes
+ * to augment visual data with machine-readable hints.
+ * @see http://www.w3.org/RDF/
+ * @see http://www.w3.org/TR/xhtml-rdfa-primer/
+ *
+ * Modules can provide mappings of their bundles' data and metadata to RDF
+ * classes and properties. This module takes care of injecting these mappings
+ * into variables available to theme functions and templates. All Drupal core
+ * themes are coded to be RDFa compatible.
+ *
+ * Example mapping from node.module:
+ * @code
+ * array(
+ * 'type' => 'node',
+ * 'bundle' => RDF_DEFAULT_BUNDLE,
+ * 'mapping' => array(
+ * 'rdftype' => array('sioc:Item', 'foaf:Document'),
+ * 'title' => array(
+ * 'predicates' => array('dc:title'),
+ * ),
+ * 'created' => array(
+ * 'predicates' => array('dc:date', 'dc:created'),
+ * 'datatype' => 'xsd:dateTime',
+ * 'callback' => 'date_iso8601',
+ * ),
+ * 'body' => array(
+ * 'predicates' => array('content:encoded'),
+ * ),
+ * 'uid' => array(
+ * 'predicates' => array('sioc:has_creator'),
+ * ),
+ * 'name' => array(
+ * 'predicates' => array('foaf:name'),
+ * ),
+ * ),
+ * );
+ * @endcode
+ */
+
+/**
+ * RDF bundle flag: Default bundle.
+ *
+ * Implementations of hook_rdf_mapping() should use this constant for the
+ * 'bundle' key when defining a default set of RDF mappings for an entity type.
+ * Each bundle will inherit the default mappings defined for the entity type
+ * unless the bundle defines its own specific mappings.
+ */
+define('RDF_DEFAULT_BUNDLE', '');
+
+/**
+ * Implements hook_rdf_namespaces().
+ */
+function rdf_rdf_namespaces() {
+ return array(
+ 'content' => 'http://purl.org/rss/1.0/modules/content/',
+ 'dc' => 'http://purl.org/dc/terms/',
+ 'foaf' => 'http://xmlns.com/foaf/0.1/',
+ 'og' => 'http://ogp.me/ns#',
+ 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+ 'sioc' => 'http://rdfs.org/sioc/ns#',
+ 'sioct' => 'http://rdfs.org/sioc/types#',
+ 'skos' => 'http://www.w3.org/2004/02/skos/core#',
+ 'xsd' => 'http://www.w3.org/2001/XMLSchema#',
+ );
+}
+
+/**
+ * Returns an array of RDF namespaces defined in modules that implement
+ * 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
+ // duplicates in order to avoid asserting any inaccurate RDF
+ // statements.
+ unset($rdf_namespaces[$prefix]);
+ }
+ }
+ }
+ return $rdf_namespaces;
+}
+
+/**
+ * Returns the mapping for attributes of a given entity type/bundle pair.
+ *
+ * @param $type
+ * An entity type.
+ * @param $bundle
+ * (optional) A bundle name.
+ *
+ * @return
+ * The mapping corresponding to the requested entity type/bundle pair or an
+ * empty array.
+ */
+function rdf_mapping_load($type, $bundle = RDF_DEFAULT_BUNDLE) {
+ // Retrieves the bundle-specific mapping from the entity info.
+ $entity_info = entity_get_info($type);
+ if (!empty($entity_info['bundles'][$bundle]['rdf_mapping'])) {
+ return $entity_info['bundles'][$bundle]['rdf_mapping'];
+ }
+ // If there is no mapping defined for this bundle, we return the default
+ // mapping that is defined for this entity type.
+ else {
+ return _rdf_get_default_mapping($type);
+ }
+}
+
+/**
+ * @} End of "defgroup rdf".
+ */
+
+/**
+ * Helper function to get the default RDF mapping for a given entity type.
+ *
+ * @param $type
+ * An entity type, e.g. 'node' or 'comment'.
+ *
+ * @return
+ * The RDF mapping or an empty array if no mapping is defined for this entity
+ * type.
+ */
+function _rdf_get_default_mapping($type) {
+ $default_mappings = &drupal_static(__FUNCTION__);
+
+ if (!isset($default_mappings)) {
+ // Get all of the modules that implement hook_rdf_mapping().
+ $modules = module_implements('rdf_mapping');
+
+ // Only consider the default entity mapping definitions.
+ foreach ($modules as $module) {
+ $mappings = module_invoke($module, 'rdf_mapping');
+ foreach ($mappings as $mapping) {
+ if ($mapping['bundle'] === RDF_DEFAULT_BUNDLE) {
+ $default_mappings[$mapping['type']] = $mapping['mapping'];
+ }
+ }
+ }
+ }
+
+ return isset($default_mappings[$type]) ? $default_mappings[$type] : array();
+}
+
+/**
+ * Helper function to retrieve an RDF mapping from the database.
+ *
+ * @param $type
+ * The entity type the mapping refers to.
+ * @param $bundle
+ * The bundle the mapping refers to.
+ *
+ * @return
+ * An RDF mapping structure or an empty array if no record was found.
+ */
+function _rdf_mapping_load($type, $bundle) {
+ $mapping = db_select('rdf_mapping')
+ ->fields(NULL, array('mapping'))
+ ->condition('type', $type)
+ ->condition('bundle', $bundle)
+ ->execute()
+ ->fetchField();
+
+ if (!$mapping) {
+ return array();
+ }
+ return unserialize($mapping);
+}
+
+/**
+ * @addtogroup rdf
+ * @{
+ */
+
+/**
+ * Saves an RDF mapping to the database.
+ *
+ * Takes a mapping structure returned by hook_rdf_mapping() implementations
+ * and creates or updates a record mapping for each encountered entity
+ * type/bundle pair. If available, adds default values for non-existent mapping
+ * keys.
+ *
+ * @param $mapping
+ * The RDF mapping to save, as an array.
+ *
+ * @return
+ * Status flag indicating the outcome of the operation.
+ */
+function rdf_mapping_save($mapping) {
+ // In the case where a field has a mapping defined in the default entity
+ // mapping, but a mapping is not specified in the bundle-specific mapping,
+ // then use the default mapping for that field.
+ $mapping['mapping'] += _rdf_get_default_mapping($mapping['type']);
+
+ $status = db_merge('rdf_mapping')
+ ->key(array(
+ 'type' => $mapping['type'],
+ 'bundle' => $mapping['bundle'],
+ ))
+ ->fields(array(
+ 'mapping' => serialize($mapping['mapping']),
+ ))
+ ->execute();
+
+ entity_info_cache_clear();
+
+ return $status;
+}
+
+/**
+ * Deletes the mapping for the given bundle from the database.
+ *
+ * @param $type
+ * The entity type the mapping refers to.
+ * @param $bundle
+ * The bundle the mapping refers to.
+ *
+ * @return
+ * Return boolean TRUE if mapping deleted, FALSE if not.
+ */
+function rdf_mapping_delete($type, $bundle) {
+ $num_rows = db_delete('rdf_mapping')
+ ->condition('type', $type)
+ ->condition('bundle', $bundle)
+ ->execute();
+
+ return (bool) ($num_rows > 0);
+}
+
+/**
+ * Builds an array of RDFa attributes for a given mapping. This array will
+ * typically be passed through drupal_attributes() to create the attributes
+ * variables that are available to template files. These include $attributes,
+ * $title_attributes, $content_attributes and the field-specific
+ * $item_attributes variables. For more information, see
+ * theme_rdf_template_variable_wrapper().
+ *
+ * @param $mapping
+ * An array containing a mandatory 'predicates' key and optional 'datatype',
+ * 'callback' and 'type' keys. For example:
+ * @code
+ * array(
+ * 'predicates' => array('dc:created'),
+ * 'datatype' => 'xsd:dateTime',
+ * 'callback' => 'date_iso8601',
+ * ),
+ * );
+ * @endcode
+ * @param $data
+ * A value that needs to be converted by the provided callback function.
+ *
+ * @return
+ * An array containing RDFa attributes suitable for drupal_attributes().
+ */
+function rdf_rdfa_attributes($mapping, $data = NULL) {
+ // The type of mapping defaults to 'property'.
+ $type = isset($mapping['type']) ? $mapping['type'] : 'property';
+
+ switch ($type) {
+ // The mapping expresses the relationship between two resources.
+ case 'rel':
+ case 'rev':
+ $attributes[$type] = $mapping['predicates'];
+ break;
+
+ // The mapping expresses the relationship between a resource and some
+ // literal text.
+ case 'property':
+ $attributes['property'] = $mapping['predicates'];
+ // Convert $data to a specific format as per the callback function.
+ if (isset($data) && isset($mapping['callback']) && function_exists($mapping['callback'])) {
+ $callback = $mapping['callback'];
+ $attributes['content'] = $callback($data);
+ }
+ if (isset($mapping['datatype'])) {
+ $attributes['datatype'] = $mapping['datatype'];
+ }
+ break;
+ }
+
+ return $attributes;
+}
+
+/**
+ * @} End of "addtogroup rdf".
+ */
+
+/**
+ * Implements hook_modules_installed().
+ *
+ * Checks if the installed modules have any RDF mapping definitions to declare
+ * and stores them in the rdf_mapping table.
+ *
+ * While both default entity mappings and specific bundle mappings can be
+ * defined in hook_rdf_mapping(), default entity mappings are not stored in the
+ * database. Only overridden mappings are stored in the database. The default
+ * entity mappings can be overriden by specific bundle mappings which are
+ * stored in the database and can be altered via the RDF CRUD mapping API.
+ */
+function rdf_modules_installed($modules) {
+ foreach ($modules as $module) {
+ $function = $module . '_rdf_mapping';
+ if (function_exists($function)) {
+ foreach ($function() as $mapping) {
+ // Only the bundle mappings are saved in the database.
+ if ($mapping['bundle'] !== RDF_DEFAULT_BUNDLE) {
+ rdf_mapping_save($mapping);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Implements hook_modules_uninstalled().
+ */
+function rdf_modules_uninstalled($modules) {
+ // @todo Remove RDF mappings of uninstalled modules.
+}
+
+/**
+ * Implements hook_entity_info_alter().
+ *
+ * Adds the proper RDF mapping to each entity type/bundle pair.
+ *
+ * @todo May need to move the comment below to another place.
+ * This hook should not be used by modules to alter the bundle mappings.
+ * The UI should always be authoritative. UI mappings are stored in the
+ * database and if hook_entity_info_alter was used to override module defined
+ * mappings, it would override the user defined mapping as well.
+ */
+function rdf_entity_info_alter(&$entity_info) {
+ // Loop through each entity type and its bundles.
+ foreach ($entity_info as $entity_type => $entity_type_info) {
+ if (isset($entity_type_info['bundles'])) {
+ foreach ($entity_type_info['bundles'] as $bundle => $bundle_info) {
+ if ($mapping = _rdf_mapping_load($entity_type, $bundle)) {
+ $entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = $mapping;
+ }
+ else {
+ // If no mapping was found in the database, assign the default RDF
+ // mapping for this entity type.
+ $entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = _rdf_get_default_mapping($entity_type);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Implements hook_entity_load().
+ */
+function rdf_entity_load($entities, $type) {
+ foreach ($entities as $entity) {
+ // Extracts the bundle of the entity being loaded.
+ list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
+ $entity->rdf_mapping = rdf_mapping_load($type, $bundle);
+ }
+}
+
+/**
+ * Implements hook_comment_load().
+ */
+function rdf_comment_load($comments) {
+ foreach ($comments as $comment) {
+ // Pages with many comments can show poor performance. This information
+ // isn't needed until rdf_preprocess_comment() is called, but set it here
+ // to optimize performance for websites that implement an entity cache.
+ $comment->rdf_data['date'] = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created);
+ $comment->rdf_data['nid_uri'] = url('node/' . $comment->nid);
+ if ($comment->pid) {
+ $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid, array('fragment' => 'comment-' . $comment->pid));
+ }
+ }
+}
+
+/**
+ * Implements hook_theme().
+ */
+function rdf_theme() {
+ return array(
+ 'rdf_template_variable_wrapper' => array(
+ 'variables' => array('content' => NULL, 'attributes' => array(), 'context' => array(), 'inline' => TRUE),
+ ),
+ 'rdf_metadata' => array(
+ 'variables' => array('metadata' => array()),
+ ),
+ );
+}
+
+/**
+ * Template process function for adding extra tags to hold RDFa attributes.
+ *
+ * Since template files already have built-in support for $attributes,
+ * $title_attributes, and $content_attributes, and field templates have support
+ * for $item_attributes, we try to leverage those as much as possible. However,
+ * in some cases additional attributes are needed not covered by these. We deal
+ * with those here.
+ */
+function rdf_process(&$variables, $hook) {
+ // Handles attributes needed for content not covered by title, content,
+ // and field items. It does this by adjusting the variable sent to the
+ // template so that the template doesn't have to worry about it. See
+ // theme_rdf_template_variable_wrapper().
+ if (!empty($variables['rdf_template_variable_attributes_array'])) {
+ foreach ($variables['rdf_template_variable_attributes_array'] as $variable_name => $attributes) {
+ $context = array(
+ 'hook' => $hook,
+ 'variable_name' => $variable_name,
+ 'variables' => $variables,
+ );
+ $variables[$variable_name] = theme('rdf_template_variable_wrapper', array('content' => $variables[$variable_name], 'attributes' => $attributes, 'context' => $context));
+ }
+ }
+ // Handles additional attributes about a template entity that for RDF parsing
+ // reasons, can't be placed into that template's $attributes variable. This
+ // is "meta" information that is related to particular content, so render it
+ // close to that content.
+ if (!empty($variables['rdf_metadata_attributes_array'])) {
+ if (!isset($variables['content']['#prefix'])) {
+ $variables['content']['#prefix'] = '';
+ }
+ $variables['content']['#prefix'] = theme('rdf_metadata', array('metadata' => $variables['rdf_metadata_attributes_array'])) . $variables['content']['#prefix'];
+ }
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_node(&$variables) {
+ // Adds RDFa markup to the node container. The about attribute specifies the
+ // URI of the resource described within the HTML element, while the @typeof
+ // attribute indicates its RDF type (e.g., foaf:Document, sioc:Person, and so
+ // on.)
+ $variables['attributes_array']['about'] = empty($variables['node_url']) ? NULL: $variables['node_url'];
+ $variables['attributes_array']['typeof'] = empty($variables['node']->rdf_mapping['rdftype']) ? NULL : $variables['node']->rdf_mapping['rdftype'];
+
+ // Adds RDFa markup to the title of the node. Because the RDFa markup is
+ // added to the <h2> tag which might contain HTML code, we specify an empty
+ // datatype to ensure the value of the title read by the RDFa parsers is a
+ // literal.
+ $variables['title_attributes_array']['property'] = empty($variables['node']->rdf_mapping['title']['predicates']) ? NULL : $variables['node']->rdf_mapping['title']['predicates'];
+ $variables['title_attributes_array']['datatype'] = '';
+
+ // In full node mode, the title is not displayed by node.tpl.php so it is
+ // added in the <head> tag of the HTML page.
+ if ($variables['page']) {
+ $element = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'content' => $variables['node']->title,
+ 'about' => $variables['node_url'],
+ ),
+ );
+ if (!empty($variables['node']->rdf_mapping['title']['predicates'])) {
+ $element['#attributes']['property'] = $variables['node']->rdf_mapping['title']['predicates'];
+ }
+ drupal_add_html_head($element, 'rdf_node_title');
+ }
+
+ // Adds RDFa markup for the date.
+ if (!empty($variables['rdf_mapping']['created'])) {
+ $date_attributes_array = rdf_rdfa_attributes($variables['rdf_mapping']['created'], $variables['created']);
+ $variables['rdf_template_variable_attributes_array']['date'] = $date_attributes_array;
+ if ($variables['submitted']) {
+ $variables['rdf_template_variable_attributes_array']['submitted'] = $date_attributes_array;
+ }
+ }
+ // Adds RDFa markup for the relation between the node and its author.
+ if (!empty($variables['rdf_mapping']['uid'])) {
+ $variables['rdf_template_variable_attributes_array']['name']['rel'] = $variables['rdf_mapping']['uid']['predicates'];
+ if ($variables['submitted']) {
+ $variables['rdf_template_variable_attributes_array']['submitted']['rel'] = $variables['rdf_mapping']['uid']['predicates'];
+ }
+ }
+
+ // Adds RDFa markup annotating the number of comments a node has.
+ if (isset($variables['node']->comment_count) && !empty($variables['node']->rdf_mapping['comment_count']['predicates'])) {
+ // Annotates the 'x comments' link in teaser view.
+ if (isset($variables['content']['links']['comment']['#links']['comment-comments'])) {
+ $comment_count_attributes['property'] = $variables['node']->rdf_mapping['comment_count']['predicates'];
+ $comment_count_attributes['content'] = $variables['node']->comment_count;
+ $comment_count_attributes['datatype'] = $variables['node']->rdf_mapping['comment_count']['datatype'];
+ // According to RDFa parsing rule number 4, a new subject URI is created
+ // from the href attribute if no rel/rev attribute is present. To get the
+ // original node URL from the about attribute of the parent container we
+ // set an empty rel attribute which triggers rule number 5. See
+ // http://www.w3.org/TR/rdfa-syntax/#sec_5.5.
+ $comment_count_attributes['rel'] = '';
+ $variables['content']['links']['comment']['#links']['comment-comments']['attributes'] += $comment_count_attributes;
+ }
+ // In full node view, the number of comments is not displayed by
+ // node.tpl.php so it is expressed in RDFa in the <head> tag of the HTML
+ // page.
+ if ($variables['page'] && user_access('access comments')) {
+ $element = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'about' => $variables['node_url'],
+ 'property' => $variables['node']->rdf_mapping['comment_count']['predicates'],
+ 'content' => $variables['node']->comment_count,
+ 'datatype' => $variables['node']->rdf_mapping['comment_count']['datatype'],
+ ),
+ );
+ drupal_add_html_head($element, 'rdf_node_comment_count');
+ }
+ }
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_field(&$variables) {
+ $element = $variables['element'];
+ $mapping = rdf_mapping_load($element['#entity_type'], $element['#bundle']);
+ $field_name = $element['#field_name'];
+
+ if (!empty($mapping) && !empty($mapping[$field_name])) {
+ foreach ($element['#items'] as $delta => $item) {
+ $variables['item_attributes_array'][$delta] = rdf_rdfa_attributes($mapping[$field_name], $item);
+ // If this field is an image, RDFa will not output correctly when the
+ // image is in a containing <a> tag. If the field is a file, RDFa will
+ // not output correctly if the filetype icon comes before the link to the
+ // file. We correct this by adding a resource attribute to the div if
+ // this field has a URI.
+ if (isset($item['uri'])) {
+ if (!empty($element[$delta]['#image_style'])) {
+ $variables['item_attributes_array'][$delta]['resource'] = image_style_url($element[$delta]['#image_style'], $item['uri']);
+ }
+ else {
+ $variables['item_attributes_array'][$delta]['resource'] = file_create_url($item['uri']);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_user_profile(&$variables) {
+ $account = $variables['elements']['#account'];
+ $uri = entity_uri('user', $account);
+
+ // Adds RDFa markup to the user profile page. Fields displayed in this page
+ // will automatically describe the user.
+ if (!empty($account->rdf_mapping['rdftype'])) {
+ $variables['attributes_array']['typeof'] = $account->rdf_mapping['rdftype'];
+ $variables['attributes_array']['about'] = url($uri['path'], $uri['options']);
+ }
+ // Adds the relationship between the sioc:UserAccount and the foaf:Person who
+ // holds the account.
+ $account_holder_meta = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'about' => url($uri['path'], array_merge($uri['options'], array('fragment' => 'me'))),
+ 'typeof' => array('foaf:Person'),
+ 'rel' => array('foaf:account'),
+ 'resource' => url($uri['path'], $uri['options']),
+ ),
+ );
+ // Adds the markup for username.
+ $username_meta = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'about' => url($uri['path'], $uri['options']),
+ 'property' => $account->rdf_mapping['name']['predicates'],
+ 'content' => $account->name,
+ )
+ );
+ drupal_add_html_head($account_holder_meta, 'rdf_user_account_holder');
+ drupal_add_html_head($username_meta, 'rdf_user_username');
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_username(&$variables) {
+ // Because xml:lang is set on the HTML element that wraps the page, the
+ // username inherits this language attribute. However, since the username
+ // might not be transliterated to the same language that the content is in,
+ // we do not want it to inherit the language attribute, so we set the
+ // attribute to an empty string.
+ if (empty($variables['attributes_array']['xml:lang'])) {
+ $variables['attributes_array']['xml:lang'] = '';
+ }
+
+ // $variables['account'] is a pseudo account object, and as such, does not
+ // contain the RDF mappings for the user. In the case of nodes and comments,
+ // it contains the mappings for the node or comment object instead. However,
+ // while the RDF mappings are available from a full user_load(), this should
+ // be avoided for performance reasons. Since the type and bundle for users is
+ // already known, call rdf_mapping_load() directly.
+ $rdf_mapping = rdf_mapping_load('user', 'user');
+
+ // The profile URI is used to identify the user account. The about attribute
+ // is used to set the URI as the default subject of the predicates embedded
+ // as RDFa in the child elements. Even if the user profile is not accessible
+ // to the current user, we use its URI in order to identify the user in RDF.
+ // We do not use this attribute for the anonymous user because we do not have
+ // a user profile URI for it (only a homepage which cannot be used as user
+ // profile in RDF.)
+ if ($variables['uid'] > 0) {
+ $variables['attributes_array']['about'] = url('user/' . $variables['uid']);
+ }
+
+ $attributes = array();
+ // The typeof attribute specifies the RDF type(s) of this resource. They
+ // are defined in the 'rdftype' property of the user RDF mapping.
+ if (!empty($rdf_mapping['rdftype'])) {
+ $attributes['typeof'] = $rdf_mapping['rdftype'];
+ }
+ // Annotate the username in RDFa. A property attribute is used with an empty
+ // datatype attribute to ensure the username is parsed as a plain literal
+ // in RDFa 1.0 and 1.1.
+ if (!empty($rdf_mapping['name'])) {
+ $attributes['property'] = $rdf_mapping['name']['predicates'];
+ $attributes['datatype'] = '';
+ }
+ // Add the homepage RDFa markup if present.
+ if (!empty($variables['homepage']) && !empty($rdf_mapping['homepage'])) {
+ $attributes['rel'] = $rdf_mapping['homepage']['predicates'];
+ }
+ // The remaining attributes can have multiple values listed, with whitespace
+ // separating the values in the RDFa attributes
+ // (see http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes).
+ // Therefore, merge rather than override so as not to clobber values set by
+ // earlier preprocess functions.
+ $variables['attributes_array'] = array_merge_recursive($variables['attributes_array'], $attributes);
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_comment(&$variables) {
+ $comment = $variables['comment'];
+ if (!empty($comment->rdf_mapping['rdftype'])) {
+ // Adds RDFa markup to the comment container. The about attribute specifies
+ // the URI of the resource described within the HTML element, while the
+ // typeof attribute indicates its RDF type (e.g., sioc:Post, foaf:Document,
+ // and so on.)
+ $uri = entity_uri('comment', $comment);
+ $variables['attributes_array']['about'] = url($uri['path'], $uri['options']);
+ $variables['attributes_array']['typeof'] = $comment->rdf_mapping['rdftype'];
+ }
+
+ // Adds RDFa markup for the date of the comment.
+ if (!empty($comment->rdf_mapping['created'])) {
+ // The comment date is precomputed as part of the rdf_data so that it can be
+ // cached as part of the entity.
+ $date_attributes_array = $comment->rdf_data['date'];
+ $variables['rdf_template_variable_attributes_array']['created'] = $date_attributes_array;
+ $variables['rdf_template_variable_attributes_array']['submitted'] = $date_attributes_array;
+ }
+ // Adds RDFa markup for the relation between the comment and its author.
+ if (!empty($comment->rdf_mapping['uid'])) {
+ $variables['rdf_template_variable_attributes_array']['author']['rel'] = $comment->rdf_mapping['uid']['predicates'];
+ $variables['rdf_template_variable_attributes_array']['submitted']['rel'] = $comment->rdf_mapping['uid']['predicates'];
+ }
+ if (!empty($comment->rdf_mapping['title'])) {
+ // Adds RDFa markup to the subject of the comment. Because the RDFa markup
+ // is added to an <h3> tag which might contain HTML code, we specify an
+ // empty datatype to ensure the value of the title read by the RDFa parsers
+ // is a literal.
+ $variables['title_attributes_array']['property'] = $comment->rdf_mapping['title']['predicates'];
+ $variables['title_attributes_array']['datatype'] = '';
+ }
+
+ // Annotates the parent relationship between the current comment and the node
+ // it belongs to. If available, the parent comment is also annotated.
+ if (!empty($comment->rdf_mapping['pid'])) {
+ // Adds the relation to the parent node.
+ $parent_node_attributes['rel'] = $comment->rdf_mapping['pid']['predicates'];
+ // The parent node URI is precomputed as part of the rdf_data so that it can
+ // be cached as part of the entity.
+ $parent_node_attributes['resource'] = $comment->rdf_data['nid_uri'];
+ $variables['rdf_metadata_attributes_array'][] = $parent_node_attributes;
+
+ // Adds the relation to parent comment, if it exists.
+ if ($comment->pid != 0) {
+ $parent_comment_attributes['rel'] = $comment->rdf_mapping['pid']['predicates'];
+ // The parent comment URI is precomputed as part of the rdf_data so that
+ // it can be cached as part of the entity.
+ $parent_comment_attributes['resource'] = $comment->rdf_data['pid_uri'];
+ $variables['rdf_metadata_attributes_array'][] = $parent_comment_attributes;
+ }
+ }
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_taxonomy_term(&$variables) {
+ // Adds the RDF type of the term and the term name in a <meta> tag.
+ $term = $variables['term'];
+ $term_label_meta = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'about' => url('taxonomy/term/' . $term->tid),
+ 'typeof' => $term->rdf_mapping['rdftype'],
+ 'property' => $term->rdf_mapping['name']['predicates'],
+ 'content' => $term->name,
+ ),
+ );
+ drupal_add_html_head($term_label_meta, 'rdf_term_label');
+}
+
+/**
+ * Implements hook_field_attach_view_alter().
+ */
+function rdf_field_attach_view_alter(&$output, $context) {
+ // Append term mappings on displayed taxonomy links.
+ foreach (element_children($output) as $field_name) {
+ $element = &$output[$field_name];
+ if ($element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'taxonomy_term_reference_link') {
+ foreach ($element['#items'] as $delta => $item) {
+ // This function is invoked during entity preview when taxonomy term
+ // reference items might contain free-tagging terms that do not exist
+ // yet and thus have no $item['taxonomy_term'].
+ if (isset($item['taxonomy_term'])) {
+ $term = $item['taxonomy_term'];
+ if (!empty($term->rdf_mapping['rdftype'])) {
+ $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
+ }
+ if (!empty($term->rdf_mapping['name']['predicates'])) {
+ // A property attribute is used with an empty datatype attribute so
+ // the term name is parsed as a plain literal in RDFa 1.0 and 1.1.
+ $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
+ $element[$delta]['#options']['attributes']['datatype'] = '';
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_image(&$variables) {
+ // Adds the RDF type for image. We cannot use the usual entity-based mapping
+ // to get 'foaf:Image' because image does not have its own entity type or
+ // bundle.
+ $variables['attributes']['typeof'] = array('foaf:Image');
+}
+
+/**
+ * Returns HTML for a template variable wrapped in an HTML element with the
+ * RDF attributes.
+ *
+ * This is called by rdf_process() shortly before the theme system renders
+ * a template file. It is called once for each template variable for which
+ * additional attributes are needed. While template files are responsible for
+ * rendering the attributes for the template's primary object (via the
+ * $attributes variable), title (via the $title_attributes variable), and
+ * content (via the $content_attributes variable), additional template
+ * variables that need containing attributes are routed through this function,
+ * allowing the template file to receive properly wrapped variables.
+ *
+ * Tip for themers: if you're already outputting a wrapper element around a
+ * particular template variable in your template file, and if you don't want
+ * an extra wrapper element, you can override this function to not wrap that
+ * variable and instead print the following inside your template file:
+ * @code
+ * drupal_attributes($rdf_template_variable_attributes_array[$variable_name])
+ * @endcode
+ *
+ * @param $variables
+ * An associative array containing:
+ * - content: A string of content to be wrapped with attributes.
+ * - attributes: An array of attributes to be placed on the wrapping element.
+ * - context: An array of context information about the content to be wrapped:
+ * - hook: The theme hook that will use the wrapped content. This
+ * corresponds to the key within the theme registry for this template.
+ * For example, if this content is about to be used in node.tpl.php or
+ * node-[type].tpl.php, then the 'hook' is 'node'.
+ * - variable_name: The name of the variable by which the template will
+ * refer to this content. Each template file has documentation about
+ * the variables it uses. For example, if this function is called in
+ * preparing the $author variable for comment.tpl.php, then the
+ * 'variable_name' is 'author'.
+ * - variables: The full array of variables about to be passed to the
+ * template.
+ * - inline: TRUE if the content contains only inline HTML elements and
+ * therefore can be validly wrapped by a <span> tag. FALSE if the content
+ * might contain block level HTML elements and therefore cannot be validly
+ * wrapped by a <span> tag. Modules implementing preprocess functions that
+ * set 'rdf_template_variable_attributes_array' for a particular template
+ * variable that might contain block level HTML must also implement
+ * hook_preprocess_rdf_template_variable_wrapper() and set 'inline' to FALSE
+ * for that context. Themes that render normally inline content with block
+ * level HTML must similarly implement
+ * hook_preprocess_rdf_template_variable_wrapper() and set 'inline'
+ * accordingly.
+ *
+ * @see rdf_process()
+ * @ingroup themeable
+ * @ingroup rdf
+ */
+function theme_rdf_template_variable_wrapper($variables) {
+ $output = $variables['content'];
+ if (!empty($output) && !empty($variables['attributes'])) {
+ $attributes = drupal_attributes($variables['attributes']);
+ $output = $variables['inline'] ? "<span$attributes>$output</span>" : "<div$attributes>$output</div>";
+ }
+ return $output;
+}
+
+/**
+ * Returns HTML for a series of empty spans for exporting RDF metadata in RDFa.
+ *
+ * Sometimes it is useful to export data which is not semantically present in
+ * the HTML output. For example, a hierarchy of comments is visible for a human
+ * but not for machines because this hiearchy is not present in the DOM tree.
+ * We can express it in RDFa via empty <span> tags. These aren't visible and
+ * give machines extra information about the content and its structure.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - metadata: An array of attribute arrays. Each item in the array
+ * corresponds to its own set of attributes, and therefore, needs its own
+ * element.
+ *
+ * @see rdf_process()
+ * @ingroup themeable
+ * @ingroup rdf
+ */
+function theme_rdf_metadata($variables) {
+ $output = '';
+ foreach ($variables['metadata'] as $attributes) {
+ // Add a class so that developers viewing the HTML source can see why there
+ // are empty <span> tags in the document. The class can also be used to set
+ // a CSS display:none rule in a theme where empty spans affect display.
+ $attributes['class'][] = 'rdf-meta';
+ // The XHTML+RDFa doctype allows either <span></span> or <span /> syntax to
+ // be used, but for maximum browser compatibility, W3C recommends the
+ // former when serving pages using the text/html media type, see
+ // http://www.w3.org/TR/xhtml1/#C_3.
+ $output .= '<span' . drupal_attributes($attributes) . '></span>';
+ }
+ return $output;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/rdf.test b/kolab.org/www/drupal-7.26/modules/rdf/rdf.test
new file mode 100644
index 0000000..370dbb2
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/rdf.test
@@ -0,0 +1,720 @@
+<?php
+
+/**
+ * @file
+ * Tests for rdf.module.
+ */
+
+class RdfMappingHookTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDF mapping hook',
+ 'description' => 'Test hook_rdf_mapping().',
+ 'group' => 'RDF',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('rdf', 'rdf_test', 'field_test');
+ }
+
+ /**
+ * Test that hook_rdf_mapping() correctly returns and processes mapping.
+ */
+ function testMapping() {
+ // Test that the mapping is returned correctly by the hook.
+ $mapping = rdf_mapping_load('test_entity', 'test_bundle');
+ $this->assertIdentical($mapping['rdftype'], array('sioc:Post'), 'Mapping for rdftype is sioc:Post.');
+ $this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), 'Mapping for title is dc:title.');
+ $this->assertIdentical($mapping['created'], array(
+ 'predicates' => array('dc:created'),
+ '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'), 'type' => 'rel'), '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(), 'Empty array returned when an entity type, bundle pair has no mapping.');
+ }
+}
+
+/**
+ * Test RDFa markup generation.
+ */
+class RdfRdfaMarkupTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDFa markup',
+ 'description' => 'Test RDFa markup generation.',
+ 'group' => 'RDF',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('rdf', 'field_test', 'rdf_test');
+ }
+
+ /**
+ * Test rdf_rdfa_attributes().
+ */
+ function testDrupalRdfaAttributes() {
+ // 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_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);
+ 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);
+ }
+
+ /**
+ * Ensure that file fields have the correct resource as the object in RDFa
+ * when displayed as a teaser.
+ */
+ function testAttributesInMarkupFile() {
+ // Create a user to post the image.
+ $admin_user = $this->drupalCreateUser(array('edit own article content', 'revert revisions', 'administer content types'));
+ $this->drupalLogin($admin_user);
+
+ $langcode = LANGUAGE_NONE;
+ $bundle_name = "article";
+
+ $field_name = 'file_test';
+ $field = array(
+ 'field_name' => $field_name,
+ 'type' => 'file',
+ );
+ field_create_field($field);
+ $instance = array(
+ 'field_name' => $field_name,
+ 'entity_type' => 'node',
+ 'bundle' => $bundle_name,
+ 'display' => array(
+ 'teaser' => array(
+ 'type' => 'file_default',
+ ),
+ ),
+ );
+ field_create_instance($instance);
+
+ // Set the RDF mapping for the new field.
+ $rdf_mapping = rdf_mapping_load('node', $bundle_name);
+ $rdf_mapping += array($field_name => array('predicates' => array('rdfs:seeAlso'), 'type' => 'rel'));
+ $rdf_mapping_save = array('mapping' => $rdf_mapping, 'type' => 'node', 'bundle' => $bundle_name);
+ rdf_mapping_save($rdf_mapping_save);
+
+ // Get the test file that simpletest provides.
+ $file = current($this->drupalGetTestFiles('text'));
+
+ // Prepare image variables.
+ $image_field = "field_image";
+ // Get the test image that simpletest provides.
+ $image = current($this->drupalGetTestFiles('image'));
+
+ // Create an array for drupalPost with the field names as the keys and
+ // the URIs for the test files as the values.
+ $edit = array("files[" . $field_name . "_" . $langcode . "_0]" => drupal_realpath($file->uri),
+ "files[" . $image_field . "_" . $langcode . "_0]" => drupal_realpath($image->uri));
+
+ // Create node and save, then edit node to upload files.
+ $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
+
+ // Get filenames and nid for comparison with HTML output.
+ $file_filename = $file->filename;
+ $image_filename = $image->filename;
+ $nid = $node->nid;
+ // Navigate to front page, where node is displayed in teaser form.
+ $this->drupalGet('node');
+
+ // We only check to make sure that the resource attribute contains '.txt'
+ // instead of the full file name because the filename is altered on upload.
+ $file_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, ".txt")]', array(
+ ':node-uri' => 'node/' . $nid,
+ ));
+ $this->assertTrue(!empty($file_rel), "Attribute 'rel' set on file field. Attribute 'resource' is also set.");
+ $image_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, :image)]//img[contains(@typeof, "foaf:Image")]', array(
+ ':node-uri' => 'node/' . $nid,
+ ':image' => $image_filename,
+ ));
+
+ $this->assertTrue(!empty($image_rel), "Attribute 'rel' set on image field. Attribute 'resource' is also set.");
+
+ // Edits the node to add tags.
+ $tag1 = $this->randomName(8);
+ $tag2 = $this->randomName(8);
+ $edit = array();
+ $edit['field_tags[' . LANGUAGE_NONE . ']'] = "$tag1, $tag2";
+ $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
+ // Ensures the RDFa markup for the relationship between the node and its
+ // tags is correct.
+ $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(
+ ':node-url' => url('node/' . $node->nid),
+ ':term-name' => $tag1,
+ ));
+ $this->assertTrue(!empty($term_rdfa_meta), 'Property dc:subject is present for the tag1 field item.');
+ $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(
+ ':node-url' => url('node/' . $node->nid),
+ ':term-name' => $tag2,
+ ));
+ $this->assertTrue(!empty($term_rdfa_meta), 'Property dc:subject is present for the tag2 field item.');
+ }
+}
+
+class RdfCrudTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDF mapping CRUD functions',
+ 'description' => 'Test the RDF mapping CRUD functions.',
+ 'group' => 'RDF',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('rdf', 'rdf_test');
+ }
+
+ /**
+ * Test inserting, loading, updating, and deleting RDF mappings.
+ */
+ function testCRUD() {
+ // Verify loading of a default mapping.
+ $mapping = _rdf_mapping_load('test_entity', 'test_bundle');
+ $this->assertTrue(count($mapping), 'Default mapping was found.');
+
+ // Verify saving a mapping.
+ $mapping = array(
+ 'type' => 'crud_test_entity',
+ 'bundle' => 'crud_test_bundle',
+ 'mapping' => array(
+ 'rdftype' => array('sioc:Post'),
+ 'title' => array(
+ 'predicates' => array('dc:title'),
+ ),
+ 'uid' => array(
+ 'predicates' => array('sioc:has_creator', 'dc:creator'),
+ 'type' => 'rel',
+ ),
+ ),
+ );
+ $this->assertTrue(rdf_mapping_save($mapping) === SAVED_NEW, 'Mapping was saved.');
+
+ // Read the raw record from the {rdf_mapping} table.
+ $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
+ $stored_mapping = $result->fetchAssoc();
+ $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
+ $this->assertEqual($mapping, $stored_mapping, 'Mapping was stored properly in the {rdf_mapping} table.');
+
+ // Verify loading of saved mapping.
+ $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Saved mapping loaded successfully.');
+
+ // Verify updating of mapping.
+ $mapping['mapping']['title'] = array(
+ 'predicates' => array('dc2:bar2'),
+ );
+ $this->assertTrue(rdf_mapping_save($mapping) === SAVED_UPDATED, 'Mapping was updated.');
+
+ // Read the raw record from the {rdf_mapping} table.
+ $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
+ $stored_mapping = $result->fetchAssoc();
+ $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
+ $this->assertEqual($mapping, $stored_mapping, 'Updated mapping was stored properly in the {rdf_mapping} table.');
+
+ // Verify loading of saved mapping.
+ $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Saved mapping loaded successfully.');
+
+ // Verify deleting of mapping.
+ $this->assertTrue(rdf_mapping_delete($mapping['type'], $mapping['bundle']), 'Mapping was deleted.');
+ $this->assertFalse(_rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Deleted mapping is no longer found in the database.');
+ }
+}
+
+class RdfMappingDefinitionTestCase extends TaxonomyWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDF mapping definition functionality',
+ 'description' => 'Test the different types of RDF mappings and ensure the proper RDFa markup in included in nodes and user profile pages.',
+ 'group' => 'RDF',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('rdf', 'rdf_test', 'blog');
+ }
+
+ /**
+ * Create a node of type blog and test whether the RDF mapping defined for
+ * this node type in rdf_test.module is used in the node page.
+ */
+ function testAttributesInMarkup1() {
+ $node = $this->drupalCreateNode(array('type' => 'blog'));
+ $isoDate = date('c', $node->changed);
+ $url = url('node/' . $node->nid);
+ $this->drupalGet('node/' . $node->nid);
+
+ // Ensure the default bundle mapping for node is used. These attributes come
+ // from the node default bundle definition.
+ $blog_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
+ $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']");
+ $this->assertTrue(!empty($blog_title), 'Property dc:title is present in meta tag.');
+ $this->assertTrue(!empty($blog_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
+ }
+
+ /**
+ * Create a content type and a node of type test_bundle_hook_install and test
+ * whether the RDF mapping defined in rdf_test.install is used.
+ */
+ function testAttributesInMarkup2() {
+ $type = $this->drupalCreateContentType(array('type' => 'test_bundle_hook_install'));
+ // Create node with single quotation mark title to ensure it does not get
+ // escaped more than once.
+ $node = $this->drupalCreateNode(array(
+ 'type' => 'test_bundle_hook_install',
+ 'title' => $this->randomName(8) . "'",
+ ));
+ $isoDate = date('c', $node->changed);
+ $url = url('node/' . $node->nid);
+ $this->drupalGet('node/' . $node->nid);
+
+ // Ensure the mapping defined in rdf_module.test is used.
+ $test_bundle_title = $this->xpath('//meta[@property="dc:title" and @content="' . $node->title . '"]');
+ $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']");
+ $this->assertTrue(!empty($test_bundle_title), 'Property dc:title is present in meta tag.');
+ $this->assertTrue(!empty($test_bundle_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
+ }
+
+ /**
+ * Create a random content type and node and ensure the default mapping for
+ * node is used.
+ */
+ function testAttributesInMarkup3() {
+ $type = $this->drupalCreateContentType();
+ $node = $this->drupalCreateNode(array('type' => $type->type));
+ $isoDate = date('c', $node->changed);
+ $url = url('node/' . $node->nid);
+ $this->drupalGet('node/' . $node->nid);
+
+ // Ensure the default bundle mapping for node is used. These attributes come
+ // from the node default bundle definition.
+ $random_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
+ $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']");
+ $this->assertTrue(!empty($random_bundle_title), 'Property dc:title is present in meta tag.');
+ $this->assertTrue(!empty($random_bundle_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
+ }
+
+ /**
+ * Create a random user and ensure the default mapping for user is used.
+ */
+ function testUserAttributesInMarkup() {
+ // Create two users, one with access to user profiles.
+ $user1 = $this->drupalCreateUser(array('access user profiles'));
+ $user2 = $this->drupalCreateUser();
+ $username = $user2->name;
+ $this->drupalLogin($user1);
+ // Browse to the user profile page.
+ $this->drupalGet('user/' . $user2->uid);
+ // Ensure the default bundle mapping for user is used on the user profile
+ // page. These attributes come from the user default bundle definition.
+ $account_uri = url('user/' . $user2->uid);
+ $person_uri = url('user/' . $user2->uid, array('fragment' => 'me'));
+
+ $user2_profile_about = $this->xpath('//div[@class="profile" and @typeof="sioc:UserAccount" and @about=:account-uri]', array(
+ ':account-uri' => $account_uri,
+ ));
+ $this->assertTrue(!empty($user2_profile_about), 'RDFa markup found on user profile page');
+
+ $user_account_holder = $this->xpath('//meta[contains(@typeof, "foaf:Person") and @about=:person-uri and @resource=:account-uri and contains(@rel, "foaf:account")]', array(
+ ':person-uri' => $person_uri,
+ ':account-uri' => $account_uri,
+ ));
+ $this->assertTrue(!empty($user_account_holder), 'URI created for account holder and username set on sioc:UserAccount.');
+
+ $user_username = $this->xpath('//meta[@about=:account-uri and contains(@property, "foaf:name") and @content=:username]', array(
+ ':account-uri' => $account_uri,
+ ':username' => $username,
+ ));
+ $this->assertTrue(!empty($user_username), 'foaf:name set on username.');
+
+ // User 2 creates node.
+ $this->drupalLogin($user2);
+ $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $this->drupalLogin($user1);
+ $this->drupalGet('node/' . $node->nid);
+ // Ensures the default bundle mapping for user is used on the Authored By
+ // information on the node.
+ $author_about = $this->xpath('//a[@typeof="sioc:UserAccount" and @about=:account-uri and @property="foaf:name" and @datatype="" and contains(@xml:lang, "")]', array(
+ ':account-uri' => $account_uri,
+ ));
+ $this->assertTrue(!empty($author_about), 'RDFa markup found on author information on post. xml:lang on username is set to empty string.');
+ }
+
+ /**
+ * Creates a random term and ensures the right RDFa markup is used.
+ */
+ function testTaxonomyTermRdfaAttributes() {
+ $vocabulary = $this->createVocabulary();
+ $term = $this->createTerm($vocabulary);
+
+ // Views the term and checks that the RDFa markup is correct.
+ $this->drupalGet('taxonomy/term/' . $term->tid);
+ $term_url = url('taxonomy/term/' . $term->tid);
+ $term_name = $term->name;
+ $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(
+ ':term-url' => $term_url,
+ ':term-name' => $term_name,
+ ));
+ $this->assertTrue(!empty($term_rdfa_meta), 'RDFa markup found on term page.');
+ }
+}
+
+class RdfCommentAttributesTestCase extends CommentHelperCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDF comment mapping',
+ 'description' => 'Tests the RDFa markup of comments.',
+ 'group' => 'RDF',
+ );
+ }
+
+ public function setUp() {
+ parent::setUp('comment', 'rdf', 'rdf_test');
+
+ $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions', 'administer blocks'));
+ $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'access user profiles'));
+
+ // Enables anonymous user comments.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => TRUE,
+ ));
+ // Allows anonymous to leave their contact information.
+ $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
+ $this->setCommentPreview(DRUPAL_OPTIONAL);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
+
+ // Creates the nodes on which the test comments will be posted.
+ $this->drupalLogin($this->web_user);
+ $this->node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $this->node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $this->drupalLogout();
+ }
+
+ /**
+ * Tests the presence of the RDFa markup for the number of comments.
+ */
+ public function testNumberOfCommentsRdfaMarkup() {
+ // Posts 2 comments as a registered user.
+ $this->drupalLogin($this->web_user);
+ $this->postComment($this->node1, $this->randomName(), $this->randomName());
+ $this->postComment($this->node1, $this->randomName(), $this->randomName());
+
+ // Tests number of comments in teaser view.
+ $this->drupalGet('node');
+ $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"]');
+ $this->assertTrue(!empty($comment_count_teaser), 'RDFa markup for the number of comments found on teaser view.');
+ $comment_count_link = $this->xpath('//div[@about=:url]//a[contains(@property, "sioc:num_replies") and @rel=""]', array(':url' => url("node/{$this->node1->nid}")));
+ $this->assertTrue(!empty($comment_count_link), 'Empty rel attribute found in comment count link.');
+
+ // Tests number of comments in full node view.
+ $this->drupalGet('node/' . $this->node1->nid);
+ $node_url = url('node/' . $this->node1->nid);
+ $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));
+ $this->assertTrue(!empty($comment_count_teaser), 'RDFa markup for the number of comments found on full node view.');
+ }
+
+ /**
+ * Tests the presence of the RDFa markup for the title, date and author and
+ * homepage on registered users and anonymous comments.
+ */
+ public function testCommentRdfaMarkup() {
+
+ // Posts comment #1 as a registered user.
+ $this->drupalLogin($this->web_user);
+ $comment1_subject = $this->randomName();
+ $comment1_body = $this->randomName();
+ $comment1 = $this->postComment($this->node1, $comment1_body, $comment1_subject);
+
+ // Tests comment #1 with access to the user profile.
+ $this->drupalGet('node/' . $this->node1->nid);
+ $this->_testBasicCommentRdfaMarkup($comment1);
+
+ // Tests comment #1 with no access to the user profile (as anonymous user).
+ $this->drupalLogout();
+ $this->drupalGet('node/' . $this->node1->nid);
+ $this->_testBasicCommentRdfaMarkup($comment1);
+
+ // Posts comment #2 as anonymous user.
+ $comment2_subject = $this->randomName();
+ $comment2_body = $this->randomName();
+ $anonymous_user = array();
+ $anonymous_user['name'] = $this->randomName();
+ $anonymous_user['mail'] = 'tester@simpletest.org';
+ $anonymous_user['homepage'] = 'http://example.org/';
+ $comment2 = $this->postComment($this->node2, $comment2_body, $comment2_subject, $anonymous_user);
+ $this->drupalGet('node/' . $this->node2->nid);
+
+ // Tests comment #2 as anonymous user.
+ $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
+ // Tests the RDFa markup for the homepage (specific to anonymous comments).
+ $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")]');
+ $this->assertTrue(!empty($comment_homepage), 'RDFa markup for the homepage of anonymous user found.');
+ // There should be no about attribute on anonymous comments.
+ $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]');
+ $this->assertTrue(empty($comment_homepage), 'No about attribute is present on anonymous user comment.');
+
+ // Tests comment #2 as logged in user.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('node/' . $this->node2->nid);
+ $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
+ // Tests the RDFa markup for the homepage (specific to anonymous comments).
+ $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")]');
+ $this->assertTrue(!empty($comment_homepage), "RDFa markup for the homepage of anonymous user found.");
+ // There should be no about attribute on anonymous comments.
+ $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]');
+ $this->assertTrue(empty($comment_homepage), "No about attribute is present on anonymous user comment.");
+ }
+
+ /**
+ * Test RDF comment replies.
+ */
+ public function testCommentReplyOfRdfaMarkup() {
+ // Posts comment #1 as a registered user.
+ $this->drupalLogin($this->web_user);
+ $comments[] = $this->postComment($this->node1, $this->randomName(), $this->randomName());
+
+ // Tests the reply_of relationship of a first level comment.
+ $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}")));
+ $this->assertEqual(1, count($result), 'RDFa markup referring to the node is present.');
+ $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')));
+ $this->assertFalse($result, 'No RDFa markup referring to the comment itself is present.');
+
+ // Posts a reply to the first comment.
+ $this->drupalGet('comment/reply/' . $this->node1->nid . '/' . $comments[0]->id);
+ $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
+
+ // Tests the reply_of relationship of a second level comment.
+ $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}")));
+ $this->assertEqual(1, count($result), 'RDFa markup referring to the node is present.');
+ $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'))));
+ $this->assertEqual(1, count($result), 'RDFa markup referring to the parent comment is present.');
+ $comments = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]");
+ }
+
+ /**
+ * Helper function for testCommentRdfaMarkup().
+ *
+ * Tests the current page for basic comment RDFa markup.
+ *
+ * @param $comment
+ * Comment object.
+ * @param $account
+ * An array containing information about an anonymous user.
+ */
+ function _testBasicCommentRdfaMarkup($comment, $account = array()) {
+ $comment_container = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]');
+ $this->assertTrue(!empty($comment_container), "Comment RDF type for comment found.");
+ $comment_title = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//h3[@property="dc:title"]');
+ $this->assertEqual((string)$comment_title[0]->a, $comment->subject, "RDFa markup for the comment title found.");
+ $comment_date = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//*[contains(@property, "dc:date") and contains(@property, "dc:created")]');
+ $this->assertTrue(!empty($comment_date), "RDFa markup for the date of the comment found.");
+ // The author tag can be either a or span
+ $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=""]');
+ $name = empty($account["name"]) ? $this->web_user->name : $account["name"] . " (not verified)";
+ $this->assertEqual((string)$comment_author[0], $name, "RDFa markup for the comment author found.");
+ $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"]');
+ $this->assertEqual((string)$comment_body[0]->p, $comment->comment, "RDFa markup for the comment body found.");
+ }
+}
+
+class RdfTrackerAttributesTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'RDF tracker page mapping',
+ 'description' => 'Test the mapping for the tracker page and ensure the proper RDFa markup in included.',
+ 'group' => 'RDF',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('rdf', 'rdf_test', 'tracker');
+ // Enable anonymous posting of content.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'create article content' => TRUE,
+ 'access comments' => TRUE,
+ 'post comments' => TRUE,
+ 'skip comment approval' => TRUE,
+ ));
+ }
+
+ /**
+ * Create nodes as both admin and anonymous user and test for correct RDFa
+ * markup on the tracker page for those nodes and their comments.
+ */
+ function testAttributesInTracker() {
+ // Create node as anonymous user.
+ $node_anon = $this->drupalCreateNode(array('type' => 'article', 'uid' => 0));
+ // Create node as admin user.
+ $node_admin = $this->drupalCreateNode(array('type' => 'article', 'uid' => 1));
+
+ // Pass both the anonymously posted node and the administrator posted node
+ // through to test for the RDF attributes.
+ $this->_testBasicTrackerRdfaMarkup($node_anon);
+ $this->_testBasicTrackerRdfaMarkup($node_admin);
+
+ }
+
+ /**
+ * Helper function for testAttributesInTracker().
+ *
+ * Tests the tracker page for RDFa markup.
+ *
+ * @param $node
+ * The node just created.
+ */
+ function _testBasicTrackerRdfaMarkup($node) {
+ $url = url('node/' . $node->nid);
+
+ $user = ($node->uid == 0) ? 'Anonymous user' : 'Registered user';
+
+ // Navigate to tracker page.
+ $this->drupalGet('tracker');
+
+ // Tests whether the about property is applied. This is implicit in the
+ // success of the following tests, but making it explicit will make
+ // debugging easier in case of failure.
+ $tracker_about = $this->xpath('//tr[@about=:url]', array(':url' => $url));
+ $this->assertTrue(!empty($tracker_about), format_string('About attribute found on table row for @user content.', array('@user'=> $user)));
+
+ // Tests whether the title has the correct property attribute.
+ $tracker_title = $this->xpath('//tr[@about=:url]/td[@property="dc:title" and @datatype=""]', array(':url' => $url));
+ $this->assertTrue(!empty($tracker_title), format_string('Title property attribute found on @user content.', array('@user'=> $user)));
+
+ // Tests whether the relationship between the content and user has been set.
+ $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));
+ $this->assertTrue(!empty($tracker_user), format_string('Typeof and name property attributes found on @user.', array('@user'=> $user)));
+ // There should be an about attribute on logged in users and no about
+ // attribute for anonymous users.
+ $tracker_user = $this->xpath('//tr[@about=:url]//td[@rel="sioc:has_creator"]/*[@about]', array(':url' => $url));
+ if ($node->uid == 0) {
+ $this->assertTrue(empty($tracker_user), format_string('No about attribute is present on @user.', array('@user'=> $user)));
+ }
+ elseif ($node->uid > 0) {
+ $this->assertTrue(!empty($tracker_user), format_string('About attribute is present on @user.', array('@user'=> $user)));
+ }
+
+ // Tests whether the property has been set for number of comments.
+ $tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "0") and @datatype="xsd:integer"]', array(':url' => $url));
+ $this->assertTrue($tracker_replies, format_string('Num replies property and content attributes found on @user content.', array('@user'=> $user)));
+
+ // Tests that the appropriate RDFa markup to annotate the latest activity
+ // date has been added to the tracker output before comments have been
+ // posted, meaning the latest activity reflects changes to the node itself.
+ $isoDate = date('c', $node->changed);
+ $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));
+ $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)));
+
+ // Tests that the appropriate RDFa markup to annotate the latest activity
+ // date has been added to the tracker output after a comment is posted.
+ $comment = array(
+ 'subject' => $this->randomName(),
+ 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(),
+ );
+ $this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
+ $this->drupalGet('tracker');
+
+ // Tests whether the property has been set for number of comments.
+ $tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "1") and @datatype="xsd:integer"]', array(':url' => $url));
+ $this->assertTrue($tracker_replies, format_string('Num replies property and content attributes found on @user content.', array('@user'=> $user)));
+
+ // Need to query database directly to obtain last_activity_date because
+ // it cannot be accessed via node_load().
+ $result = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid));
+ foreach ($result as $node) {
+ $expected_last_activity_date = $node->changed;
+ }
+ $isoDate = date('c', $expected_last_activity_date);
+ $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));
+ $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)));
+ }
+}
+
+/**
+ * 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['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.');
+ $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.');
+ $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.');
+ $this->assertTrue(!isset($ns['dc']), 'A prefix with conflicting namespaces is discarded.');
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.info b/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.info
new file mode 100644
index 0000000..e0fa92d
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.info
@@ -0,0 +1,12 @@
+name = "RDF module tests"
+description = "Support module for RDF module testing."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.install b/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.install
new file mode 100644
index 0000000..91a3392
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.install
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the rdf module.
+ */
+
+/**
+ * Implements hook_install().
+ */
+function rdf_test_install() {
+ $rdf_mappings = array(
+ array(
+ 'type' => 'node',
+ 'bundle' => 'test_bundle_hook_install',
+ 'mapping' => array(
+ 'rdftype' => array('foo:mapping_install1', 'bar:mapping_install2'),
+ ),
+ ),
+ );
+
+ foreach ($rdf_mappings as $rdf_mapping) {
+ rdf_mapping_save($rdf_mapping);
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.module b/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.module
new file mode 100644
index 0000000..c133a33
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/rdf/tests/rdf_test.module
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * @file
+ * Test API interaction with the RDF module.
+ */
+
+/**
+ * Implements hook_rdf_mapping().
+ */
+function rdf_test_rdf_mapping() {
+ return array(
+ array(
+ 'type' => 'test_entity',
+ 'bundle' => 'test_bundle',
+ 'mapping' => array(
+ 'rdftype' => array('sioc:Post'),
+ 'title' => array(
+ 'predicates' => array('dc:title'),
+ ),
+ 'created' => array(
+ 'predicates' => array('dc:created'),
+ 'datatype' => 'xsd:dateTime',
+ 'callback' => 'date_iso8601',
+ ),
+ '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(
+ 'type' => 'node',
+ 'bundle' => 'blog',
+ 'mapping' => array(
+ 'rdftype' => array('sioct:Weblog'),
+ ),
+ ),
+ );
+}
+
+/**
+ * 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/',
+ );
+}