Browse Source

Added base classes for testing islandora and its solution packs.

pull/192/head
Daniel Lamb 12 years ago
parent
commit
6a75c547c9
  1. 24
      fedora_repository.solutionpacks.inc
  2. 98
      fedora_repository.test.inc

24
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))); 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");
}
}

98
fedora_repository.test.inc

@ -0,0 +1,98 @@
<?php
/**
* @file
* Generic test case to be extended to implement Islandora testing.
*/
abstract class IslandoraTestCase extends DrupalWebTestCase
{
/**
* User with the rights required to perform the test
*/
protected $privileged_user;
/**
* Override this method to provide the short form name of the module,
* e.g. the name of the .module file
*
* @return string - The short form name of the module
*/
abstract protected function getModuleShortFormName();
/**
* 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();
}
}
Loading…
Cancel
Save