From 886de6449b77a4951d6d2c35502586237b7b47e1 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Mon, 15 Oct 2012 15:04:57 -0300 Subject: [PATCH 1/7] Changed hook name from 'required_fedora_objects' to 'fedora_repository_required_fedora_objects'. --- fedora_repository.solutionpacks.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index e1835556..81f5a256 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -33,7 +33,7 @@ * Builds the tab for the solution packs. */ function fedora_repository_solution_packs_page() { - $enabled_solution_packs = module_invoke_all('required_fedora_objects'); + $enabled_solution_packs = module_invoke_all('fedora_repository_required_fedora_objects'); $output = ''; foreach ($enabled_solution_packs as $solution_pack_module => $solution_pack_info) { $objects = array(); From 6a75c547c9bf72cba0a63a4c61dc52254f9a3f15 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Thu, 25 Oct 2012 15:16:01 -0230 Subject: [PATCH 2/7] Added base classes for testing islandora and its solution packs. --- fedora_repository.solutionpacks.inc | 24 +++++++ fedora_repository.test.inc | 98 +++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 fedora_repository.test.inc diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 81f5a256..3b40c054 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -257,3 +257,27 @@ function solution_pack_add_form_association($content_model, $form_name) { drupal_set_message(t("Added association between @cm and @name", array("@cm" => $content_model, "@name" => $form_name))); } } + + +module_load_include('inc', 'fedora_repository', 'fedora_repository.test'); + +/** + * Class containing tests that are common to all solution packs. + */ +abstract class SolutionPackTestCase extends IslandoraTestCase { + + /** + * Tests the fedora_repository_required_fedora_objects hook. + */ + public function testFedoraRepositoryRequiredFedoraObjects() { + $results = module_invoke($this->getModuleShortFormName(), 'fedora_repository_required_fedora_objects'); + + $this->assertNotNull($results, 'A non-null result was returned from the fedora_repository_required_fedora_objects hook.'); + $this->assertTrue(is_array($results), 'An array was returned from the fedora_repository_required_fedora_objects hook.'); + $this->assertTrue(array_key_exists($this->getModuleShortFormName(), $results), "Returned array has top level key that is equal to the module's short form name"); + $this->assertTrue(is_array($results[$this->getModuleShortFormName()]), "Value associated with top level key that is eqal to the module's short form name is an array"); + $this->assertTrue(array_key_exists('module', $results[$this->getModuleShortFormName()]), "Top level array has 'module' key"); + $this->assertEqual($results[$this->getModuleShortFormName()]['module'], $this->getModuleShortFormName(), "Value associated with 'module' key is equal to the module's short form name"); + + } +} diff --git a/fedora_repository.test.inc b/fedora_repository.test.inc new file mode 100644 index 00000000..14121f81 --- /dev/null +++ b/fedora_repository.test.inc @@ -0,0 +1,98 @@ +drupalCreateRole($this->getUserPermissions()); + + // Create a user model + $user = array( + 'name' => 'simpletestuser', + 'mail' => 'simpletestuser@example.com', + 'roles' => array( $role => $role ), + 'pass' => 'simpletestpass', + 'status' => 1, + ); + + // Create a user from the model + $this->privileged_user = user_save('', $user); + + // Add the raw password so we can log in + $this->privileged_user->pass_raw = $user['pass']; + + // Log in + !$this->drupalLogin($this->privileged_user); + } + + /** + * Automatically generates all module dependencies and enables them in order. + * Also logs in a privileged user with the appropriate permissions for the + * test. + * + * If you need to override this method to provide extra functionality, + * please be sure to call parent::setUp so dependency resolution and + * authentication still happen. + */ + public function setUp() { + // Grab all the available modules + $modules = module_rebuild_cache(); + + // Grab the module to test's dependencies + $dependencies = $modules[$this->getModuleShortFormName()]->info['dependencies']; + + // Sort them so they're in the correct order to enable + $dependencies = array_reverse($dependencies); + + // Add our module to the end + $dependencies[] = $this->getModuleShortFormName(); + + // Enable the module's dependencies in order + call_user_func_array('parent::setUp', $dependencies); + + // Authenticate the privileged user + $this->createPrivilegedUser(); + } +} From 6e4c1e2a3bf381e61643e414cedfd726abcdf157 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Fri, 26 Oct 2012 11:43:52 -0230 Subject: [PATCH 3/7] Finalized schema to test for in the required_fedora_objects test. --- fedora_repository.solutionpacks.inc | 32 ++++++++++++++++++++++++++--- fedora_repository.test.inc | 3 +-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index 3b40c054..c0861a94 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -267,17 +267,43 @@ module_load_include('inc', 'fedora_repository', 'fedora_repository.test'); abstract class SolutionPackTestCase extends IslandoraTestCase { /** - * Tests the fedora_repository_required_fedora_objects hook. + * Tests the fedora_repository_required_fedora_objects hook. + * + * Validates the schema of the array returned by the hook. The array should + * be roughly of the form: + * [ + * module_name => + * [ + * 'module' => module_name, + * 'title' => module_title, + * 'objects' => + * [ + * ... + * ] + * ] + * ] + * + * Where each entry of the 'objects' sub-array should be arrays themselves, + * each containing the information needed for drupal_get_form(). + * + * Note that the root key of the array is the actual module name (e.g. + * islandora_audio_sp, islandora_image_sp, etc...), not 'module_name' */ public function testFedoraRepositoryRequiredFedoraObjects() { + + // Invoke the hook $results = module_invoke($this->getModuleShortFormName(), 'fedora_repository_required_fedora_objects'); + // Validate the schema of the returned data structure $this->assertNotNull($results, 'A non-null result was returned from the fedora_repository_required_fedora_objects hook.'); $this->assertTrue(is_array($results), 'An array was returned from the fedora_repository_required_fedora_objects hook.'); $this->assertTrue(array_key_exists($this->getModuleShortFormName(), $results), "Returned array has top level key that is equal to the module's short form name"); - $this->assertTrue(is_array($results[$this->getModuleShortFormName()]), "Value associated with top level key that is eqal to the module's short form name is an array"); + $this->assertTrue(is_array($results[$this->getModuleShortFormName()]), "Value associated with top level key that is equal to the module's short form name is an array"); $this->assertTrue(array_key_exists('module', $results[$this->getModuleShortFormName()]), "Top level array has 'module' key"); $this->assertEqual($results[$this->getModuleShortFormName()]['module'], $this->getModuleShortFormName(), "Value associated with 'module' key is equal to the module's short form name"); - + $this->assertTrue(array_key_exists('title', $results[$this->getModuleShortFormName()]), "Top level array has 'title' key"); + $this->assertTrue($results[$this->getModuleShortFormName()]['title'], "Title string is not empty"); + $this->assertTrue(array_key_exists('objects', $results[$this->getModuleShortFormName()]), "Returned array has second level key equal to 'object'"); + $this->assertTrue(is_array($results[$this->getModuleShortFormName()]['objects']), "Value associated with second level 'object' key is an array"); } } diff --git a/fedora_repository.test.inc b/fedora_repository.test.inc index 14121f81..1296cf00 100644 --- a/fedora_repository.test.inc +++ b/fedora_repository.test.inc @@ -4,8 +4,7 @@ * @file * Generic test case to be extended to implement Islandora testing. */ -abstract class IslandoraTestCase extends DrupalWebTestCase -{ +abstract class IslandoraTestCase extends DrupalWebTestCase { /** * User with the rights required to perform the test From 36002603e243a96772e686cdaeda2cfd591a98f5 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Fri, 26 Oct 2012 11:56:06 -0230 Subject: [PATCH 4/7] Changed invalid reference to to match the function's parameter. Was getting an exception when trying to construct the query for the SOAP call in getOwnerId() --- api/fedora_item.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 4a26e516..b1fecb65 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -1553,7 +1553,7 @@ RDF; static function getOwnerId($PID) { $params = array( - 'query' => array(array('property' => 'pid', 'operator' => 'eq', 'value' => $object_id)), + 'query' => array(array('property' => 'pid', 'operator' => 'eq', 'value' => $PID)), 'resultFields' => array('pid', 'ownerId'), 'maxResults' => 1, ); From 2843214c2a4d65cdad2247a2ddda77240f916288 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Fri, 26 Oct 2012 11:56:06 -0230 Subject: [PATCH 5/7] Changed invalid object_id reference to PID to match the function's parameter. Was getting an exception when trying to construct the query for the SOAP call in getOwnerId() --- api/fedora_item.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 4a26e516..b1fecb65 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -1553,7 +1553,7 @@ RDF; static function getOwnerId($PID) { $params = array( - 'query' => array(array('property' => 'pid', 'operator' => 'eq', 'value' => $object_id)), + 'query' => array(array('property' => 'pid', 'operator' => 'eq', 'value' => $PID)), 'resultFields' => array('pid', 'ownerId'), 'maxResults' => 1, ); From 6b57a06c2d624664442627d7886b549a52402910 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Fri, 26 Oct 2012 16:59:01 -0230 Subject: [PATCH 6/7] Added instructions to create test user in comments --- fedora_repository.test.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fedora_repository.test.inc b/fedora_repository.test.inc index 1296cf00..ed945191 100644 --- a/fedora_repository.test.inc +++ b/fedora_repository.test.inc @@ -3,6 +3,16 @@ /** * @file * Generic test case to be extended to implement Islandora testing. + * + * In order to use this properly, you must place a test user in + * your Fedora installation. Please add the follwing snippet to your + * $FEDORA_HOME/server/config/fedora-users.xml: + * + * + * + * administrator + * + * */ abstract class IslandoraTestCase extends DrupalWebTestCase { From 4d5e68e91d509ad8f416d3be9beb0fb399384c58 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Mon, 29 Oct 2012 12:24:37 -0230 Subject: [PATCH 7/7] Making changes as per Jon Green's suggestions --- fedora_repository.solutionpacks.inc | 50 --------------------------- fedora_repository.test.inc | 53 +++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 53 deletions(-) diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc index c0861a94..81f5a256 100644 --- a/fedora_repository.solutionpacks.inc +++ b/fedora_repository.solutionpacks.inc @@ -257,53 +257,3 @@ function solution_pack_add_form_association($content_model, $form_name) { drupal_set_message(t("Added association between @cm and @name", array("@cm" => $content_model, "@name" => $form_name))); } } - - -module_load_include('inc', 'fedora_repository', 'fedora_repository.test'); - -/** - * Class containing tests that are common to all solution packs. - */ -abstract class SolutionPackTestCase extends IslandoraTestCase { - - /** - * Tests the fedora_repository_required_fedora_objects hook. - * - * Validates the schema of the array returned by the hook. The array should - * be roughly of the form: - * [ - * module_name => - * [ - * 'module' => module_name, - * 'title' => module_title, - * 'objects' => - * [ - * ... - * ] - * ] - * ] - * - * Where each entry of the 'objects' sub-array should be arrays themselves, - * each containing the information needed for drupal_get_form(). - * - * Note that the root key of the array is the actual module name (e.g. - * islandora_audio_sp, islandora_image_sp, etc...), not 'module_name' - */ - public function testFedoraRepositoryRequiredFedoraObjects() { - - // Invoke the hook - $results = module_invoke($this->getModuleShortFormName(), 'fedora_repository_required_fedora_objects'); - - // Validate the schema of the returned data structure - $this->assertNotNull($results, 'A non-null result was returned from the fedora_repository_required_fedora_objects hook.'); - $this->assertTrue(is_array($results), 'An array was returned from the fedora_repository_required_fedora_objects hook.'); - $this->assertTrue(array_key_exists($this->getModuleShortFormName(), $results), "Returned array has top level key that is equal to the module's short form name"); - $this->assertTrue(is_array($results[$this->getModuleShortFormName()]), "Value associated with top level key that is equal to the module's short form name is an array"); - $this->assertTrue(array_key_exists('module', $results[$this->getModuleShortFormName()]), "Top level array has 'module' key"); - $this->assertEqual($results[$this->getModuleShortFormName()]['module'], $this->getModuleShortFormName(), "Value associated with 'module' key is equal to the module's short form name"); - $this->assertTrue(array_key_exists('title', $results[$this->getModuleShortFormName()]), "Top level array has 'title' key"); - $this->assertTrue($results[$this->getModuleShortFormName()]['title'], "Title string is not empty"); - $this->assertTrue(array_key_exists('objects', $results[$this->getModuleShortFormName()]), "Returned array has second level key equal to 'object'"); - $this->assertTrue(is_array($results[$this->getModuleShortFormName()]['objects']), "Value associated with second level 'object' key is an array"); - } -} diff --git a/fedora_repository.test.inc b/fedora_repository.test.inc index ed945191..e9fad088 100644 --- a/fedora_repository.test.inc +++ b/fedora_repository.test.inc @@ -22,12 +22,12 @@ abstract class IslandoraTestCase extends DrupalWebTestCase { protected $privileged_user; /** - * Override this method to provide the short form name of the module, + * Override this method to provide the name of the module, * e.g. the name of the .module file * - * @return string - The short form name of the module + * @return string - The name of the module */ - abstract protected function getModuleShortFormName(); + abstract protected function getModuleName(); /** * Returns basic permissions needed for running Islandora tests. @@ -105,3 +105,50 @@ abstract class IslandoraTestCase extends DrupalWebTestCase { $this->createPrivilegedUser(); } } + +/** + * Class containing tests that are common to all solution packs. + */ +abstract class SolutionPackTestCase extends IslandoraTestCase { + + /** + * Tests the fedora_repository_required_fedora_objects hook. + * + * Validates the schema of the array returned by the hook. The array should + * be roughly of the form: + * [ + * module_name => + * [ + * 'module' => module_name, + * 'title' => module_title, + * 'objects' => + * [ + * ... + * ] + * ] + * ] + * + * Where each entry of the 'objects' sub-array should be arrays themselves, + * each containing the information needed for drupal_get_form(). + * + * Note that the root key of the array is the actual module name (e.g. + * islandora_audio_sp, islandora_image_sp, etc...), not 'module_name' + */ + public function testFedoraRepositoryRequiredFedoraObjects() { + + // Invoke the hook + $results = module_invoke($this->getModuleShortFormName(), 'fedora_repository_required_fedora_objects'); + + // Validate the schema of the returned data structure + $this->assertNotNull($results, 'A non-null result was returned from the fedora_repository_required_fedora_objects hook.'); + $this->assertTrue(is_array($results), 'An array was returned from the fedora_repository_required_fedora_objects hook.'); + $this->assertTrue(array_key_exists($this->getModuleShortFormName(), $results), "Returned array has top level key that is equal to the module's short form name"); + $this->assertTrue(is_array($results[$this->getModuleShortFormName()]), "Value associated with top level key that is equal to the module's short form name is an array"); + $this->assertTrue(array_key_exists('module', $results[$this->getModuleShortFormName()]), "Top level array has 'module' key"); + $this->assertEqual($results[$this->getModuleShortFormName()]['module'], $this->getModuleShortFormName(), "Value associated with 'module' key is equal to the module's short form name"); + $this->assertTrue(array_key_exists('title', $results[$this->getModuleShortFormName()]), "Top level array has 'title' key"); + $this->assertTrue($results[$this->getModuleShortFormName()]['title'], "Title string is not empty"); + $this->assertTrue(array_key_exists('objects', $results[$this->getModuleShortFormName()]), "Returned array has second level key equal to 'object'"); + $this->assertTrue(is_array($results[$this->getModuleShortFormName()]['objects']), "Value associated with second level 'object' key is an array"); + } +}