From d59a91f5296e402604ddd42a76e6c2bd2eb716d0 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Thu, 11 Jul 2013 12:01:10 -0300 Subject: [PATCH 01/11] Logging in as user 1 in islandora_install_solution_pack() for drush installation of islandora modules. --- includes/solution_packs.inc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 26bd77b5..4e43a4c3 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -256,6 +256,14 @@ function islandora_install_solution_pack($module, $op = 'install') { return; } + // Login as user 1 if the installation is coming from the command line (e.g. + // drush). + if (drupal_is_cli()) { + global $user; + $user = user_load(1); + user_login_finalize(); + } + $t = get_t(); // Some general replacements. From 4d3642b1bc5971c2877bc809e1396eb736aef636 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Thu, 11 Jul 2013 12:46:39 -0300 Subject: [PATCH 02/11] Logging in as user 1 on solution pack uninstalls as well. --- includes/solution_packs.inc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 4e43a4c3..8e726f34 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -336,6 +336,15 @@ function islandora_install_solution_pack($module, $op = 'install') { * directly for each solution pack. */ function islandora_uninstall_solution_pack($module) { + + // Login as user 1 if the uninstall is coming from the command line (e.g. + // drush). + if (drupal_is_cli()) { + global $user; + $user = user_load(1); + user_login_finalize(); + } + $t = get_t(); module_load_include('module', 'islandora', 'islandora'); module_load_include('inc', 'islandora', 'includes/utilities'); From 0a213cb6d05befe17d5de2d9857b8fd148770d15 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Thu, 11 Jul 2013 16:49:26 -0300 Subject: [PATCH 03/11] Tuque cache will clear if new user is provided to islandora_get_tuque_connection. Tests. --- islandora.info | 1 + islandora.module | 14 ++++++--- tests/islandora_tuque.test | 59 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 tests/islandora_tuque.test diff --git a/islandora.info b/islandora.info index ce6ba947..31d79491 100644 --- a/islandora.info +++ b/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 diff --git a/islandora.module b/islandora.module index 5b45fb1a..d13d0b4e 100644 --- a/islandora.module +++ b/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'); diff --git a/tests/islandora_tuque.test b/tests/islandora_tuque.test new file mode 100644 index 00000000..4d8f0041 --- /dev/null +++ b/tests/islandora_tuque.test @@ -0,0 +1,59 @@ + '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()."); + } + +} From 0fc33b5e2fc1ece9f5b11029d3c4c3e4cdd2b395 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Fri, 12 Jul 2013 22:50:29 -0300 Subject: [PATCH 04/11] Committing so christian can write the test. --- islandora.module | 87 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 12 deletions(-) diff --git a/islandora.module b/islandora.module index d13d0b4e..e7e501fb 100644 --- a/islandora.module +++ b/islandora.module @@ -812,7 +812,7 @@ function islandora_default_islandora_view_object($object) { * * Includes some very basic error logging. * - * @param object $usr + * @param object $new_user * The user to connect as. * @param string $url * The URL to connect to. @@ -820,30 +820,93 @@ function islandora_default_islandora_view_object($object) { * @return IslandoraTuque * A IslandoraTuque instance */ -function islandora_get_tuque_connection($usr = NULL, $url = NULL) { +function islandora_get_tuque_connection($new_user = NULL, $url = NULL) { $tuque = &drupal_static(__FUNCTION__); 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($usr, $url); + // $user_for_tuque = NULL; + // + // if TUQUE DOES NOT EXIST { + // if PROVIDED USER IS NOT NULL { + // MAKE TUQUE WITH PROVIDED USER + // } + // else + // { + // MAKE TUQUE WITH GLOBAL USER + // } + // } + // else { + // if PROVIDED USER IS NOT NULL { + // if PROVIDED USER IS NOT TUQUE'S USER { + // MAKE TUQUE WITH PROVIDED USER + // } + // else { + // LEAVE TUQUE ALONE + // } + // } + // else { + // if GLOBAL USER IS NOT TUQUE'S USER { + // MAKE TUQUE WITH GLOBAL USER + // } + // else { + // LEAVE TUQUE ALONE + // } + // } + // } + + // If tuque is NULL. + if (!$tuque) { + // If the provided user is not null, pass it along to Tuque. + if ($new_user) { + $tuque = islandora_make_tuque($new_user, $url); + } + // Otherwise give Tuque the global user. + else { + $tuque = islandora_make_tuque($user, $url); + } + } + // Else, tuque already exists. So only make it if the users are different. + else { + if ($new_user) { + // Get the name of the new user. If it's '', then it's actually + // 'anonymous' as far as Tuque is concerned. + $new_user_name = $new_user->name; + if (empty($new_user_name)) { + $new_user_name = 'anonymous'; } - catch (Exception $e) { - drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + if ($new_user_name != $tuque->connection->username) { + $tuque = islandora_make_tuque($new_user); } } else { - return NULL; + // Get the name of the global user. If it's '', then it's actually + // 'anonymous' as far as Tuque is concerned. + $user_name = $user->name; + if (empty($user_name)) { + $user_name = 'anonymous'; + } + if ($user->name != $tuque->connection->username) { + $tuque = islandora_make_tuque($user); + } } } return $tuque; } +function islandora_make_tuque($user, $url) { + if (IslandoraTuque::exists()) { + try { + return new IslandoraTuque($user, $url); + } + catch (Exception $e) { + drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + } + } + + return NULL; +} + /** * Loads the object from the given ID if possible. * From 76a742618b75ac018de7e3f060d4112b32e79c24 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Fri, 23 Aug 2013 11:20:19 -0300 Subject: [PATCH 05/11] Test --- islandora.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.info b/islandora.info index 2f2aaa1a..2c4ff077 100644 --- a/islandora.info +++ b/islandora.info @@ -19,5 +19,5 @@ files[] = tests/hooked_access.test files[] = tests/islandora_manage_permissions.test files[] = tests/datastream_versions.test files[] = tests/derivatives.test -files[] = tests/islandora_tuque.test +files[] = tests/islandora_tuque.test php = 5.3 From 1a1a08ab20f006f03ff24c39f9ba37749f0d3304 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Fri, 23 Aug 2013 11:20:36 -0300 Subject: [PATCH 06/11] Revert "Test" This reverts commit 76a742618b75ac018de7e3f060d4112b32e79c24. --- islandora.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.info b/islandora.info index 2c4ff077..2f2aaa1a 100644 --- a/islandora.info +++ b/islandora.info @@ -19,5 +19,5 @@ files[] = tests/hooked_access.test files[] = tests/islandora_manage_permissions.test files[] = tests/datastream_versions.test files[] = tests/derivatives.test -files[] = tests/islandora_tuque.test +files[] = tests/islandora_tuque.test php = 5.3 From 04b4e0c0b1e0bf32a27d66f68cb9dad4923c3a4e Mon Sep 17 00:00:00 2001 From: Christian Selig Date: Wed, 28 Aug 2013 14:42:25 +0000 Subject: [PATCH 07/11] Added tests for tuque. --- includes/utilities.inc | 24 ++++++++++ tests/islandora_tuque.test | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/includes/utilities.inc b/includes/utilities.inc index 91988918..ffa0244b 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -912,3 +912,27 @@ function islandora_as_renderable_array(&$markup_array) { } unset($value); } + +/** + * Creates and returns a singleton of tuque if one does not already exist. + * + * @param object $user + * User who created the request. + * @param object $url + * URL to Fedora. + * + * @return IslandoraTuque + * An IslandoraTuque instance. + */ +function islandora_make_tuque($user, $url) { + if (IslandoraTuque::exists()) { + try { + return new IslandoraTuque($user, $url); + } + catch (Exception $e) { + drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + } + } + + return NULL; +} diff --git a/tests/islandora_tuque.test b/tests/islandora_tuque.test index 4d8f0041..13b5eff9 100644 --- a/tests/islandora_tuque.test +++ b/tests/islandora_tuque.test @@ -57,3 +57,94 @@ class IslandoraTuqueTestCase extends IslandoraWebTestCase { } } + + /** + * Tests that tuque does not exist and the user is not null. + */ + public function testTuqueDoesNotExistAndUserIsNotNull() { + $tuque = &drupal_static(__FUNCTION__); + $tuque = NULL; + + $user_to_provide = user_load(0); + + $new_tuque = islandora_get_tuque_connection($user_to_provide); + $new_tuque_user_name = $new_tuque->connection->username; + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($user_to_provide->name, $new_tuque_user_name); + } + + /** + * Tests that tuque does not exist and the user is null. + */ + public function testTuqueDoesNotExistAndUserIsNull() { + $tuque = &drupal_static(__FUNCTION__); + $tuque = NULL; + + $user_to_provide = NULL; + + $new_tuque = islandora_get_tuque_connection($user_to_provide); + $new_tuque_user_name = $new_tuque->connection->username; + + global $user; + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($new_tuque_user_name, $user); + } + + /** + * Test that tuque exists and the user is not null and the user is not tuque's + * user. + */ + public function testTuqueExistsAndUserIsNotNullAndUserIsNotTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + $user_to_provide = user_load(0); + $new_tuque = islandora_get_tuque_connection($user_to_provide); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertNotEqual($user_to_provide->name, $new_tuque->connection->username); + } + + /** + * Tests that tuque exists and the user is not null and the user is tuque's user + */ + public function testTuqueExistsAndUserIsNotNullAndUserIsTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + $new_tuque = islandora_get_tuque_connection($tuque->connection->username); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($tuque->connection->username, $new_tuque->connection->username); + } + + /** + * Tests that tuque exists and the user is null and the global user is not + * tuque's user. + */ + public function testTuqueExistsAndUserIsNullAndGlobalUserIsNotTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + global $user = NULL; + $new_tuque = islandora_get_tuque_connection($user); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertNotEqual($new_tuque->connection->username, $user); + } + + /** + * Tests that tuque exists and the user is null and the global user is tuque's + * user. + */ + public function testTuqueExistsAndUserIsNullAndGlobalUserIsTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + global $user = $tuque->connection->username; + $new_tuque = islandora_get_tuque_connection($user); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($new_tuque->connection->username, $user); + } + From 86d85e96d2a4ea99e2def187b8271365598e198e Mon Sep 17 00:00:00 2001 From: Christian Selig Date: Thu, 29 Aug 2013 18:39:17 +0000 Subject: [PATCH 08/11] Fixed coding standards issues. --- includes/utilities.inc | 4 +- islandora.module | 41 +++------- tests/islandora_tuque.test | 151 ++++++++++++++++++------------------- 3 files changed, 87 insertions(+), 109 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index ffa0244b..971cfaac 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -916,9 +916,9 @@ function islandora_as_renderable_array(&$markup_array) { /** * Creates and returns a singleton of tuque if one does not already exist. * - * @param object $user + * @param object $user * User who created the request. - * @param object $url + * @param object $url * URL to Fedora. * * @return IslandoraTuque diff --git a/islandora.module b/islandora.module index cb9f38ec..727b06b0 100644 --- a/islandora.module +++ b/islandora.module @@ -998,36 +998,6 @@ function islandora_get_tuque_connection($new_user = NULL, $url = NULL) { global $user; - // $user_for_tuque = NULL; - // - // if TUQUE DOES NOT EXIST { - // if PROVIDED USER IS NOT NULL { - // MAKE TUQUE WITH PROVIDED USER - // } - // else - // { - // MAKE TUQUE WITH GLOBAL USER - // } - // } - // else { - // if PROVIDED USER IS NOT NULL { - // if PROVIDED USER IS NOT TUQUE'S USER { - // MAKE TUQUE WITH PROVIDED USER - // } - // else { - // LEAVE TUQUE ALONE - // } - // } - // else { - // if GLOBAL USER IS NOT TUQUE'S USER { - // MAKE TUQUE WITH GLOBAL USER - // } - // else { - // LEAVE TUQUE ALONE - // } - // } - // } - // If tuque is NULL. if (!$tuque) { // If the provided user is not null, pass it along to Tuque. @@ -1067,6 +1037,17 @@ function islandora_get_tuque_connection($new_user = NULL, $url = NULL) { return $tuque; } +/** + * Creates a singleton of tuque. + * + * @param object $user + * The user to create tuque with. + * @param string $url + * The URL to create tuque with. + * + * @return IslandoraTuque + * The singleton tuque object. + */ function islandora_make_tuque($user, $url) { if (IslandoraTuque::exists()) { try { diff --git a/tests/islandora_tuque.test b/tests/islandora_tuque.test index 13b5eff9..dab3117b 100644 --- a/tests/islandora_tuque.test +++ b/tests/islandora_tuque.test @@ -58,93 +58,90 @@ class IslandoraTuqueTestCase extends IslandoraWebTestCase { } - /** - * Tests that tuque does not exist and the user is not null. - */ - public function testTuqueDoesNotExistAndUserIsNotNull() { - $tuque = &drupal_static(__FUNCTION__); - $tuque = NULL; - - $user_to_provide = user_load(0); +/** + * Tests that tuque does not exist and the user is not null. + */ +public function testTuqueDoesNotExistAndUserIsNotNull() { + $tuque = &drupal_static(__FUNCTION__); + $tuque = NULL; - $new_tuque = islandora_get_tuque_connection($user_to_provide); - $new_tuque_user_name = $new_tuque->connection->username; + $user_to_provide = user_load(0); - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($user_to_provide->name, $new_tuque_user_name); - } + $new_tuque = islandora_get_tuque_connection($user_to_provide); + $new_tuque_user_name = $new_tuque->connection->username; - /** - * Tests that tuque does not exist and the user is null. - */ - public function testTuqueDoesNotExistAndUserIsNull() { - $tuque = &drupal_static(__FUNCTION__); - $tuque = NULL; + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($user_to_provide->name, $new_tuque_user_name); +} - $user_to_provide = NULL; +/** + * Tests that tuque does not exist and the user is null. + */ +public function testTuqueDoesNotExistAndUserIsNull() { + $tuque = &drupal_static(__FUNCTION__); + $tuque = NULL; - $new_tuque = islandora_get_tuque_connection($user_to_provide); - $new_tuque_user_name = $new_tuque->connection->username; + $user_to_provide = NULL; - global $user; + $new_tuque = islandora_get_tuque_connection($user_to_provide); + $new_tuque_user_name = $new_tuque->connection->username; - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($new_tuque_user_name, $user); - } + global $user; - /** - * Test that tuque exists and the user is not null and the user is not tuque's - * user. - */ - public function testTuqueExistsAndUserIsNotNullAndUserIsNotTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - $user_to_provide = user_load(0); - $new_tuque = islandora_get_tuque_connection($user_to_provide); - - assertNotNull($new_tuque); - assertNotNull($tuque); - assertNotEqual($user_to_provide->name, $new_tuque->connection->username); - } + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($new_tuque_user_name, $user); +} - /** - * Tests that tuque exists and the user is not null and the user is tuque's user - */ - public function testTuqueExistsAndUserIsNotNullAndUserIsTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - $new_tuque = islandora_get_tuque_connection($tuque->connection->username); +/** + * Test that tuque exists, the user is not null, the user is not tuque's user. + */ +public function testTuqueExistsAndUserIsNotNullAndUserIsNotTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + $user_to_provide = user_load(0); + $new_tuque = islandora_get_tuque_connection($user_to_provide); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertNotEqual($user_to_provide->name, $new_tuque->connection->username); +} - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($tuque->connection->username, $new_tuque->connection->username); - } +/** + * Tests that tuque exists, the user is not null, the user is tuque's user. + */ +public function testTuqueExistsAndUserIsNotNullAndUserIsTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + $new_tuque = islandora_get_tuque_connection($tuque->connection->username); - /** - * Tests that tuque exists and the user is null and the global user is not - * tuque's user. - */ - public function testTuqueExistsAndUserIsNullAndGlobalUserIsNotTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - global $user = NULL; - $new_tuque = islandora_get_tuque_connection($user); - - assertNotNull($new_tuque); - assertNotNull($tuque); - assertNotEqual($new_tuque->connection->username, $user); - } + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($tuque->connection->username, $new_tuque->connection->username); +} - /** - * Tests that tuque exists and the user is null and the global user is tuque's - * user. - */ - public function testTuqueExistsAndUserIsNullAndGlobalUserIsTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - global $user = $tuque->connection->username; - $new_tuque = islandora_get_tuque_connection($user); - - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($new_tuque->connection->username, $user); - } +/** + * Tests that tuque exists, the user is null, global user is not tuque's user. + */ +public function testTuqueExistsAndUserIsNullAndGlobalUserIsNotTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + global $user = NULL; + $new_tuque = islandora_get_tuque_connection($user); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertNotEqual($new_tuque->connection->username, $user); +} +/** + * Tests that tuque exists, the user is null, global user is tuque's user. + */ +public function testTuqueExistsAndUserIsNullAndGlobalUserIsTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + global $_islandora_user; + $_islandora_user = $tuque->connection->username; + $new_tuque = islandora_get_tuque_connection($user); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($new_tuque->connection->username, $user); +} From 31aafceb6c0a3ca7dc2f413a883c97af297f37b6 Mon Sep 17 00:00:00 2001 From: Christian Selig Date: Fri, 30 Aug 2013 17:52:49 +0000 Subject: [PATCH 09/11] Attempt at fixing tests. --- tests/islandora_tuque.test | 149 ++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/tests/islandora_tuque.test b/tests/islandora_tuque.test index dab3117b..83ec4b91 100644 --- a/tests/islandora_tuque.test +++ b/tests/islandora_tuque.test @@ -56,92 +56,91 @@ class IslandoraTuqueTestCase extends IslandoraWebTestCase { $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()."); } -} - -/** - * Tests that tuque does not exist and the user is not null. - */ -public function testTuqueDoesNotExistAndUserIsNotNull() { - $tuque = &drupal_static(__FUNCTION__); - $tuque = NULL; + /** + * Tests that tuque does not exist and the user is not null. + */ + public function testTuqueDoesNotExistAndUserIsNotNull() { + $tuque = &drupal_static(__FUNCTION__); + $tuque = NULL; - $user_to_provide = user_load(0); + $user_to_provide = user_load(0); - $new_tuque = islandora_get_tuque_connection($user_to_provide); - $new_tuque_user_name = $new_tuque->connection->username; + $new_tuque = islandora_get_tuque_connection($user_to_provide); + $new_tuque_user_name = $new_tuque->connection->username; - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($user_to_provide->name, $new_tuque_user_name); -} + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($user_to_provide->name, $new_tuque_user_name); + } -/** - * Tests that tuque does not exist and the user is null. - */ -public function testTuqueDoesNotExistAndUserIsNull() { - $tuque = &drupal_static(__FUNCTION__); - $tuque = NULL; + /** + * Tests that tuque does not exist and the user is null. + */ + public function testTuqueDoesNotExistAndUserIsNull() { + $tuque = &drupal_static(__FUNCTION__); + $tuque = NULL; - $user_to_provide = NULL; + $user_to_provide = NULL; - $new_tuque = islandora_get_tuque_connection($user_to_provide); - $new_tuque_user_name = $new_tuque->connection->username; + $new_tuque = islandora_get_tuque_connection($user_to_provide); + $new_tuque_user_name = $new_tuque->connection->username; - global $user; + global $user; - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($new_tuque_user_name, $user); -} + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($new_tuque_user_name, $user); + } -/** - * Test that tuque exists, the user is not null, the user is not tuque's user. - */ -public function testTuqueExistsAndUserIsNotNullAndUserIsNotTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - $user_to_provide = user_load(0); - $new_tuque = islandora_get_tuque_connection($user_to_provide); - - assertNotNull($new_tuque); - assertNotNull($tuque); - assertNotEqual($user_to_provide->name, $new_tuque->connection->username); -} + /** + * Test that tuque exists, the user is not null, the user is not tuque's user. + */ + public function testTuqueExistsAndUserIsNotNullAndUserIsNotTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + $user_to_provide = user_load(0); + $new_tuque = islandora_get_tuque_connection($user_to_provide); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertNotEqual($user_to_provide->name, $new_tuque->connection->username); + } -/** - * Tests that tuque exists, the user is not null, the user is tuque's user. - */ -public function testTuqueExistsAndUserIsNotNullAndUserIsTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - $new_tuque = islandora_get_tuque_connection($tuque->connection->username); + /** + * Tests that tuque exists, the user is not null, the user is tuque's user. + */ + public function testTuqueExistsAndUserIsNotNullAndUserIsTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + $new_tuque = islandora_get_tuque_connection($tuque->connection->username); - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($tuque->connection->username, $new_tuque->connection->username); -} + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($tuque->connection->username, $new_tuque->connection->username); + } -/** - * Tests that tuque exists, the user is null, global user is not tuque's user. - */ -public function testTuqueExistsAndUserIsNullAndGlobalUserIsNotTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - global $user = NULL; - $new_tuque = islandora_get_tuque_connection($user); - - assertNotNull($new_tuque); - assertNotNull($tuque); - assertNotEqual($new_tuque->connection->username, $user); -} + /** + * Tests that tuque exists, the user is null, global user is not tuque's user. + */ + public function testTuqueExistsAndUserIsNullAndGlobalUserIsNotTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + global $user = NULL; + $new_tuque = islandora_get_tuque_connection($user); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertNotEqual($new_tuque->connection->username, $user); + } -/** - * Tests that tuque exists, the user is null, global user is tuque's user. - */ -public function testTuqueExistsAndUserIsNullAndGlobalUserIsTuquesUser() { - $tuque = &drupal_static(__FUNCTION__); - global $_islandora_user; - $_islandora_user = $tuque->connection->username; - $new_tuque = islandora_get_tuque_connection($user); - - assertNotNull($new_tuque); - assertNotNull($tuque); - assertEqual($new_tuque->connection->username, $user); + /** + * Tests that tuque exists, the user is null, global user is tuque's user. + */ + public function testTuqueExistsAndUserIsNullAndGlobalUserIsTuquesUser() { + $tuque = &drupal_static(__FUNCTION__); + global $_islandora_user; + $_islandora_user = $tuque->connection->username; + $new_tuque = islandora_get_tuque_connection($user); + + assertNotNull($new_tuque); + assertNotNull($tuque); + assertEqual($new_tuque->connection->username, $user); + } } From 542922429700066d4bb98986e6cd9b0bf2d443e4 Mon Sep 17 00:00:00 2001 From: Christian Selig Date: Fri, 30 Aug 2013 18:10:15 +0000 Subject: [PATCH 10/11] Further attempt at fixing tests. --- tests/islandora_tuque.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/islandora_tuque.test b/tests/islandora_tuque.test index 83ec4b91..ca3b5612 100644 --- a/tests/islandora_tuque.test +++ b/tests/islandora_tuque.test @@ -122,7 +122,8 @@ class IslandoraTuqueTestCase extends IslandoraWebTestCase { */ public function testTuqueExistsAndUserIsNullAndGlobalUserIsNotTuquesUser() { $tuque = &drupal_static(__FUNCTION__); - global $user = NULL; + global $user; + $user = NULL; $new_tuque = islandora_get_tuque_connection($user); assertNotNull($new_tuque); From 36238d7d97c8720fc7b029490aae13eec78f6029 Mon Sep 17 00:00:00 2001 From: Christian Selig Date: Fri, 30 Aug 2013 18:51:52 +0000 Subject: [PATCH 11/11] Removed duplicated islandora_make_tuque function. --- islandora.module | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/islandora.module b/islandora.module index 727b06b0..b7c9857a 100644 --- a/islandora.module +++ b/islandora.module @@ -994,6 +994,8 @@ function islandora_default_islandora_printer_object($object, $alter) { * A IslandoraTuque instance */ function islandora_get_tuque_connection($new_user = NULL, $url = NULL) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $tuque = &drupal_static(__FUNCTION__); global $user; @@ -1037,30 +1039,6 @@ function islandora_get_tuque_connection($new_user = NULL, $url = NULL) { return $tuque; } -/** - * Creates a singleton of tuque. - * - * @param object $user - * The user to create tuque with. - * @param string $url - * The URL to create tuque with. - * - * @return IslandoraTuque - * The singleton tuque object. - */ -function islandora_make_tuque($user, $url) { - if (IslandoraTuque::exists()) { - try { - return new IslandoraTuque($user, $url); - } - catch (Exception $e) { - drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); - } - } - - return NULL; -} - /** * Loads the object from the given ID if possible. *