From 251d8c9c47b236afbb5dbb227eddd0842992b005 Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 23 Apr 2015 16:07:02 -0300 Subject: [PATCH 1/5] a couple new utilities --- tests/includes/utilities.inc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index eefae4cc..f4925d6f 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -359,4 +359,36 @@ QUERY; return ($object instanceof FedoraObject); } + /** + * Asserts that the given PID represents a Fedora object. + * + * @param $pid + * The PID of the object. + * + * @return bool + * TRUE if the object exists in the repository; FALSE otherwise. + */ + public function assertObjectExists($pid) { + $object = islandora_object_load($pid); + $exists = $this->assertFedoraObject($pid); + $this->addResult($exists, "Object $pid exists in the repository."); + return $exists; + } + + /** + * Asserts that the given PID does not represent a Fedora object. + * + * @param $pid + * The PID of the object. + * + * @return bool + * TRUE if the object does not exist in the repository, or FALSE otherwise. + */ + public function assertNoObjectExists($pid) { + $object = islandora_object_load($pid); + $exists = $this->assertFedoraObject($pid); + $this->addResult(!$exists, "Object $pid does not exist in the repository."); + return !$exists; + } + } From e56c73f49190d4c2483f11d5fcbcb658240f4427 Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 23 Apr 2015 16:54:32 -0300 Subject: [PATCH 2/5] boo to me --- tests/includes/utilities.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index f4925d6f..4ea610ad 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -362,7 +362,7 @@ QUERY; /** * Asserts that the given PID represents a Fedora object. * - * @param $pid + * @param string $pid * The PID of the object. * * @return bool @@ -378,7 +378,7 @@ QUERY; /** * Asserts that the given PID does not represent a Fedora object. * - * @param $pid + * @param string $pid * The PID of the object. * * @return bool From 922fe4a4ccd7daa2adb878980169b833c7ab2c29 Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 2 Jul 2015 17:04:36 -0300 Subject: [PATCH 3/5] fixin' the assertions --- tests/includes/utilities.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index 4ea610ad..53a5107e 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -370,7 +370,7 @@ QUERY; */ public function assertObjectExists($pid) { $object = islandora_object_load($pid); - $exists = $this->assertFedoraObject($pid); + $exists = $this->assertFedoraObject($object); $this->addResult($exists, "Object $pid exists in the repository."); return $exists; } @@ -386,7 +386,7 @@ QUERY; */ public function assertNoObjectExists($pid) { $object = islandora_object_load($pid); - $exists = $this->assertFedoraObject($pid); + $exists = $this->assertFedoraObject($object); $this->addResult(!$exists, "Object $pid does not exist in the repository."); return !$exists; } From d982ac19853bc1c6ed068cdff412a6cd1bb09127 Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 2 Jul 2015 17:54:36 -0300 Subject: [PATCH 4/5] better asserting objects --- tests/includes/utilities.inc | 77 ++++++++++++++---------------------- 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index 53a5107e..38a60462 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -112,10 +112,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * TRUE on success, FALSE on fail. */ public function assertDatastreams($object, array $datastreams) { - if (!self::assertFedoraObject($object)) { - $this->addResult(FALSE, "Failed. Object passed in is invalid.", 'Islandora'); - } - else { + if (self::assertFedoraObject($object)) { $missing_datastreams = array_diff_key(array_flip($datastreams), $object->repository->api->a->listDatastreams($object->id)); if (!empty($missing_datastreams)) { @@ -137,8 +134,8 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * An array of datastreams to confirm not present. */ public function assertNoDatastreams($object, array $datastreams) { - if (!self::assertFedoraObject($object)) { - $this->addResult(FALSE, "Failed. Object passed in is invalid.", 'Islandora'); + if (self::assertFedoraObject($object, FALSE)) { + $this->addResult("Failed to check the datastreams on the object; the object could not be loaded."); return; } $found_datastreams = array_intersect_key(array_flip($datastreams), $object->repository->api->a->listDatastreams($object->id)); @@ -169,8 +166,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * for examples. */ public function validateDatastreams($object, array $datastreams) { - - if (!self::assertFedoraObject($object)) { + if (self::assertFedoraObject($object, FALSE)) { $this->addResult(FALSE, "Datastream validation failed; Object passed in is invalid.", 'Islandora'); return; } @@ -347,48 +343,33 @@ QUERY; } /** - * Asserts that an object is a FedoraObject or an IslandoraFedoraObject. - * - * @param object $object - * The object to assess. - * - * @return bool - * TRUE if it is either of those object types, or FALSE otherwise. - */ - public static function assertFedoraObject($object) { - return ($object instanceof FedoraObject); - } - - /** - * Asserts that the given PID represents a Fedora object. + * Asserts a Fedora object from an object or PID, and loads it if possible. * - * @param string $pid - * The PID of the object. + * @param FedoraObject|string $object + * The object to assess, or a string to use as a PID. + * @param bool $exists + * Whether or not the object should exist in the repository, according to + * our assertion. Defaults to TRUE. * - * @return bool - * TRUE if the object exists in the repository; FALSE otherwise. + * @return FedoraObject|bool + * The object in question if it was a FedoraObject or loaded into one, or + * FALSE otherwise. */ - public function assertObjectExists($pid) { - $object = islandora_object_load($pid); - $exists = $this->assertFedoraObject($object); - $this->addResult($exists, "Object $pid exists in the repository."); - return $exists; - } - - /** - * Asserts that the given PID does not represent a Fedora object. - * - * @param string $pid - * The PID of the object. - * - * @return bool - * TRUE if the object does not exist in the repository, or FALSE otherwise. - */ - public function assertNoObjectExists($pid) { - $object = islandora_object_load($pid); - $exists = $this->assertFedoraObject($object); - $this->addResult(!$exists, "Object $pid does not exist in the repository."); - return !$exists; + public static function assertFedoraObject($object, $exists = TRUE) { + if ($object instanceof FedoraObject) { + $this->addResult($exists, "Object loaded from $object->id is a Fedora repository object."); + return $object; + } + elseif (is_string($object)) { + $loaded_object = islandora_object_load($object); + if ($loaded_object instanceof FedoraObject) { + $this->addResult($exists, "Successfully loaded object $object from the Fedora repository."); + return $loaded_object; + } + $this->addResult($exists, "Object identified by $object was not found in the repository."); + return FALSE; + } + $this->addResult($exists, "Object passed in was not found in the repository."); + return FALSE; } - } From a9b40175ed894eb5fe44aa0140414e72533264d7 Mon Sep 17 00:00:00 2001 From: qadan Date: Fri, 3 Jul 2015 09:56:54 -0300 Subject: [PATCH 5/5] just get rid of it --- tests/includes/utilities.inc | 37 +++--------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index 38a60462..a94d0ab9 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -112,7 +112,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * TRUE on success, FALSE on fail. */ public function assertDatastreams($object, array $datastreams) { - if (self::assertFedoraObject($object)) { + if ($object = islandora_object_load($object)) { $missing_datastreams = array_diff_key(array_flip($datastreams), $object->repository->api->a->listDatastreams($object->id)); if (!empty($missing_datastreams)) { @@ -134,7 +134,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * An array of datastreams to confirm not present. */ public function assertNoDatastreams($object, array $datastreams) { - if (self::assertFedoraObject($object, FALSE)) { + if ($object = islandora_object_load($object)) { $this->addResult("Failed to check the datastreams on the object; the object could not be loaded."); return; } @@ -166,7 +166,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * for examples. */ public function validateDatastreams($object, array $datastreams) { - if (self::assertFedoraObject($object, FALSE)) { + if ($object = islandora_object_load($object)) { $this->addResult(FALSE, "Datastream validation failed; Object passed in is invalid.", 'Islandora'); return; } @@ -341,35 +341,4 @@ QUERY; } return $return_value; } - - /** - * Asserts a Fedora object from an object or PID, and loads it if possible. - * - * @param FedoraObject|string $object - * The object to assess, or a string to use as a PID. - * @param bool $exists - * Whether or not the object should exist in the repository, according to - * our assertion. Defaults to TRUE. - * - * @return FedoraObject|bool - * The object in question if it was a FedoraObject or loaded into one, or - * FALSE otherwise. - */ - public static function assertFedoraObject($object, $exists = TRUE) { - if ($object instanceof FedoraObject) { - $this->addResult($exists, "Object loaded from $object->id is a Fedora repository object."); - return $object; - } - elseif (is_string($object)) { - $loaded_object = islandora_object_load($object); - if ($loaded_object instanceof FedoraObject) { - $this->addResult($exists, "Successfully loaded object $object from the Fedora repository."); - return $loaded_object; - } - $this->addResult($exists, "Object identified by $object was not found in the repository."); - return FALSE; - } - $this->addResult($exists, "Object passed in was not found in the repository."); - return FALSE; - } }