Browse Source

Move around some logic.

"Lazy-run" validators.
pull/463/head^2
Adam Vessey 11 years ago
parent
commit
cb8c41936e
  1. 30
      tests/datastream_validators.inc

30
tests/datastream_validators.inc

@ -192,7 +192,6 @@ abstract class DatastreamValidator {
$this->params = $params; $this->params = $params;
if ($object[$datastream]) { if ($object[$datastream]) {
$this->datastreamContent = $object[$datastream]->content; $this->datastreamContent = $object[$datastream]->content;
$this->runValidators();
} }
else { else {
drupal_set_message(t("Error grabbing content from datastream %datastream in object %id", 'error'), array( drupal_set_message(t("Error grabbing content from datastream %datastream in object %id", 'error'), array(
@ -226,6 +225,9 @@ abstract class DatastreamValidator {
* The results. * The results.
*/ */
public function getResults() { public function getResults() {
if (empty($this->results)) {
$this->runValidators();
}
return $this->results; return $this->results;
} }
@ -415,19 +417,24 @@ class PDFDatastreamValidator extends DatastreamValidator {
* integer representing the number of times it should appear in the datastream. * integer representing the number of times it should appear in the datastream.
*/ */
class TextDatastreamValidator extends DatastreamValidator { 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()) {
if (count($params) < 2) {
throw new InvalidArgumentException('$params must contain at least two values to instantiate a TextDatastreamValidator.');
}
parent::__construct($object, $datastream, $params);
}
/** /**
* Asserts that the string given appears the correct number of times. * Asserts that the string given appears the correct number of times.
*/ */
protected function assertTextStringCount() { protected function assertTextStringCount() {
if (!isset($this->params[1])) {
$this->addResult(FALSE, "TextDatastreamValidator cannot be instantiated without two keys in the 'params' variable.");
return;
}
$string_count = self::getTextStringCount(); $string_count = self::getTextStringCount();
$expected = $this->params[1]; list($string, $expected) = $this->params;
$assertion = $string_count === $expected; $assertion = $string_count === $expected;
$this->addResult($assertion, "{$this->datastream} datastream contains the word(s) '{$this->params[0]}' repeated {$string_count} time(s) (expected: {$expected})."); $this->addResult($assertion, "{$this->datastream} datastream contains the word(s) '{$string}' repeated {$string_count} time(s) (expected: {$expected}).");
} }
/** /**
@ -463,12 +470,9 @@ class WAVDatastreamValidator extends DatastreamValidator {
* @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($object, $datastream, array $params = array()) { public function __construct(IslandoraFedoraObject $object, $datastream, array $params = array()) {
$this->object = $object; parent::__construct($object, $datastream, $params);
$this->datastream = $datastream; $this->datastreamContent = bin2hex($this->datastreamContent);
$this->params = $params;
$this->datastreamContent = bin2hex($object[$datastream]->content);
$this->runValidators();
} }
/** /**

Loading…
Cancel
Save