;
+ fm:state fm:Active
+ }
+ OPTIONAL{
+ ?object fm:label ?label
+ }
+ }";
$content_models = array();
- $results = $tuque->repository->ri->itqlQuery($query, 'unlimited');
+ $results = $tuque->repository->ri->sparqlQuery($query, 'unlimited');
foreach ($results as $result) {
$content_model = $result['object']['value'];
$label = $result['label']['value'];
@@ -738,3 +760,60 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) {
}
return $content_models;
}
+
+/**
+ * Returns Drupal tableselect element allowing selection of Content Models.
+ *
+ * @param string $drupal_variable
+ * the name of the Drupal variable holding selected content models
+ * Content models held in this variable will appear at the top of
+ * the displayed list
+ * @param array $default_values_array
+ * default values to display if $drupal_variable is unset
+ *
+ * @return array
+ * Drupal form element allowing content model selection
+ */
+function islandora_content_model_select_table_form_element($drupal_variable, $default_values_array = array('')) {
+ $defaults = array();
+ $rows = array();
+ $content_models = array();
+ $options = islandora_get_content_models(TRUE);
+ foreach ($options as $option) {
+ $content_models[$option['pid']] = $option['label'];
+ }
+
+ $selected = array_values(variable_get($drupal_variable, $default_values_array));
+ $comparator = function ($a, $b) use ($selected) {
+ $a_val = $b_val = 0;
+ if (in_array($a, $selected)) {
+ $a_val = 1;
+ }
+ if (in_array($b, $selected)) {
+ $b_val = 1;
+ }
+ return $b_val - $a_val;
+ };
+ uksort($content_models, $comparator);
+ foreach ($content_models as $pid => $label) {
+ $rows[$pid] = array(
+ 'pid' => $pid,
+ 'title' => $label,
+ );
+ $defaults[$pid] = in_array($pid, $selected);
+ }
+ $header = array(
+ 'pid' => array('data' => t('PID')),
+ 'title' => array('data' => t('Content Model')),
+ );
+ // Build and return table element.
+ $element = array(
+ '#type' => 'tableselect',
+ '#header' => $header,
+ '#options' => $rows,
+ '#default_value' => $defaults,
+ '#empty' => t("There are no content models in this Fedora Repository."),
+ );
+
+ return $element;
+}
diff --git a/islandora.api.php b/islandora.api.php
index 5e976194..17db59ad 100644
--- a/islandora.api.php
+++ b/islandora.api.php
@@ -45,11 +45,24 @@ function hook_CMODEL_PID_islandora_view_object($object) {
* @param FedoraObject $object
* A Tuque FedoraObject being operated on.
* @param array $rendered
- * An arr of rendered views.
+ * The array of rendered views.
*/
function hook_islandora_view_object_alter(&$object, &$rendered) {
}
+/**
+ * Alter display output if the object has the given model.
+ *
+ * @see hook_islandora_view_object_alter()
+ *
+ * @param FedoraObject $object
+ * A Tuque FedoraObject being operated on.
+ * @param array $rendered
+ * The array of rendered views.
+ */
+function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) {
+}
+
/**
* Generate an object's management display.
*
@@ -291,7 +304,7 @@ function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastre
}
/**
- * Notify modules that the given datastream was ingested.
+ * Notify modules that the given datastream was modified.
*
* @see hook_islandora_datastream_modified()
*/
@@ -373,15 +386,26 @@ function hook_islandora_undeletable_datastreams(array $models) {
* @return array
* An associative array of associative arrays which define each step in the
* ingest process. Each step should consist of a unique name mapped to an
- * array of properties (keys) including:
- * - type: The type of step. Currently, only "form" is implemented.
- * - weight: The "weight" of this step--heavier(/"larger") values sink to the
- * end of the process while smaller(/"lighter") values are executed first.
+ * array of properties (keys) which take different paramaters based upon type:
+ * - type: Type of step. Only "form" and "callback" are implemented so far.
+ * Required "form" type specific parameters:
* - form_id: The form building function to call to get the form structure
* for this step.
* - args: An array of arguments to pass to the form building function.
- * And may optionally include both:
+ * Required "callback" type specific parameters:
+ * - do_function: An associate array including:
+ * - 'function': The callback function to be called.
+ * - 'args': An array of arguments to pass to the callback function.
+ * - undo_function: An associate array including:
+ * - 'function': The callback function to be called to reverse the
+ * executed action in the ingest steps.
+ * - 'args': An array of arguments to pass to the callback function.
+ * Shared parameters between both types:
+ * - weight: The "weight" of this step--heavier(/"larger") values sink to the
+ * end of the process while smaller(/"lighter") values are executed first.
+ * Both types may optionally include:
* - module: A module from which we want to load an include.
+ * "Form" type may optionally include:
* - file: A file to include (relative to the module's path, including the
* file's extension).
*/
@@ -393,6 +417,18 @@ function hook_islandora_ingest_steps(array $form_state) {
'form_id' => 'my_cool_form',
'args' => array('arg_one', 'numero deux'),
),
+ 'my_cool_step_callback' => array(
+ 'type' => 'callback',
+ 'weight' => 2,
+ 'do_function' => array(
+ 'function' => 'my_cool_execute_function',
+ 'args' => array('arg_one', 'numero deux'),
+ ),
+ 'undo_function' => array(
+ 'function' => 'my_cool_undo_function',
+ 'args' => array('arg_one', 'numero deux'),
+ ),
+ ),
);
}
/**
diff --git a/islandora.install b/islandora.install
index 9a1825b5..caff7d75 100644
--- a/islandora.install
+++ b/islandora.install
@@ -10,13 +10,14 @@
*/
function islandora_requirements($phase) {
$requirements = array();
- // Ensure translations don't break at install time
+
+ // Ensure translations don't break at install time.
$t = get_t();
if (!class_exists('XSLTProcessor', FALSE)) {
$requirements['islandora_xsltprocessor']['title'] = $t('Islandora XSLTProcessor Prerequisite');
$requirements['islandora_xsltprocessor']['value'] = $t('Not installed');
- $link = l($t('PHP XSL extension'), 'http://us2.php.net/manual/en/book.xsl.php', array('attributes' => array('target'=>'_blank')));
+ $link = l($t('PHP XSL extension'), 'http://us2.php.net/manual/en/book.xsl.php', array('attributes' => array('target' => '_blank')));
$requirements['islandora_xsltprocessor']['description'] = $t('The !xsllink is required. Check your installed PHP extensions and php.ini file.', array('!xsllink' => $link));
$requirements['islandora_xsltprocessor']['severity'] = REQUIREMENT_ERROR;
}
diff --git a/islandora.module b/islandora.module
index 94aedbe0..ad9e569e 100644
--- a/islandora.module
+++ b/islandora.module
@@ -120,7 +120,7 @@ function islandora_menu() {
FEDORA_METADATA_EDIT,
FEDORA_ADD_DS,
FEDORA_PURGE,
- FEDORA_INGEST
+ FEDORA_INGEST,
), 2),
);
@@ -238,12 +238,13 @@ function islandora_menu() {
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
'load arguments' => array(2),
);
- $items['islandora/ingest'] = array(
- 'title' => 'Add an Object',
- 'page callback' => 'islandora_ingest_callback',
- 'file' => 'includes/ingest.menu.inc',
- 'type' => MENU_SUGGESTED_ITEM,
- 'access arguments' => array(FEDORA_INGEST),
+ $items['islandora/object/%islandora_object/download_clip'] = array(
+ 'page callback' => 'islandora_download_clip',
+ 'page arguments' => array(2),
+ 'type' => MENU_CALLBACK,
+ 'access callback' => 'islandora_object_access_callback',
+ 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
+ 'load arguments' => array(2),
);
return $items;
}
@@ -286,6 +287,29 @@ function islandora_theme() {
'file' => 'theme/theme.inc',
'variables' => array('object' => NULL, 'content' => array()),
),
+ // Render a bunch of objects as either a grid or a list.
+ 'islandora_objects' => array(
+ 'file' => 'theme/theme.inc',
+ 'template' => 'theme/islandora-objects',
+ 'variables' => array(
+ 'objects' => NULL,
+ 'display' => NULL,
+ 'page_size' => 20,
+ 'limit' => 10,
+ ),
+ ),
+ // Render a bunch of objects as a grid.
+ 'islandora_objects_grid' => array(
+ 'file' => 'theme/theme.inc',
+ 'template' => 'theme/islandora-objects-grid',
+ 'variables' => array('objects' => NULL),
+ ),
+ // Render a bunch of objects as a list.
+ 'islandora_objects_list' => array(
+ 'file' => 'theme/theme.inc',
+ 'template' => 'theme/islandora-objects-list',
+ 'variables' => array('objects' => NULL),
+ ),
);
}
@@ -334,6 +358,88 @@ function islandora_forms($form_id) {
return $forms;
}
+/**
+ * Checks whether the user can access the given object.
+ *
+ * Checks for repository access, object/datastream existance, namespace access,
+ * user permissions, content models.
+ *
+ * Will check the given user or the user repersented by the GET token parameter,
+ * failing that it will use the global user.
+ *
+ * @global $user
+ *
+ * @param mixed $object
+ * The FedoraObject or FedoraDatastream to test for accessibility, if NULL
+ * is given the object is assumed to not exist or be inaccessible.
+ * @param array $permissions
+ * The required user permissions.
+ * @param array $content_models
+ * The required content models.
+ * @param bool $access_any
+ * (optional) TRUE to grant access if any single requirement is met from both
+ * the permissions and content models parameters. FALSE if all requirements
+ * must be met from both the permissions and content model parameters.
+ * @param object $account
+ * (optional) The account to check, if not given check the GET parameters for
+ * a token to restore the user. If no GET parameter is present use currently
+ * logged in user.
+ *
+ * @return bool
+ * TRUE if the user is allowed to access this object/datastream, FALSE
+ * otherwise.
+ */
+function islandora_user_access($object, array $permissions, $content_models = array(), $access_any = TRUE, $account = NULL) {
+ module_load_include('inc', 'islandora', 'includes/utilities');
+ $is_repository_accessible = &drupal_static(__FUNCTION__);
+ // If the repository is inaccessible then access always fails.
+ if (!isset($is_repository_accessible)) {
+ $is_repository_accessible = islandora_describe_repository();
+ if (!$is_repository_accessible) {
+ // Only display the inaccessible message once.
+ islandora_display_repository_inaccessible_message();
+ return FALSE;
+ }
+ }
+ if (!$is_repository_accessible || !is_object($object)) {
+ return FALSE;
+ }
+ // Determine the user account to test against.
+ if (!isset($account)) {
+ $token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
+ if ($token) {
+ module_load_include('inc', 'islandora', 'includes/authtokens');
+ $user = islandora_validate_object_token($object->id, $datastream->id, $token);
+ if ($user) {
+ $account = user_load($user->uid);
+ }
+ }
+ else {
+ global $user;
+ $account = $user;
+ }
+ }
+ // Determine what has been passed as $object.
+ if (is_subclass_of($object, 'FedoraObject')) {
+ $object = $object;
+ }
+ elseif (is_subclass_of($object, 'FedoraDatastream')) {
+ $datastream = $object;
+ $object = $datastream->parent;
+ }
+ // Check for access.
+ $accessible_namespace = islandora_namespace_accessible($object->id);
+ if ($access_any) {
+ $has_required_permissions = islandora_user_access_any($permissions, $account);
+ $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0;
+ }
+ else {
+ $has_required_permissions = islandora_user_access_all($permissions, $account);
+ $has_required_content_models = count(array_diff($content_models, $object->models)) == 0;
+ }
+ return $accessible_namespace && $has_required_permissions && $has_required_content_models;
+}
+
/**
* Checks whether the user can access the given object.
*
@@ -570,7 +676,8 @@ function islandora_view_object(FedoraObject $object) {
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
$output = array();
- foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models) as $hook) {
+ $hooks = islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models);
+ foreach ($hooks as $hook) {
// @todo Remove page number and size from this hook, implementers of the
// hook should use drupal page handling directly.
$temp = module_invoke_all($hook, $object, $page_number, $page_size);
@@ -583,7 +690,7 @@ function islandora_view_object(FedoraObject $object) {
$output = islandora_default_islandora_view_object($object);
}
arsort($output);
- drupal_alter(ISLANDORA_VIEW_HOOK, $object, $output);
+ drupal_alter($hooks, $object, $output);
return implode('', $output);
}
@@ -859,7 +966,7 @@ function islandora_delete_object(FedoraObject &$object) {
$object = NULL;
return TRUE;
}
- catch(Exception $e) {
+ catch (Exception $e) {
// Exception message gets logged in Tuque Wrapper.
return FALSE;
}
@@ -964,7 +1071,29 @@ function islandora_entity_property_info() {
* @return array
* A renderable array.
*/
-function islandora_print_object(FedoraObject $object) {
+function islandora_print_object(AbstractObject $object) {
drupal_set_title($object->label);
return theme('islandora_object_print', array('object' => $object));
}
+
+/**
+ * Menu callback downloads the given clip.
+ */
+function islandora_download_clip(AbstractObject $object) {
+ if (isset($_GET['clip'])) {
+ $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
+ $http_protocol = $is_https ? 'https' : 'http';
+ $url = $http_protocol . '://' . $_SERVER['HTTP_HOST'] . $_GET['clip'];
+ $filename = $object->label;
+ header("Content-Disposition: attachment; filename=\"{$filename}.jpg\"");
+ header("Content-type: image/jpeg");
+ header("Content-Transfer-Encoding: binary");
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_URL, $url);
+ $response = curl_exec($ch);
+ curl_close($ch);
+ }
+ exit();
+}
diff --git a/tests/README.txt b/tests/README.txt
index 797d788b..c03004ae 100644
--- a/tests/README.txt
+++ b/tests/README.txt
@@ -1,3 +1,4 @@
You can define your own configurations specific to your enviroment by copying
default.test_config.ini to test_config.ini, making your changes in the copied
-file.
\ No newline at end of file
+file. These test need write access to the system's $FEDORA_HOME/server/config
+directory as well as the filter-drupal.xml file.
\ No newline at end of file
diff --git a/tests/hooks.test b/tests/hooks.test
index 0a667fee..3133d656 100644
--- a/tests/hooks.test
+++ b/tests/hooks.test
@@ -32,7 +32,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
* @see IslandoraWebTestCase::setUp()
*/
public function setUp() {
- parent::setUp('islandora_hooks_test', 'devel');
+ parent::setUp('islandora_hooks_test');
$this->repository = $this->admin->repository;
$this->purgeTestObjects();
}
@@ -67,7 +67,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$object->label = "Don't Block";
$this->repository->purgeObject($object->id);
}
- catch(Exception $e) {
+ catch (Exception $e) {
// Meh... Either it didn't exist or the purge failed.
}
}
@@ -95,7 +95,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$this->fail('Blocked ingest should throw an Exception.');
$this->repository->purgeObject($object->id);
}
- catch(Exception $e) {
+ catch (Exception $e) {
$this->pass('Ingest blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.');
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.');
@@ -115,7 +115,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$object->label = 'block';
$this->fail('Blocked modify should throw an Exception.');
}
- catch(Exception $e) {
+ catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.');
$this->assertNotEqual($object->label, 'block', 'Modification did not stick.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.');
@@ -149,7 +149,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$this->repository->purgeObject($object->id);
$this->fail('Blocked modify should throw an Exception.');
}
- catch(Exception $e) {
+ catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.');
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.');
@@ -191,7 +191,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$ds->label = 'block';
$this->fail('Blocked modify should throw an Exception.');
}
- catch(Exception $e) {
+ catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.');
$this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.');
diff --git a/tests/islandora_test.info b/tests/islandora_hooks_test.info
similarity index 62%
rename from tests/islandora_test.info
rename to tests/islandora_hooks_test.info
index c6cb57ad..9d211978 100644
--- a/tests/islandora_test.info
+++ b/tests/islandora_hooks_test.info
@@ -1,6 +1,7 @@
-name = Islandora Test Module
+name = Islandora Hook testing
description = Tests Hooks. Do not enable.
core = 7.x
package = Testing
hidden = TRUE
dependencies[] = islandora
+files[] = islandora_hooks_test.module
diff --git a/tests/islandora_test.module b/tests/islandora_hooks_test.module
similarity index 100%
rename from tests/islandora_test.module
rename to tests/islandora_hooks_test.module
diff --git a/tests/islandora_manage_permissions.test b/tests/islandora_manage_permissions.test
index 76f43a6d..8fc1549f 100644
--- a/tests/islandora_manage_permissions.test
+++ b/tests/islandora_manage_permissions.test
@@ -1,7 +1,17 @@
'Islandora Manage Permissions',
@@ -10,69 +20,117 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
);
}
+ /**
+ * Prepares enviroment for testing.
+ *
+ * @see IslandoraWebTestCase::setUp()
+ */
public function setUp() {
parent::setUp(array('islandora'));
}
+ /**
+ * Test manage permissions.
+ */
public function testManagePermissions() {
-
-
- // permission FEDORA_VIEW_OBJECTS
- // create a user with permission
+ // Test permission FEDORA_VIEW_OBJECTS.
+ // Create a user with permission.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
- // log the user in
+ // Log the user in.
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertNoLink('Manage', 'Manage tab is not on current page.');
-
-
- // permission FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES
+
+ // Test permission FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES));
- // log the user in
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
$this->clickLink(t('Manage'));
$this->assertLink('Properties', 0, 'Properties tab is on current page.');
$this->assertNoLink('Datastreams', 'Datastreams tab is not on current page.');
- $this->assertNoLink('Collection','Collection tab is not on current page.');
+ $this->assertNoLink('Collection', 'Collection tab is not on current page.');
-
- // permission FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS
+ // Test permission FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS));
- // log the user in
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
$this->clickLink(t('Manage'));
$this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.');
$this->assertNoLink('Properties', 'Properties tab is not on current page.');
- $this->assertNoLink('Collection','Collection tab is not on current page.');
-
-
- // permission FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT
+ $this->assertNoLink('Collection', 'Collection tab is not on current page.');
+
+ // Test permission FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT));
- // log the user in
- $this->drupalLogin($user);
+ $this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
$this->clickLink(t('Manage'));
$this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.');
$this->assertNoLink('Properties', 'Properties tab is not on current page.');
- $this->assertNoLink('Collection','Collection tab is not on current page.');
-
-
- // permission FEDORA_VIEW_OBJECTS, FEDORA_PURGE
+ $this->assertNoLink('Collection', 'Collection tab is not on current page.');
+
+ // Test permission FEDORA_VIEW_OBJECTS, FEDORA_PURGE.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE));
- // log the user in
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
$this->clickLink(t('Manage'));
$this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.');
$this->assertNoLink('Properties', 'Properties tab is not on current page.');
- $this->assertNoLink('Collection','Collection tab is not on current page.');
-
+ $this->assertNoLink('Collection', 'Collection tab is not on current page.');
}
- }
\ No newline at end of file
+ /**
+ * Test generic access functions.
+ *
+ * Note that we can't test with the Global user as SimpleTest doesn't support
+ * it. Therefore we can't test the authtoken support.
+ */
+ public function testAccessFunctions() {
+ $object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root'));
+ // Test islandora_user_access().
+ // Test no object/permissions.
+ $ret = islandora_user_access(NULL, array());
+ $this->assertFalse($ret, 'User access denied when no object/permissions are provided.');
+ // Test with object no permissions.
+ $ret = islandora_user_access($object, array());
+ $this->assertFalse($ret, 'User access denied when no permissions are provided.');
+ // Test access with matching permission.
+ $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user);
+ $this->assertTrue($ret, 'User access granted when permissions match.');
+ // Test access with matching permission but access any is FALSE.
+ $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array(), FALSE, $user);
+ $this->assertFalse($ret, 'User access denied for matching permission but with access any set to FALSE.');
+ // Test access with non-matching permission.
+ $user = $this->drupalCreateUser(array(FEDORA_PURGE));
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user);
+ $this->assertFalse($ret, 'User access denied when permissions did not match.');
+ // Test access with both permissions and content model.
+ $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
+ $model = $object->models;
+ $model = reset($model);
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array($model), TRUE, $user);
+ $this->assertTrue($ret, 'User access granted for matching permission and model.');
+ // Test access with matching permissions and non-matching content model.
+ $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array('islandora:obviouslyNotACModel'), TRUE, $user);
+ $this->assertFalse($ret, 'User access denied for matching permission and non-matching model.');
+ // Test access with all matching permissions and one matching model but
+ // access any is FALSE.
+ $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE));
+ $model = $object->models;
+ $model = reset($model);
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array($model, 'islandora:obviouslyNotACModel'), FALSE, $user);
+ $this->assertFalse($ret, 'User access denied for all matching permissions and one matching model but with access any set to FALSE.');
+ $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array($model), FALSE, $user);
+ $this->assertTrue($ret, 'User access granted for all matching permissions and matching models with access any set to FALSE.');
+ // Test passing in a Datastream.
+ $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE));
+ $ret = islandora_user_access($object['DC'], array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user);
+ $this->assertTrue($ret, 'User access granted for matching permissions, with a datastream given instead of an object.');
+ }
+}
diff --git a/tests/scripts/line_endings.sh b/tests/scripts/line_endings.sh
new file mode 100755
index 00000000..b72dde22
--- /dev/null
+++ b/tests/scripts/line_endings.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+RETURN=0
+FILES=`find -L $1 -name "*.info" -o -name "*.txt" -o -name "*.md"`
+echo "Testing for files with DOS line endings..."
+for FILE in $FILES
+do
+ file $FILE | grep CRLF
+ if [ $? == 0 ]
+ then
+ RETURN=1
+ fi
+done
+exit $RETURN
diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh
new file mode 100755
index 00000000..c3515198
--- /dev/null
+++ b/tests/scripts/travis_setup.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+mysql -u root -e 'create database drupal;'
+mysql -u root -e "create database fedora;"
+mysql -u root -e "GRANT ALL PRIVILEGES ON fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';"
+mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';"
+cd $HOME
+git clone git://github.com/Islandora/tuque.git
+git clone -b $FEDORA_VERSION git://github.com/Islandora/islandora_tomcat.git
+cd islandora_tomcat
+export CATALINA_HOME='.'
+./bin/startup.sh
+cd $HOME
+pyrus channel-discover pear.drush.org
+pyrus channel-discover pear.phpqatools.org
+pyrus channel-discover pear.netpirates.net
+pyrus install drush/drush
+pyrus install pear/PHP_CodeSniffer
+pyrus install pear.phpunit.de/phpcpd
+phpenv rehash
+drush dl --yes drupal
+cd drupal-*
+drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes
+drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/dev/null &
+ln -s $ISLANDORA_DIR sites/all/modules/islandora
+mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini
+mkdir sites/all/libraries
+ln -s $HOME/tuque sites/all/libraries/tuque
+drush dl --yes coder
+drush dl --yes potx
+drush en --yes coder_review
+drush en --yes simpletest
+drush en --yes potx
+drush en --user=1 --yes islandora
+drush cc all
+sleep 4
diff --git a/tests/travis.test_config.ini b/tests/travis.test_config.ini
new file mode 100644
index 00000000..61d63713
--- /dev/null
+++ b/tests/travis.test_config.ini
@@ -0,0 +1,6 @@
+[fedora]
+fedora_url = "http://localhost:8080/fedora"
+use_drupal_filter = TRUE
+drupal_filter_file = "/home/travis/islandora_tomcat/fedora/server/config/filter-drupal.xml"
+admin_user = "fedoraAdmin"
+admin_pass = "fedoraAdmin"
diff --git a/tests/web_test_case.inc b/tests/web_test_case.inc
index a513de43..8a5b9a00 100644
--- a/tests/web_test_case.inc
+++ b/tests/web_test_case.inc
@@ -18,6 +18,11 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
// Always enable islandora.
$args[] = 'islandora';
parent::setUp($args);
+
+ // Its possible test are running before class autoloading.
+ module_load_include('inc', 'islandora', 'includes/tuque');
+ module_load_include('inc', 'islandora', 'includes/tuque_wrapper');
+
$this->configuration = $this->getTestConfiguration();
if ($this->configuration['use_drupal_filter']) {
$this->backUpDrupalFilter();
diff --git a/theme/islandora-objects-grid.tpl.php b/theme/islandora-objects-grid.tpl.php
new file mode 100644
index 00000000..e6d7e140
--- /dev/null
+++ b/theme/islandora-objects-grid.tpl.php
@@ -0,0 +1,17 @@
+
+
diff --git a/theme/islandora-objects-list.tpl.php b/theme/islandora-objects-list.tpl.php
new file mode 100644
index 00000000..67f5f02d
--- /dev/null
+++ b/theme/islandora-objects-list.tpl.php
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+
+
diff --git a/theme/islandora-objects.tpl.php b/theme/islandora-objects.tpl.php
new file mode 100644
index 00000000..f1893ef6
--- /dev/null
+++ b/theme/islandora-objects.tpl.php
@@ -0,0 +1,21 @@
+
+
+
+ $display_links,
+ 'attributes' => array('class' => array('links', 'inline')),
+ )
+ );
+ ?>
+
+
+
+
+
diff --git a/theme/theme.inc b/theme/theme.inc
index 87e44fc1..7c43deef 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -157,3 +157,64 @@ function islandora_preprocess_islandora_object_print(array &$variables) {
function theme_islandora_object_print(array &$variables) {
return drupal_render($variables['content']);
}
+
+/**
+ * Implements hook_preprocess_theme().
+ */
+function islandora_preprocess_islandora_objects(array &$variables) {
+ module_load_include('inc', 'islandora_paged_content', 'includes/utilities');
+ $display = (empty($_GET['display'])) ? 'grid' : $_GET['display'];
+ $grid_display = $display == 'grid';
+ $list_display = !$grid_display;
+ $query_params = drupal_get_query_parameters($_GET);
+ $variables['display_links'] = array(
+ array(
+ 'title' => t('Grid view'),
+ 'href' => url($_GET['q'], array('absolute' => TRUE)),
+ 'attributes' => array(
+ 'class' => $grid_display ? 'active' : '',
+ ),
+ 'query' => array('display' => 'grid') + $query_params,
+ ),
+ array(
+ 'title' => t('List view'),
+ 'href' => url($_GET['q'], array('absolute' => TRUE)),
+ 'attributes' => array(
+ 'class' => $list_display ? 'active' : '',
+ ),
+ 'query' => array('display' => 'list') + $query_params,
+ ),
+ );
+ // Pager.
+ $objects = $variables['objects'];
+ $limit = $variables['limit'];
+ $page_size = $variables['page_size'];
+ $page = pager_default_initialize(count($objects), $limit);
+ $objects = array_slice($objects, $page * $limit, $limit);
+ $variables['pager'] = theme('pager', array('quantity' => 10));
+ // Content.
+ $map_objects = function($o) {
+ $o = islandora_object_load($o);
+ $url = "islandora/object/{$o->id}";
+ $link_options = array('html' => TRUE, 'attributes' => array('title' => $o->label));
+ $img = theme_image(array('path' => url("$url/datastream/TN/view"), 'attributes' => array()));
+ $description = NULL;
+ $dc = DublinCore::importFromXMLString($o['DC']->content);
+ if ($dc) {
+ $dc = $dc->asArray();
+ $description = $dc['dc:description']['value'];
+ }
+ return array(
+ 'label' => $o->label,
+ 'class' => drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $o->id)),
+ 'link' => l($o->label, $url, $link_options),
+ 'thumb' => l($img, $url, $link_options),
+ 'description' => $description,
+ );
+ };
+ $objects = array_map($map_objects, $objects);
+ $theme = $grid_display ? 'islandora_objects_grid' : 'islandora_objects_list';
+ $variables['content'] = theme($theme, array('objects' => $objects));
+ $module_path = drupal_get_path('module', 'islandora');
+ drupal_add_css("$module_path/css/islandora.objects.css");
+}