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(); diff --git a/fedora_repository.test.inc b/fedora_repository.test.inc new file mode 100644 index 00000000..e9fad088 --- /dev/null +++ b/fedora_repository.test.inc @@ -0,0 +1,154 @@ + + * + * administrator + * + * + */ +abstract class IslandoraTestCase extends DrupalWebTestCase { + + /** + * User with the rights required to perform the test + */ + protected $privileged_user; + + /** + * Override this method to provide the name of the module, + * e.g. the name of the .module file + * + * @return string - The name of the module + */ + abstract protected function getModuleName(); + + /** + * Returns basic permissions needed for running Islandora tests. + * Override this method to provide additional permissions, but + * be sure to append your new permissions to the return value + * of parent::getUserPermissions and return that. + * + * @return array - An array of strings describing permissions + */ + protected function getUserPermissions() { + return array( + 'access content', + 'add fedora datastreams', + 'edit fedora meta data', + 'edit tags datastream', + 'ingest new fedora objects', + 'purge objects and datastreams', + 'view fedora collection', + 'view detailed list of content', + ); + } + + /** + * Creates a user with permissions required for the test, and logs in. + */ + protected function createPrivilegedUser() { + // Create a role with the permissions from getUserPermissions() + $role = $this->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(); + } +} + +/** + * 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"); + } +}