From fc357e6f7df95c0a0dc2d85d0d68bc06fb352a88 Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 29 May 2014 12:32:12 +0000 Subject: [PATCH] last bit of bugfixes and cleanup --- includes/derivatives.inc | 36 +++++++++++--------- tests/includes/datastream_validators.inc | 16 ++++----- tests/includes/utilities.inc | 42 ++++++++++++++++-------- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/includes/derivatives.inc b/includes/derivatives.inc index 47ec4fad..8a36512e 100644 --- a/includes/derivatives.inc +++ b/includes/derivatives.inc @@ -21,25 +21,29 @@ function islandora_run_derivatives(AbstractObject $object, $dsid) { islandora_derivative_logging($logging_results); } else { - batch_set( - // Title won't show for batch in a batch. + $operations = islandora_do_batch_derivatives( + $object, 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
Time elapsed: @elapsed
- 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, - ) - ), + '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
Time elapsed: @elapsed
+ 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', + ) + ); + } } } diff --git a/tests/includes/datastream_validators.inc b/tests/includes/datastream_validators.inc index 49c090e5..4768e989 100644 --- a/tests/includes/datastream_validators.inc +++ b/tests/includes/datastream_validators.inc @@ -48,7 +48,7 @@ function islandora_hex2int($hex) { * Abstraction for datastream validators. * * 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 * using the naming convention assertThing(); each of these functions should * 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 { /** - * The IslandoraFedoraObject containing the datastream to test. + * The Fedora object containing the datastream to test. * - * @var IslandoraFedoraObject + * @var IslandoraFedoraObject|FedoraObject */ public $object; @@ -97,14 +97,14 @@ abstract class DatastreamValidator extends IslandoraTestUtilityClass { /** * Constructs a DatastreamValidator. * - * @param IslandoraFedoraObject $object + * @param IslandoraFedoraObject|FedoraObject $object * The object to grab the datastream from. * @param string $datastream * The DSID of the datastream itself. * @param array $params * 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->datastream = $datastream; $this->params = $params; @@ -343,7 +343,7 @@ class TextDatastreamValidator extends DatastreamValidator { /** * 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) { 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. * - * @param IslandoraFedoraObject $object + * @param IslandoraFedoraObject|FedoraObject $object * The object to grab the datastream from. * @param string $datastream * The DSID of the datastream itself. * @param array $params * 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); $this->datastreamContent = bin2hex($this->datastreamContent); } diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index e0672fd8..e0682397 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -261,17 +261,9 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { public function __construct($configuration, array $params = array()) { $this->configuration = $configuration; $this->params = $params; - // If we have DB access, we want to use the Islandora Tuque wrappers. - if ($params['db_access']) { - $connection = islandora_get_tuque_connection(); - $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()); - } + $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. * * @param AbstractObject $object - * The PID of the object + * The object to check. * @param array $datastreams - * An array of strings containing datastream names + * An array of strings containing datastream names. * * @return bool * 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. *