Browse Source

Making changes as per Jon Green's suggestions

pull/192/head
Daniel Lamb 12 years ago
parent
commit
4d5e68e91d
  1. 50
      fedora_repository.solutionpacks.inc
  2. 53
      fedora_repository.test.inc

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

53
fedora_repository.test.inc

@ -22,12 +22,12 @@ abstract class IslandoraTestCase extends DrupalWebTestCase {
protected $privileged_user; 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 * 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. * Returns basic permissions needed for running Islandora tests.
@ -105,3 +105,50 @@ abstract class IslandoraTestCase extends DrupalWebTestCase {
$this->createPrivilegedUser(); $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");
}
}

Loading…
Cancel
Save