Browse Source

last bit of bugfixes and cleanup

pull/507/head
qadan 11 years ago
parent
commit
fc357e6f7d
  1. 36
      includes/derivatives.inc
  2. 16
      tests/includes/datastream_validators.inc
  3. 42
      tests/includes/utilities.inc

36
includes/derivatives.inc

@ -21,25 +21,29 @@ function islandora_run_derivatives(AbstractObject $object, $dsid) {
islandora_derivative_logging($logging_results); islandora_derivative_logging($logging_results);
} }
else { else {
batch_set( $operations = islandora_do_batch_derivatives(
// Title won't show for batch in a batch. $object,
array( array(
'init_message' => t('Preparing derivatives for @label', array('@label' => $object->label)), 'source_dsid' => $dsid,
'error_message' => t('An error occured creating derivatives.'),
'progress_message' => t(
'Creating derivatives for @label <br/>Time elapsed: @elapsed <br/>
Estimated time remaining @estimate.',
array('@label' => $object->label)
),
'file' => drupal_get_path('module', 'islandora') . '/includes/regenerate_derivatives.form.inc',
'operations' => islandora_do_batch_derivatives(
$object,
array(
'source_dsid' => $dsid,
)
),
) )
); );
if ($operations) {
batch_set(
// Title won't show for batch in a batch.
array(
'init_message' => t('Preparing derivatives for @label', array('@label' => $object->label)),
'error_message' => t('An error occured creating derivatives.'),
'progress_message' => t(
'Creating derivatives for @label <br/>Time elapsed: @elapsed <br/>
Estimated time remaining @estimate.',
array('@label' => $object->label)
),
'file' => drupal_get_path('module', 'islandora') . '/includes/regenerate_derivatives.form.inc',
'operations' => $operations,
'finished' => 'islandora_regenerate_derivative_batch_finished',
)
);
}
} }
} }

16
tests/includes/datastream_validators.inc

@ -48,7 +48,7 @@ function islandora_hex2int($hex) {
* Abstraction for datastream validators. * Abstraction for datastream validators.
* *
* Classes extended from DatastreamValidator don't require much to be useful. * Classes extended from DatastreamValidator don't require much to be useful.
* They accept an IslandoraFedoraObject and a DSID to perform assertions on; * They accept a Fedora object and a DSID to perform assertions on;
* all you have to do is place a series of functions inside the extended class * all you have to do is place a series of functions inside the extended class
* using the naming convention assertThing(); each of these functions should * using the naming convention assertThing(); each of these functions should
* ideally assert one thing and one thing only (for simplicity's sake), and * ideally assert one thing and one thing only (for simplicity's sake), and
@ -67,9 +67,9 @@ function islandora_hex2int($hex) {
abstract class DatastreamValidator extends IslandoraTestUtilityClass { abstract class DatastreamValidator extends IslandoraTestUtilityClass {
/** /**
* The IslandoraFedoraObject containing the datastream to test. * The Fedora object containing the datastream to test.
* *
* @var IslandoraFedoraObject * @var IslandoraFedoraObject|FedoraObject
*/ */
public $object; public $object;
@ -97,14 +97,14 @@ abstract class DatastreamValidator extends IslandoraTestUtilityClass {
/** /**
* Constructs a DatastreamValidator. * Constructs a DatastreamValidator.
* *
* @param IslandoraFedoraObject $object * @param IslandoraFedoraObject|FedoraObject $object
* The object to grab the datastream from. * The object to grab the datastream from.
* @param string $datastream * @param string $datastream
* The DSID of the datastream itself. * The DSID of the datastream itself.
* @param array $params * @param array $params
* An extra array of parameters the validator might need. * An extra array of parameters the validator might need.
*/ */
public function __construct(IslandoraFedoraObject $object, $datastream, array $params = array()) { public function __construct($object, $datastream, array $params = array()) {
$this->object = $object; $this->object = $object;
$this->datastream = $datastream; $this->datastream = $datastream;
$this->params = $params; $this->params = $params;
@ -343,7 +343,7 @@ class TextDatastreamValidator extends DatastreamValidator {
/** /**
* Constructor override; blow up if we don't have our two values. * Constructor override; blow up if we don't have our two values.
*/ */
public function __construct(IslandoraFedoraObject $object, $datastream, array $params = array()) { public function __construct($object, $datastream, array $params = array()) {
if (count($params) < 2) { if (count($params) < 2) {
throw new InvalidArgumentException('$params must contain at least two values to instantiate a TextDatastreamValidator.'); throw new InvalidArgumentException('$params must contain at least two values to instantiate a TextDatastreamValidator.');
} }
@ -386,14 +386,14 @@ class WAVDatastreamValidator extends DatastreamValidator {
/** /**
* We need a special constructor here to get the hex datastream content. * We need a special constructor here to get the hex datastream content.
* *
* @param IslandoraFedoraObject $object * @param IslandoraFedoraObject|FedoraObject $object
* The object to grab the datastream from. * The object to grab the datastream from.
* @param string $datastream * @param string $datastream
* The DSID of the datastream itself. * The DSID of the datastream itself.
* @param array $params * @param array $params
* An extra array of parameters the validator might need. * An extra array of parameters the validator might need.
*/ */
public function __construct(IslandoraFedoraObject $object, $datastream, array $params = array()) { public function __construct($object, $datastream, array $params = array()) {
parent::__construct($object, $datastream, $params); parent::__construct($object, $datastream, $params);
$this->datastreamContent = bin2hex($this->datastreamContent); $this->datastreamContent = bin2hex($this->datastreamContent);
} }

42
tests/includes/utilities.inc

@ -261,17 +261,9 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass {
public function __construct($configuration, array $params = array()) { public function __construct($configuration, array $params = array()) {
$this->configuration = $configuration; $this->configuration = $configuration;
$this->params = $params; $this->params = $params;
// If we have DB access, we want to use the Islandora Tuque wrappers. $connection = new RepositoryConnection($this->configuration['fedora_url'], $this->configuration['admin_user'], $this->configuration['admin_pass']);
if ($params['db_access']) { $api = new FedoraApi($connection);
$connection = islandora_get_tuque_connection(); $this->repository = new FedoraRepository($api, new SimpleCache());
$this->repository = $connection->repository;
}
// Otherwise, get a generic Tuque repository.
else {
$connection = new RepositoryConnection($this->configuration['fedora_url'], $this->configuration['admin_user'], $this->configuration['admin_pass']);
$api = new FedoraApi($connection);
$this->repository = new FedoraRepository($api, new SimpleCache());
}
} }
/** /**
@ -317,9 +309,9 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass {
* Asserts that the given datastreams exist correctly on the object. * Asserts that the given datastreams exist correctly on the object.
* *
* @param AbstractObject $object * @param AbstractObject $object
* The PID of the object * The object to check.
* @param array $datastreams * @param array $datastreams
* An array of strings containing datastream names * An array of strings containing datastream names.
* *
* @return bool * @return bool
* TRUE on success, FALSE on fail. * TRUE on success, FALSE on fail.
@ -341,6 +333,30 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass {
} }
} }
/**
* Asserts that the given datastreams do not exist on the object.
*
* @param AbstractObject $object
* The object to check.
* @param array $datastreams
* An array of datastreams to confirm not present.
*/
public function assertNoDatastreams($object, array $datastreams) {
if (!is_object($object)) {
$this->addResult(FALSE, "Failed. Object passed in is invalid.", 'Islandora');
return;
}
$found_datastreams = array_intersect_key(array_flip($datastreams), $object->repository->api->a->listDatastreams($object->id));
if (!empty($found_datastreams)) {
$this->addResult(FALSE, "Found unwanted datastream(s)" . implode(', ', array_flip($found_datastreams)) . " in object {$object->id}.");
return FALSE;
}
$this->addResult(TRUE, "Unwanted datastream(s) not found in object {$object->id}");
return TRUE;
}
/** /**
* Attempts to validate an array of datastreams, generally via binary checks. * Attempts to validate an array of datastreams, generally via binary checks.
* *

Loading…
Cancel
Save