Browse Source

Resolve failing tests after merge.

pull/105/head
Alexander O'Neill 14 years ago
parent
commit
8f318129f0
  1. 2
      fedora_repository.module
  2. 181
      tests/fedora_repository.test

2
fedora_repository.module

@ -314,7 +314,7 @@ function add_stream_form_submit($form, &$form_state) {
$dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.;
$file_basename = basename($file); $file_basename = basename($file);
$file_directory = dirname($file); $file_directory = dirname($file);
$streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); $streamUrl = $base_url . '/' . $file_directory . '/' . drupal_urlencode($file_basename);
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
* need a better way to get mimetypes * need a better way to get mimetypes

181
tests/fedora_repository.test

@ -8,9 +8,32 @@
class FedoraRepositoryTestCase extends DrupalWebTestCase { class FedoraRepositoryTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Fedora Repository',
'description' => t('The Fedora repository content models.'),
'group' => t('fedora repository'),
);
}
function setUp() {
parent::setUp('tabs', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// Create and login user.
$repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams',
'edit fedora meta data',
'edit tags datastream',
'ingest new fedora objects',
'purge objects and datastreams',
'view fedora collection',
'view detailed list of content'));
public function testDatastreams() { $this->repository_user = $repository_user;
$this->drupalLogin($repository_user);
}
public function testDatastreams() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$pid_list = array(); $pid_list = array();
@ -32,12 +55,14 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
$rpath = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf'); $rpath = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf');
$add_stream_form['files[add-stream-file-location]'] = $rpath; $add_stream_form['files[add-stream-file-location]'] = $rpath;
$add_stream_form['stream_id'] = 'OBJ'; $add_stream_form['stream_id'] = 'OBJ';
$this->outputScreenContents();
$this->drupalPost('fedora/repository/' . $pdf_item->pid, $add_stream_form, 'Add Datastream'); $this->drupalPost('fedora/repository/' . $pdf_item->pid, $add_stream_form, 'Add Datastream');
$this->outputScreenContents();
// Test replace datastream form // Test replace datastream form
$this->assertText('The datastream has been uploaded', "Add initial datastream.", 'fedora datastreams'); $this->assertText('The datastream has been uploaded', "Add initial datastream.", 'fedora datastreams');
$this->drupalGet('fedora/repository/'.$pdf_item->pid); $this->drupalGet('fedora/repository/'.$pdf_item->pid);
$this->assertText($add_stream_form['stream_label'], 'Datastream appears in DS list.', 'fedora datastreams'); $this->assertText($add_stream_form['stream_label'], 'Datastream appears in DS list.', 'fedora datastreams');
$replace_stream_edit = array(); $replace_stream_edit = array();
$replace_stream_rpath = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/jabberwocky.pdf'); $replace_stream_rpath = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/jabberwocky.pdf');
$replace_stream_edit['files[file]'] = $replace_stream_rpath; $replace_stream_edit['files[file]'] = $replace_stream_rpath;
@ -47,156 +72,6 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
$this->outputScreenContents(); $this->outputScreenContents();
} }
/**
* Add an item based on a content model. Initially we will assume that the repository
* will be populated with the default content models and collections that are
* created from the admin settings -> Install Demos page.
*
*/
public function testIngest() {
// Check that the 'Strict PDF' content model exists in the repository.
//$pdf_cm = new Fedora_Item('islandora:strict_pdf');
$pid_list = array();
// Create a collection for ingesting PDF content model objects.
//$this->drupalGet('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection');
$ingest_form = array();
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM';
$this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next');
// Add a sample PDF object via the web ingest form.
// Required fields are file location, dc:title and dc:description
$ingest_form_step_2 = array();
$ingest_form_step_2['dc:title'] = $this->randomName(32);
$ingest_form_step_2['dc:description'] = $this->randomName(256);
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf');
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest');
$this->assertText('mimetype (application/pdf) is not associated with this Content Model', 'PDF mime type not accepted in collection content model.', 'message');
$this->outputScreenContents('Initial ingest form submit step 2', 'fedora_repository');
// Now try ingesting a proper collection policy.
$ingest_form = array();
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM';
$this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next');
// Required fields are file location, dc:title and dc:description
$ingest_form_step_2 = array();
$ingest_title = $this->randomName(32);
$ingest_form_step_2['dc:title'] = $ingest_title;
$ingest_form_step_2['dc:description'] = $this->randomName(256);
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PDF-COLLECTION POLICY.xml');
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest');
//$this->outputScreenContents('Initial ingest form submit step 2 - PDF collection', 'fedora_repository');
$this->assertPattern('/Item .* created successfully./', "Verified item created.");
$pid = $this->getIngestedPid();
$this->drupalGet("fedora/repository/$pid");
$this->assertLink('Home');
$this->assertLink('Digital Repository');
$this->assertLink($ingest_title);
$pid_list[] = $pid;
$this->pass('Now attempting to ingest a PDF into the new collection.');
// Now try ingesting a PDF
$ingest_form = array();
$ingest_form['models'] = 'islandora:strict_pdf/ISLANDORACM';
$this->drupalPost("fedora/ingestObject/$pid/", $ingest_form, 'Next');
// Required fields are file location, dc:title and dc:description
$ingest_form_step_2 = array();
$ingest_form_step_2['dc:title'] = "Lorem Ipsum";
$ingest_form_step_2['dc:description'] = $this->randomName(256);
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf');
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest');
$pid = $this->getIngestedPid();
$pid_list[] = $pid;
if (!empty($pid)) {
$this->pass("Successfully ingested PDF object $pid.");
}
$this->cleanUpRepository($pid_list);
}
private function cleanUpRepository($pid_list = array()) {
$this->pass("This is the PID list to purge: ". implode(", ", $pid_list) );
foreach ($pid_list as $pid) {
$this->drupalPost("fedora/repository/purgeObject/$pid", array(), 'Purge');
$this->drupalPost(NULL, array(), 'Delete');
}
}
private function getIngestedPid() {
$subject = $this->drupalGetContent();
$pattern = '/">(.*)<\/a> created successfully./';
$matches = array();
$res = preg_match($pattern, $subject, $matches);
return $matches[1];
}
private function outputScreenContents($description = '', $basename = '') {
// This is a hack to get a directory that won't be cleaned up by SimpleTest.
$file_dir = file_directory_path() . '../simpletest_output_pages';
if (!is_dir($file_dir)) {
mkdir($file_dir, 0777, TRUE);
}
$output_path = "$file_dir/$basename.". $this->randomName(10) . '.html';
$rv = file_put_contents($output_path, $this->drupalGetContent());
$this->pass("$description: Contents of result page are ". l('here', $output_path));
}
protected function drupalCreateFedoraUser($permissions = array('access comments', 'access content', 'post comments', 'post comments without approval')) {
// Create a role with the given permission set.
if (!($rid = $this->drupalCreateRole($permissions))) {
return FALSE;
}
// Create a user assigned to that role.
$edit = array();
$edit['name'] = 'simpletestuser';
$edit['mail'] = $edit['name'] . '@example.com';
$edit['roles'] = array($rid => $rid);
$edit['pass'] = 'simpletestpass';
$edit['status'] = 1;
$account = user_save('', $edit);
$this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login'));
if (empty($account->uid)) {
return FALSE;
}
// Add the raw password so that we can log in as this user.
$account->pass_raw = $edit['pass'];
return $account;
}
public static function getInfo() {
return array(
'name' => 'Fedora Repository',
'description' => t('The Fedora repository content models.'),
'group' => t('fedora repository'),
);
}
function setUp() {
parent::setUp('fedora_repository');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// Create and login user.
$repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams',
'edit fedora meta data',
'edit tags datastream',
'ingest new fedora objects',
'purge objects and datastreams',
'view fedora collection'));
$this->repository_user = $repository_user;
$this->drupalLogin($repository_user);
}
/** /**
* Add an item based on a content model. Initially we will assume that the repository * Add an item based on a content model. Initially we will assume that the repository
* will be populated with the default content models and collections that are * will be populated with the default content models and collections that are
@ -308,7 +183,7 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
return $matches[1]; return $matches[1];
} }
private function outputScreenContents($description, $basename) { private function outputScreenContents($description = "Screen contents", $basename = 'Fedora Repository') {
// This is a hack to get a directory that won't be cleaned up by SimpleTest. // This is a hack to get a directory that won't be cleaned up by SimpleTest.
$file_dir = file_directory_path() . '../simpletest_output_pages'; $file_dir = file_directory_path() . '../simpletest_output_pages';
if (!is_dir($file_dir)) { if (!is_dir($file_dir)) {

Loading…
Cancel
Save