MorganDawe
12 years ago
13 changed files with 679 additions and 128 deletions
@ -0,0 +1,127 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* @file |
||||||
|
* The form displayed that shows the datastream version history. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Function that returns markup for the datastream versions page. |
||||||
|
*/ |
||||||
|
function islandora_datastream_version_table($datastream) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/datastream'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
|
||||||
|
drupal_set_title(t("@dsid Previous Versions", array('@dsid' => $datastream->id))); |
||||||
|
|
||||||
|
$header = array(); |
||||||
|
$header[] = array('data' => t('Created Date')); |
||||||
|
$header[] = array('data' => t('Size')); |
||||||
|
$header[] = array('data' => t('Label')); |
||||||
|
$header[] = array('data' => t('Mime type')); |
||||||
|
$header[] = array('data' => t('Operations')); |
||||||
|
$rows = array(); |
||||||
|
|
||||||
|
foreach ($datastream as $version => $datastream_version) { |
||||||
|
$row = array(); |
||||||
|
$row[] = array( |
||||||
|
'class' => 'datastream-date', |
||||||
|
'data' => theme('islandora_datastream_view_link', array( |
||||||
|
'datastream' => $datastream, |
||||||
|
'label' => $datastream_version->createdDate->format(DATE_RFC850), |
||||||
|
'version' => $version, |
||||||
|
)), |
||||||
|
); |
||||||
|
$row[] = array( |
||||||
|
'class' => 'datastream-size', |
||||||
|
'data' => islandora_datastream_get_human_readable_size($datastream_version), |
||||||
|
); |
||||||
|
$row[] = array( |
||||||
|
'class' => 'datastream-label', |
||||||
|
'data' => $datastream_version->label, |
||||||
|
); |
||||||
|
$row[] = array( |
||||||
|
'class' => 'datastream-mime', |
||||||
|
'data' => $datastream_version->mimeType, |
||||||
|
); |
||||||
|
$row[] = array( |
||||||
|
'class' => 'datastream-delete', |
||||||
|
'data' => theme('islandora_datastream_delete_link', array( |
||||||
|
'datastream' => $datastream, |
||||||
|
'version' => $version, |
||||||
|
)), |
||||||
|
); |
||||||
|
$rows[] = $row; |
||||||
|
} |
||||||
|
|
||||||
|
return theme('table', array('header' => $header, 'rows' => $rows)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The admin delete datastream form. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param AbstractDatastream $datastream |
||||||
|
* The datastream to be deleted. |
||||||
|
* @param string $version |
||||||
|
* The version number of the datastream we are trying to delete. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The drupal form definition. |
||||||
|
*/ |
||||||
|
function islandora_delete_datastream_version_form(array $form, array &$form_state, AbstractDatastream $datastream, $version) { |
||||||
|
if (!isset($datastream[$version]) || count($datastream) < 2) { |
||||||
|
return drupal_not_found(); |
||||||
|
} |
||||||
|
|
||||||
|
$form_state['datastream'] = $datastream; |
||||||
|
$form_state['version'] = $version; |
||||||
|
return confirm_form($form, |
||||||
|
t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), |
||||||
|
"islandora/object/{$datastream->parent->id}", |
||||||
|
t('This action cannot be undone.'), |
||||||
|
t('Delete'), |
||||||
|
t('Cancel') |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Submit handler for the delete datastream form. |
||||||
|
* |
||||||
|
* Purges/Delete's the given AbstractDatastream if possible. |
||||||
|
* |
||||||
|
* The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to |
||||||
|
* whether the given FedoraDatastream |
||||||
|
* should be: blocked from purging; state set to 'Deleted'; or purged. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_delete_datastream_version_form_submit(array $form, array &$form_state) { |
||||||
|
$datastream = $form_state['datastream']; |
||||||
|
$version = $form_state['version']; |
||||||
|
|
||||||
|
$datastream_id = $datastream->id; |
||||||
|
$object = $datastream->parent; |
||||||
|
|
||||||
|
try { |
||||||
|
unset($datastream[$version]); |
||||||
|
} |
||||||
|
catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error deleting version %v of %s datastream from object %o %e', array( |
||||||
|
'%v' => $version, |
||||||
|
'%s' => $datastream_id, |
||||||
|
'%o' => $object->label, |
||||||
|
'%e' => $e->getMessage())), 'error'); |
||||||
|
} |
||||||
|
|
||||||
|
drupal_set_message(t('%d datastream version successfully deleted from Islandora object %o', array( |
||||||
|
'%d' => $datastream_id, |
||||||
|
'%o' => $object->label))); |
||||||
|
|
||||||
|
$form_state['redirect'] = "islandora/object/{$object->id}/datastream/{$datastream->id}/version"; |
||||||
|
} |
@ -0,0 +1,198 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* Tests that datastream versions code works as intended |
||||||
|
*/ |
||||||
|
|
||||||
|
class IslandoraDatastreamVersionTestCase extends IslandoraWebTestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets info to display to describe this test. |
||||||
|
* |
||||||
|
* @see IslandoraWebTestCase::getInfo() |
||||||
|
*/ |
||||||
|
public static function getInfo() { |
||||||
|
return array( |
||||||
|
'name' => 'Islandora Datastream Versions', |
||||||
|
'description' => 'Tests the functionality related to datastream versions in Islandora.', |
||||||
|
'group' => 'Islandora', |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create an object with many datastram versions. |
||||||
|
* |
||||||
|
* @see IslandoraWebTestCase::setUp() |
||||||
|
*/ |
||||||
|
public function setUp() { |
||||||
|
parent::setUp(); |
||||||
|
|
||||||
|
$this->pid = $this->randomName() . ":" . $this->randomName(); |
||||||
|
$tuque = islandora_get_tuque_connection(); |
||||||
|
$object = $tuque->repository->constructObject($this->pid); |
||||||
|
$object = $tuque->repository->ingestObject($object); |
||||||
|
$this->dsid = $this->randomName(); |
||||||
|
$ds = $object->constructDatastream($this->dsid); |
||||||
|
$ds->label = 'Test'; |
||||||
|
$ds->content = 'test'; |
||||||
|
$object->ingestDatastream($ds); |
||||||
|
|
||||||
|
// Create three versions. |
||||||
|
$ds->mimetype = 'application/pdf'; |
||||||
|
$ds->label = 'jaaaaa maaaan'; |
||||||
|
$ds->content = 'Tests... are the bests.'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Free any objects/resources created for this test. |
||||||
|
* |
||||||
|
* @see IslandoraWebTestCase::tearDown() |
||||||
|
*/ |
||||||
|
public function tearDown() { |
||||||
|
$tuque = islandora_get_tuque_connection(); |
||||||
|
$tuque->repository->purgeObject($this->pid); |
||||||
|
|
||||||
|
parent::tearDown(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check if the user can see datastream versions in the datastream table. |
||||||
|
*/ |
||||||
|
public function testSeeDatastreamVersions() { |
||||||
|
$user = $this->drupalCreateUser(array( |
||||||
|
'view fedora repository objects', |
||||||
|
'ingest fedora objects', |
||||||
|
'view old datastream versions', |
||||||
|
'add fedora datastreams', |
||||||
|
)); |
||||||
|
$this->drupalLogin($user); |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/manage/datastreams"); |
||||||
|
$this->assertLink($this->dsid); |
||||||
|
$this->assertLink("4"); |
||||||
|
$encoded_pid = urlencode($this->pid); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check that users without permission cannot see datastream versions. |
||||||
|
*/ |
||||||
|
public function testNotSeeDatastreamVersions() { |
||||||
|
$user = $this->drupalCreateUser(array( |
||||||
|
'view fedora repository objects', |
||||||
|
'ingest fedora objects', |
||||||
|
'add fedora datastreams', |
||||||
|
)); |
||||||
|
$this->drupalLogin($user); |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/manage/datastreams"); |
||||||
|
$this->assertLink($this->dsid); |
||||||
|
$this->assertNoLink("4"); |
||||||
|
$encoded_pid = urlencode($this->pid); |
||||||
|
$this->assertNoLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check that users without permission cannot see datastream version pages. |
||||||
|
*/ |
||||||
|
public function testDatastreamVersionPermissions() { |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version"); |
||||||
|
$this->assertResponse(403); |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/0/view"); |
||||||
|
$this->assertResponse(403); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check that the proper infomration is displayed on the ds version page. |
||||||
|
*/ |
||||||
|
public function testDatastreamVersionPage() { |
||||||
|
$user = $this->drupalCreateUser(array( |
||||||
|
'view old datastream versions', |
||||||
|
)); |
||||||
|
$this->drupalLogin($user); |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version"); |
||||||
|
$this->assertNoLink("Delete"); |
||||||
|
$this->assertText("text/xml"); |
||||||
|
$this->assertText("application/pdf"); |
||||||
|
$this->assertText("jaaaaa maaaan"); |
||||||
|
$this->assertText("Test"); |
||||||
|
|
||||||
|
$encoded_pid = urlencode($this->pid); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/0/view"); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/1/view"); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/2/view"); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/3/view"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Make sure the correct content is displayed for each datastream version. |
||||||
|
*/ |
||||||
|
public function testDatastreamVersionContent() { |
||||||
|
$user = $this->drupalCreateUser(array( |
||||||
|
'view old datastream versions', |
||||||
|
)); |
||||||
|
$this->drupalLogin($user); |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/3/view"); |
||||||
|
$content = $this->drupalGetContent(); |
||||||
|
if ($content != 'test') { |
||||||
|
$this->fail("Incorrect datastream content"); |
||||||
|
} |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/2/view"); |
||||||
|
$content = $this->drupalGetContent(); |
||||||
|
if ($content != 'test') { |
||||||
|
$this->fail("Incorrect datastream content"); |
||||||
|
} |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/1/view"); |
||||||
|
$content = $this->drupalGetContent(); |
||||||
|
if ($content != 'test') { |
||||||
|
$this->fail("Incorrect datastream content"); |
||||||
|
} |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/0/view"); |
||||||
|
$content = $this->drupalGetContent(); |
||||||
|
if ($content != 'Tests... are the bests.') { |
||||||
|
$this->fail("Incorrect datastream content"); |
||||||
|
} |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/5/view"); |
||||||
|
$this->assertResponse(404); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Make sure you can delete datastream versions. |
||||||
|
*/ |
||||||
|
public function testDatastreamVersionDelete() { |
||||||
|
$user = $this->drupalCreateUser(array( |
||||||
|
'view old datastream versions', |
||||||
|
'delete fedora objects and datastreams', |
||||||
|
)); |
||||||
|
$this->drupalLogin($user); |
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version"); |
||||||
|
$this->assertLink("delete"); |
||||||
|
$this->assertText('text/xml'); |
||||||
|
|
||||||
|
$encoded_pid = urlencode($this->pid); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/0/delete"); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/1/delete"); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/2/delete"); |
||||||
|
$this->assertLinkByHref("islandora/object/$encoded_pid/datastream/{$this->dsid}/version/3/delete"); |
||||||
|
|
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/3/delete"); |
||||||
|
$this->drupalPost(NULL, array(), t('Delete')); |
||||||
|
$this->assertNoText('text/xml'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Make sure you can't delete versions that don't exist/have only 1 version. |
||||||
|
*/ |
||||||
|
public function testDatastreamVersionDeleteEdgeCase() { |
||||||
|
$user = $this->drupalCreateUser(array( |
||||||
|
'view old datastream versions', |
||||||
|
'delete fedora objects and datastreams', |
||||||
|
)); |
||||||
|
$this->drupalLogin($user); |
||||||
|
|
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/{$this->dsid}/version/6/delete"); |
||||||
|
$this->assertResponse(404); |
||||||
|
|
||||||
|
$this->drupalGet("islandora/object/{$this->pid}/datastream/DC/version/0/delete"); |
||||||
|
$this->assertResponse(404); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue