Browse Source

Tuque cache will clear if new user is provided to islandora_get_tuque_connection. Tests.

pull/364/head
Daniel Lamb 11 years ago
parent
commit
0a213cb6d0
  1. 1
      islandora.info
  2. 14
      islandora.module
  3. 59
      tests/islandora_tuque.test

1
islandora.info

@ -17,4 +17,5 @@ files[] = tests/hooks.test
files[] = tests/ingest.test
files[] = tests/hooked_access.test
files[] = tests/islandora_manage_permissions.test
files[] = tests/islandora_tuque.test
php = 5.3

14
islandora.module

@ -812,7 +812,7 @@ function islandora_default_islandora_view_object($object) {
*
* Includes some very basic error logging.
*
* @param object $user
* @param object $usr
* The user to connect as.
* @param string $url
* The URL to connect to.
@ -820,12 +820,18 @@ function islandora_default_islandora_view_object($object) {
* @return IslandoraTuque
* A IslandoraTuque instance
*/
function islandora_get_tuque_connection($user = NULL, $url = NULL) {
function islandora_get_tuque_connection($usr = NULL, $url = NULL) {
$tuque = &drupal_static(__FUNCTION__);
if (!$tuque) {
global $user;
$no_tuque_yet = !$tuque;
$user_is_different = ($usr && $usr->uid != $user->uid);
if ($no_tuque_yet || $user_is_different) {
if (IslandoraTuque::exists()) {
try {
$tuque = new IslandoraTuque($user, $url);
$tuque = new IslandoraTuque($usr, $url);
}
catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');

59
tests/islandora_tuque.test

@ -0,0 +1,59 @@
<?php
/**
* @file
* Tests islandora tuque functionality.
*/
class IslandoraTuqueTestCase extends IslandoraWebTestCase {
/**
* Gets info to display to describe this test.
*
* @see IslandoraWebTestCase::getInfo()
*/
public static function getInfo() {
return array(
'name' => 'Islandora Tuque',
'description' => 'Tests basic tuque functionality.',
'group' => 'Islandora',
);
}
/**
* Prepares enviroment for testing.
*
* @see IslandoraWebTestCase::setUp()
*/
public function setUp() {
parent::setUp(array('islandora'));
}
/**
* Tests that a new tuque instance is created when a new user is provided.
*/
public function testTuqueUserChange() {
global $user;
$tuque = islandora_get_tuque_connection($user);
$old_user_name = $tuque->connection->username;
$new_user = user_load(0);
$tuque = islandora_get_tuque_connection($new_user);
$new_user_name = $tuque->connection->username;
$this->assertNotEqual($old_user_name, $new_user_name, "User in tuque's connection changes when a new user is provided to islandora_get_tuque_connection().");
$old_user_name = $new_user_name;
$tuque = islandora_get_tuque_connection();
$new_user_name = $tuque->connection->username;
$this->assertEqual($old_user_name, $new_user_name, "User in tuque's connection does not change when no user is provided to islandora_get_tuque_connection().");
}
}
Loading…
Cancel
Save