From e498db7988ccbe8430bc8436b4b8f80b9fbfe309 Mon Sep 17 00:00:00 2001 From: Daniel Aitken Date: Wed, 29 May 2013 10:25:51 -0300 Subject: [PATCH 1/3] additional functions for binary tests --- tests/islandora_web_test_case.inc | 53 +++++++++++++++++++------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index a5117695..51ffc7a3 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -128,27 +128,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 * The PID of the object * @param array $datastreams - * An array of strings containing datastream names + * An array of strings containing datastream names */ public function assertDatastreams($object, array $datastreams) { if (!is_object($object)) { - $this->fail("Failed. Object passed in is invalid."); - return; + $this->fail("Failed. Object passed in is invalid.", 'Islandora'); } foreach ($datastreams as $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 { - $this->fail("Failed to load datastream {$datastream} from PID {$object->id}"); + $this->fail("Failed to load datastream {$datastream} from PID {$object->id}.", 'Islandora'); } } + } /** @@ -170,7 +170,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { } } } - $this->fail("Failed to parse path : $path."); + $this->fail("Failed to parse path: $path."); return FALSE; } @@ -181,15 +181,6 @@ class IslandoraWebTestCase extends DrupalWebTestCase { * The PID of the collection to be deleted */ public function deleteObject($pid) { - $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'; $edit = array(); $this->drupalPost($path, $edit, t('Delete')); @@ -198,12 +189,34 @@ class IslandoraWebTestCase extends DrupalWebTestCase { $this->drupalGet("islandora/object/$pid"); $this->assertResponse(404, "Object $pid successfully deleted."); + } - if ($current_user) { - $this->drupalLogin($current_user); + /** + * 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. + */ + public function convertHexToInt($hex) { + + // A couple of quick string checks. + if (!ctype_xdigit($hex)) { + $this->fail('String passed to convertHexToInt() contains non-hexidecimal characters.', 'PHP'); + return FALSE; } - else { - $this->drupalLogout(); + if (!strlen($hex) === 4 || !strlen($hex) === 8) { + $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; } } From fca27751947b087853293fdd1cde78c02122be84 Mon Sep 17 00:00:00 2001 From: daitken Date: Thu, 30 May 2013 11:33:01 -0300 Subject: [PATCH 2/3] fix for deleting objects with different button labels The Book Solution Pack's 'delete' button says 'Delete Book' rather than just 'Delete'; this allows the Book Solution Pack to use its own special label, as well as any other solution packs that might use different labels in the future. --- tests/islandora_web_test_case.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index 51ffc7a3..3ed18ab8 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -179,11 +179,13 @@ class IslandoraWebTestCase extends DrupalWebTestCase { * * @param string $pid * 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') { $path = 'islandora/object/' . $pid . '/manage/properties'; $edit = array(); - $this->drupalPost($path, $edit, t('Delete')); + $this->drupalPost($path, $edit, $button); $this->drupalPost($this->url, $edit, t('Delete')); $object = islandora_object_load($pid); From 9af857bd542d5d8e3f31a7aa297c7423fd83c5d9 Mon Sep 17 00:00:00 2001 From: daitken Date: Thu, 6 Jun 2013 16:28:48 -0300 Subject: [PATCH 3/3] code cleanup --- tests/islandora_web_test_case.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index 3ed18ab8..ef900ab9 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -182,7 +182,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { * @param string $button * The label of the first 'Delete' button */ - public function deleteObject($pid, $button='Delete') { + public function deleteObject($pid, $button = 'Delete') { $path = 'islandora/object/' . $pid . '/manage/properties'; $edit = array(); $this->drupalPost($path, $edit, $button);