Browse Source

better handling of objects

pull/448/head
qadan 11 years ago
parent
commit
50e16d2822
  1. 55
      tests/islandora_web_test_case.inc

55
tests/islandora_web_test_case.inc

@ -7,6 +7,13 @@
class IslandoraWebTestCase extends DrupalWebTestCase { class IslandoraWebTestCase extends DrupalWebTestCase {
/**
* An array of users that may be created over the course of a test.
*
* @var array
*/
protected $users = array();
/** /**
* Sets up the Drupal filter to access this test Drupal instances database. * Sets up the Drupal filter to access this test Drupal instances database.
* *
@ -131,6 +138,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
} }
else { else {
parent::drupalLogin($account); parent::drupalLogin($account);
$this->users[] = $account;
} }
} }
@ -155,6 +163,9 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* @see DrupalWebTestCase::tearDown() * @see DrupalWebTestCase::tearDown()
*/ */
public function tearDown() { public function tearDown() {
foreach ($this->users as $user) {
$this->deleteUserCreatedObjects($user);
}
if ($this->configuration['use_drupal_filter']) { if ($this->configuration['use_drupal_filter']) {
$this->restoreDrupalFilter(); $this->restoreDrupalFilter();
} }
@ -170,20 +181,31 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* 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
*
* @return bool
* TRUE on success, FALSE on fail.
*/ */
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.", 'Islandora'); $this->fail("Failed. Object passed in is invalid.", 'Islandora');
} }
else { else {
$fails = 0;
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++;
} }
} }
if ($fails) {
return FALSE;
}
else {
return TRUE;
}
} }
} }
@ -266,7 +288,6 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
$this->drupalPost($path, $edit, "Permanently remove '{$object->label}' from repository"); $this->drupalPost($path, $edit, "Permanently remove '{$object->label}' from repository");
} }
$this->drupalPost($this->url, $edit, t('Delete')); $this->drupalPost($this->url, $edit, t('Delete'));
$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.");
@ -367,4 +388,36 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
return $object; return $object;
} }
/**
* Deletes all objects created by the given user.
*
* @param object $user
* The user whose objects we'd like to remove.
*
* @return bool
* TRUE on success, FALSE on failure.
*/
public function deleteUserCreatedObjects($user) {
if (is_object($user) && isset($user->name)) {
$query = <<<QUERY
SELECT ?object FROM <#ri> WHERE
{
?object <fedora-model:ownerId> "$user->name"
}
QUERY;
$objects = $this->admin->repository->ri->sparqlQuery($query);
foreach ($objects as $object) {
$loaded_object = islandora_object_load($object['object']['value']);
islandora_delete_object($loaded_object);
$this->assertFalse(islandora_object_load($object['object']['value']), "Object {$object['object']['value']} successfully removed from repository.", 'Islandora');
}
return TRUE;
}
else {
$this->fail("Invalid user passed in for object deletion.", "Islandora");
return FAIL;
}
}
} }

Loading…
Cancel
Save