Browse Source

Merge pull request #375 from jordandukart/7.x-qa-dan

Updated functionality for binary tests and deletion of objects.
pull/374/merge
Jonathan Green 11 years ago
parent
commit
17f075d978
  1. 62
      tests/islandora_web_test_case.inc

62
tests/islandora_web_test_case.inc

@ -157,27 +157,27 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
} }
/** /**
* Asserts that the given datastreams exist 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 PID of the object
* @param array $datastreams * @param array $datastreams
* An array of strings containing datastream names * An array of strings containing datastream names
*/ */
public function assertDatastreams($object, array $datastreams) { public function assertDatastreams($object, array $datastreams) {
if (!is_object($object)) { if (!is_object($object)) {
$this->fail("Failed. Object passed in is invalid."); $this->fail("Failed. Object passed in is invalid.", 'Islandora');
return;
} }
foreach ($datastreams as $datastream) { foreach ($datastreams as $datastream) {
if (isset($object[$datastream])) { if (isset($object[$datastream])) {
$this->pass("Loaded datastream {$datastream} from PID {$object->id}"); $this->pass("Loaded datastream {$datastream} from PID {$object->id}.", 'Islandora');
} }
else { else {
$this->fail("Failed to load datastream {$datastream} from PID {$object->id}"); $this->fail("Failed to load datastream {$datastream} from PID {$object->id}.", 'Islandora');
} }
} }
} }
/** /**
@ -199,7 +199,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
} }
} }
} }
$this->fail("Failed to parse path : $path."); $this->fail("Failed to parse path: $path.");
return FALSE; return FALSE;
} }
@ -208,31 +208,49 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* *
* @param string $pid * @param string $pid
* The PID of the collection to be deleted * The PID of the collection to be deleted
* @param string $button
* The label of the first 'Delete' button
*/ */
public function deleteObject($pid) { public function deleteObject($pid, $button = 'Delete') {
$current_user = $this->loggedInUser;
$user = $this->drupalCreateUser(array(
'manage object properties',
'delete fedora objects and datastreams',
'view fedora repository objects',
));
$this->drupalLogin($user);
$path = 'islandora/object/' . $pid . '/manage/properties'; $path = 'islandora/object/' . $pid . '/manage/properties';
$edit = array(); $edit = array();
$this->drupalPost($path, $edit, t('Delete')); $this->drupalPost($path, $edit, $button);
$this->drupalPost($this->url, $edit, t('Delete')); $this->drupalPost($this->url, $edit, t('Delete'));
$object = islandora_object_load($pid); $object = islandora_object_load($pid);
$this->drupalGet("islandora/object/$pid"); $this->drupalGet("islandora/object/$pid");
$this->assertResponse(404, "Object $pid successfully deleted."); $this->assertResponse(404, "Object $pid successfully deleted.");
}
/**
* Reverses a hex string and converts it to a little-endian-formatted integer.
*
* This is useful for running checks on values that appear in the binary
* of a datastream. Returns FALSE if the hex value contains non-hex characters
* or if the string would not return a 16- or 32-bit formatted big-endian
* signed integer.
*
* @param string $hex
* The hex value being converted.
*
* @return bool|int
* FALSE or the integer value that is converted.
*/
public function convertHexToInt($hex) {
if ($current_user) { // A couple of quick string checks.
$this->drupalLogin($current_user); if (!ctype_xdigit($hex)) {
$this->fail('String passed to convertHexToInt() contains non-hexidecimal characters.', 'PHP');
return FALSE;
} }
else { if (!strlen($hex) === 4 || !strlen($hex) === 8) {
$this->drupalLogout(); $this->fail('String passed to convertHexToInt() cannot create a 16- or 32-bit little-endian signed integer', 'PHP');
return FALSE;
} }
// The actual conversion.
$reverse_hex = implode('', array_reverse(str_split($hex, 2)));
$int = hexdec($reverse_hex);
return $int;
} }
} }

Loading…
Cancel
Save