Browse Source

fixes, better deletion function, better handling of deletion

pull/448/head
qadan 11 years ago
parent
commit
e4b054d236
  1. 71
      tests/islandora_web_test_case.inc

71
tests/islandora_web_test_case.inc

@ -138,7 +138,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
} }
else { else {
parent::drupalLogin($account); parent::drupalLogin($account);
$this->users[] = $account; $this->users[] = $account->name;
} }
} }
@ -190,20 +190,17 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
$this->fail("Failed. Object passed in is invalid.", 'Islandora'); $this->fail("Failed. Object passed in is invalid.", 'Islandora');
} }
else { else {
$fails = 0; $fails = FALSE;
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}.", 'Islandora'); $this->pass("Loaded datastream {$datastream} from PID {$object->id}.", 'Islandora');
} }
else { else {
$this->fail("Failed to load datastream {$datastream} from PID {$object->id}.", 'Islandora'); $this->fail("Failed to load datastream {$datastream} from PID {$object->id}.", 'Islandora');
$fails++; $fails = TRUE;
} }
} }
if ($fails) { return $fails;
return FALSE;
}
return TRUE;
} }
} }
@ -270,12 +267,23 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
/** /**
* Deletes an object using the PID. This does the deletion using the UI. * Deletes an object using the PID. This does the deletion using the UI.
* *
* Deprecated: please use IslandoraWebTestCase::deleteTestObject() instead, as
* it doesn't require a label, is safer, and is also not generally ridiculous.
*
* @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 * @param string $button
* The label of the first 'Delete' button * The label of the first 'Delete' button
*/ */
public function deleteObject($pid, $button = NULL) { public function deleteObject($pid, $button = NULL) {
// Hey, good for you coming down to check this out.
$message = islandora_deprecated('7.x-1.3', 'Use the "IslandoraWebTestCase::deleteTestObject()" function.');
$this->assert('debug', $message, "Debug", array(
'file' => "islandora_web_test_case.inc",
'function' => "IslandoraWebTestCase->deleteObject()",
'line' => '278',
));
$path = 'islandora/object/' . $pid . '/manage/properties'; $path = 'islandora/object/' . $pid . '/manage/properties';
$edit = array(); $edit = array();
if (isset($button)) { if (isset($button)) {
@ -291,6 +299,31 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
$this->assertResponse(404, "Object $pid successfully deleted."); $this->assertResponse(404, "Object $pid successfully deleted.");
} }
/**
* Deletes an object using the PID. This does the deletion using the UI.
*
* @param string $pid
* The PID of the object.
* @param bool $safety
* If TRUE, this will only delete objects owned by users in $this->users.
*
* @return bool
* TRUE on success, FALSE on failure.
*/
public function deleteTestObject($pid, $safety = TRUE) {
$object = islandora_object_load($pid);
if (!$safety || in_array($object->owner, $this->users)) {
$this->drupalPost('islandora/object/' . $pid . '/delete', array(), 'Delete');
$this->drupalGet('islandora/object/' . $pid);
$this->assertResponse(404, "Successfully deleted object $pid", 'Islandora');
return TRUE;
}
else {
$this->fail("Cannot delete object {$pid}; it is owned by non-test user {$object->owner}, and this function was called with the safety on.");
}
}
/** /**
* Constructs and ingests a Fedora object and datastream(s) via tuque. * Constructs and ingests a Fedora object and datastream(s) via tuque.
* *
@ -302,7 +335,9 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* 'label' - The object label; randomized if not set. * 'label' - The object label; randomized if not set.
* 'pid' - 'namespace:pid', or just 'namespace' to generate the suffix. * 'pid' - 'namespace:pid', or just 'namespace' to generate the suffix.
* 'models' - An array that can contain multiple content model PIDs. * 'models' - An array that can contain multiple content model PIDs.
* 'owner' - The object's owner. * 'owner' - The object's owner. Defaults to the currently logged-in user,
* if available. It is recommended to set this to a value that can be found
* in $this->users; otherwise, this object will have to be manually deleted.
* 'parent' - The PID of the parent collection. * 'parent' - The PID of the parent collection.
* @param array $datastreams * @param array $datastreams
* An array containing zero or more datastream arrays that use the keys: * An array containing zero or more datastream arrays that use the keys:
@ -335,6 +370,9 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
if (isset($properties['owner'])) { if (isset($properties['owner'])) {
$object->owner = $properties['owner']; $object->owner = $properties['owner'];
} }
elseif (is_object($this->loggedInUser)) {
$object->owner = $this->loggedInUser->name;
}
if (isset($properties['models']) && is_array($properties['models'])) { if (isset($properties['models']) && is_array($properties['models'])) {
foreach ($properties['models'] as $model) { foreach ($properties['models'] as $model) {
@ -389,33 +427,30 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
/** /**
* Deletes all objects created by the given user. * Deletes all objects created by the given user.
* *
* @param object $user * @param object $username
* The user whose objects we'd like to remove. * The user whose objects we'd like to remove.
* *
* @return bool * @return bool
* TRUE on success, FALSE on failure. * TRUE on success, FALSE on failure.
*/ */
public function deleteUserCreatedObjects($user) { public function deleteUserCreatedObjects($username) {
if (is_object($user) && isset($user->name)) {
$query = <<<QUERY $query = <<<QUERY
SELECT ?object FROM <#ri> WHERE SELECT ?object FROM <#ri> WHERE
{ {
?object <fedora-model:ownerId> "$user->name" ?object <fedora-model:ownerId> "$username"
} }
QUERY; QUERY;
$objects = $this->admin->repository->ri->sparqlQuery($query); $objects = $this->admin->repository->ri->sparqlQuery($query);
$fail = FALSE;
foreach ($objects as $object) { foreach ($objects as $object) {
$loaded_object = islandora_object_load($object['object']['value']); $loaded_object = islandora_object_load($object['object']['value']);
islandora_delete_object($loaded_object); islandora_delete_object($loaded_object);
$this->assertFalse(islandora_object_load($object['object']['value']), "Object {$object['object']['value']} successfully removed from repository.", 'Islandora'); if ($this->assertFalse(islandora_object_load($object['object']['value']), "Object {$object['object']['value']} successfully removed from repository.", 'Islandora')) {
$fail = TRUE;
} }
return TRUE;
}
else {
$this->fail("Invalid user passed in for object deletion.", "Islandora");
return FAIL;
} }
return $fail;
} }
} }

Loading…
Cancel
Save