Alan Stanley
14 years ago
1 changed files with 190 additions and 145 deletions
@ -1,153 +1,198 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
// $Id$ |
// $Id$ |
||||||
|
|
||||||
/* |
/* |
||||||
* Tests the functions of the Fedora Repository module. |
* Tests the functions of the Fedora Repository module. |
||||||
*/ |
*/ |
||||||
|
|
||||||
class FedoraRepositoryTestCase extends DrupalWebTestCase { |
class FedoraRepositoryTestCase extends DrupalWebTestCase { |
||||||
|
|
||||||
public static function getInfo() { |
public static function getInfo() { |
||||||
return array( |
return array( |
||||||
'name' => 'Fedora Repository', |
'name' => 'Fedora Repository', |
||||||
'description' => t('The Fedora repository content models.'), |
'description' => t('The Fedora repository content models.'), |
||||||
'group' => t('fedora repository'), |
'group' => t('fedora repository'), |
||||||
); |
); |
||||||
} |
} |
||||||
|
|
||||||
function setUp() { |
function setUp() { |
||||||
parent::setUp('fedora_repository'); |
parent::setUp('fedora_repository'); |
||||||
|
|
||||||
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); |
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); |
||||||
|
|
||||||
// Create and login user. |
// Create and login user. |
||||||
$repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams', |
$repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams', |
||||||
'edit fedora meta data', |
'edit fedora meta data', |
||||||
'edit tags datastream', |
'edit tags datastream', |
||||||
'ingest new fedora objects', |
'ingest new fedora objects', |
||||||
'purge objects and datastreams', |
'purge objects and datastreams', |
||||||
'view fedora collection')); |
'view fedora collection')); |
||||||
|
|
||||||
|
$this->repository_user = $repository_user; |
||||||
$this->drupalLogin($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 |
* created from the admin settings -> Install Demos page. |
||||||
* created from the admin settings -> Install Demos page. |
* |
||||||
* |
*/ |
||||||
*/ |
public function testIngest() { |
||||||
public function testIngest() { |
// Check that the 'Strict PDF' content model exists in the repository. |
||||||
// Check that the 'Strict PDF' content model exists in the repository. |
//$pdf_cm = new Fedora_Item('islandora:strict_pdf'); |
||||||
//$pdf_cm = new Fedora_Item('islandora:strict_pdf'); |
|
||||||
|
$pid_list = array(); |
||||||
$pid_list = array(); |
// Create a collection for ingesting PDF content model objects. |
||||||
// Create a collection for ingesting PDF content model objects. |
//$this->drupalGet('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection'); |
||||||
|
$ingest_form = array(); |
||||||
//$this->drupalGet('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection'); |
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM'; |
||||||
$ingest_form = array(); |
|
||||||
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM'; |
$this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next'); |
||||||
|
|
||||||
$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 |
||||||
// Add a sample PDF object via the web ingest form. |
$ingest_form_step_2 = array(); |
||||||
// Required fields are file location, dc:title and dc:description |
$ingest_form_step_2['dc:title'] = $this->randomName(32); |
||||||
$ingest_form_step_2 = array(); |
$ingest_form_step_2['dc:description'] = $this->randomName(256); |
||||||
$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'); |
||||||
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf'); |
$this->assertText('mimetype (application/pdf) is not associated with this Content Model', 'PDF mime type not accepted in collection content model.', 'message'); |
||||||
$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'); |
||||||
|
|
||||||
$this->outputScreenContents('Initial ingest form submit step 2', 'fedora_repository'); |
// Now try ingesting a proper collection policy. |
||||||
|
$ingest_form = array(); |
||||||
// Now try ingesting a proper collection policy. |
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM'; |
||||||
$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 |
||||||
$this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next'); |
$ingest_form_step_2 = array(); |
||||||
// Required fields are file location, dc:title and dc:description |
$ingest_form_step_2['dc:title'] = $this->randomName(32); |
||||||
$ingest_form_step_2 = array(); |
$ingest_form_step_2['dc:description'] = $this->randomName(256); |
||||||
$ingest_form_step_2['dc:title'] = $this->randomName(32); |
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PDF-COLLECTION POLICY.xml'); |
||||||
$ingest_form_step_2['dc:description'] = $this->randomName(256); |
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); |
||||||
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PDF-COLLECTION POLICY.xml'); |
//$this->outputScreenContents('Initial ingest form submit step 2 - PDF collection', 'fedora_repository'); |
||||||
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); |
$this->assertPattern('/Item .* created successfully./', "Verified item created."); |
||||||
//$this->outputScreenContents('Initial ingest form submit step 2 - PDF collection', 'fedora_repository'); |
|
||||||
$this->assertPattern('/Item .* created successfully./', "Verified item created."); |
$pid = $this->getIngestedPid(); |
||||||
|
$pid_list[] = $pid; |
||||||
$pid = $this->getIngestedPid(); |
$this->pass('Now attempting to ingest a PDF into the new collection.'); |
||||||
$pid_list[] = $pid; |
// Now try ingesting a PDF |
||||||
$this->pass('Now attempting to ingest a PDF into the new collection.'); |
$ingest_form = array(); |
||||||
// Now try ingesting a PDF |
$ingest_form['models'] = 'islandora:strict_pdf/ISLANDORACM'; |
||||||
$ingest_form = array(); |
$this->drupalPost("fedora/ingestObject/$pid/", $ingest_form, 'Next'); |
||||||
$ingest_form['models'] = 'islandora:strict_pdf/ISLANDORACM'; |
// Required fields are file location, dc:title and dc:description |
||||||
$this->drupalPost("fedora/ingestObject/$pid/", $ingest_form, 'Next'); |
$ingest_form_step_2 = array(); |
||||||
// Required fields are file location, dc:title and dc:description |
$ingest_form_step_2['dc:title'] = "Lorem Ipsum"; |
||||||
$ingest_form_step_2 = array(); |
$ingest_form_step_2['dc:description'] = $this->randomName(256); |
||||||
$ingest_form_step_2['dc:title'] = "Lorem Ipsum"; |
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf'); |
||||||
$ingest_form_step_2['dc:description'] = $this->randomName(256); |
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); |
||||||
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf'); |
$pid = $this->getIngestedPid(); |
||||||
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); |
$pid_list[] = $pid; |
||||||
$pid = $this->getIngestedPid(); |
if (!empty($pid)) { |
||||||
$pid_list[] = $pid; |
$this->pass("Successfully ingested PDF object $pid."); |
||||||
if (!empty($pid)) { |
} |
||||||
$this->pass("Successfully ingested PDF object $pid."); |
$this->cleanUpRepository($pid_list); |
||||||
} |
} |
||||||
$this->cleanUpRepository($pid_list); |
|
||||||
} |
public function testPidSpaceRestriction() { |
||||||
|
|
||||||
private function cleanUpRepository($pid_list = array()) { |
// give user full permissions |
||||||
$this->pass("This is the PID list to purge: ". implode(", ", $pid_list) ); |
$admin_tester = $this->drupalCreateUser(array('administer site configuration', 'view fedora collection')); |
||||||
foreach ($pid_list as $pid) { |
$this->drupalLogin($admin_tester); |
||||||
$this->drupalPost("fedora/repository/purgeObject/$pid", array(), 'Purge'); |
//$adminRole = $this->drupalCreateRole(array('administer site configuration','view fedora collection')); |
||||||
} |
$inVal['fedora_namespace_restriction_enforced'] = TRUE; |
||||||
} |
$inVal['fedora_pids_allowed'] = 'simpletest:'; |
||||||
|
$this->drupalPost('admin/settings/fedora_repository', $inVal, 'Save configuration'); |
||||||
private function getIngestedPid() { |
$this->assertPattern('/The configuration options have been saved./', 'The configuration options have been saved.'); |
||||||
$subject = $this->drupalGetContent(); |
|
||||||
$pattern = '/">(.*)<\/a> created successfully./'; |
$this->drupalGet('fedora/repository/demo:SmileyStuff/'); |
||||||
$matches = array(); |
$this->assertPattern('/Access denied/', 'No access to SmileyStuff Collection'); |
||||||
$res = preg_match($pattern, $subject, $matches); |
$inVal['fedora_namespace_restriction_enforced'] = 0; |
||||||
return $matches[1]; |
$this->drupalPost('admin/settings/fedora_repository', $inVal, 'Save configuration'); |
||||||
} |
$this->assertPattern('/The configuration options have been saved./', 'The configuration options have been saved.'); |
||||||
|
$this->drupalLogin($this->repository_user); |
||||||
private function outputScreenContents($description, $basename) { |
$this->drupalGet('fedora/repository/demo:SmileyStuff/'); |
||||||
// This is a hack to get a directory that won't be cleaned up by SimpleTest. |
$this->assertPattern('/Collection of Smiley Stuff/', 'Access to SmileyStuff Collection'); |
||||||
$file_dir = file_directory_path() . '../simpletest_output_pages'; |
} |
||||||
if (!is_dir($file_dir)) { |
|
||||||
mkdir($file_dir, 0777, TRUE); |
private function cleanUpRepository($pid_list = array()) { |
||||||
} |
$this->pass("This is the PID list to purge: " . implode(", ", $pid_list)); |
||||||
$output_path = "$file_dir/$basename.". $this->randomName(10) . '.html'; |
foreach ($pid_list as $pid) { |
||||||
$rv = file_put_contents($output_path, $this->drupalGetContent()); |
$this->drupalPost("fedora/repository/purgeObject/$pid", array(), 'Purge'); |
||||||
$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')) { |
private function getIngestedPid() { |
||||||
// Create a role with the given permission set. |
$subject = $this->drupalGetContent(); |
||||||
if (!($rid = $this->drupalCreateRole($permissions))) { |
$pattern = '/">(.*)<\/a> created successfully./'; |
||||||
return FALSE; |
$matches = array(); |
||||||
} |
$res = preg_match($pattern, $subject, $matches); |
||||||
|
return $matches[1]; |
||||||
// Create a user assigned to that role. |
} |
||||||
$edit = array(); |
|
||||||
$edit['name'] = 'simpletestuser'; |
private function outputScreenContents($description, $basename) { |
||||||
$edit['mail'] = $edit['name'] . '@example.com'; |
// This is a hack to get a directory that won't be cleaned up by SimpleTest. |
||||||
$edit['roles'] = array($rid => $rid); |
$file_dir = file_directory_path() . '../simpletest_output_pages'; |
||||||
$edit['pass'] = 'simpletestpass'; |
if (!is_dir($file_dir)) { |
||||||
$edit['status'] = 1; |
mkdir($file_dir, 0777, TRUE); |
||||||
|
} |
||||||
$account = user_save('', $edit); |
$output_path = "$file_dir/$basename." . $this->randomName(10) . '.html'; |
||||||
|
$rv = file_put_contents($output_path, $this->drupalGetContent()); |
||||||
$this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login')); |
$this->pass("$description: Contents of result page are " . l('here', $output_path)); |
||||||
if (empty($account->uid)) { |
} |
||||||
return FALSE; |
|
||||||
} |
protected function drupalCreateFedoraUser($permissions = array('access comments', 'access content', 'post comments', 'post comments without approval')) { |
||||||
|
// Create a role with the given permission set. |
||||||
// Add the raw password so that we can log in as this user. |
if (!($rid = $this->drupalCreateRole($permissions))) { |
||||||
$account->pass_raw = $edit['pass']; |
return FALSE; |
||||||
return $account; |
} |
||||||
} |
|
||||||
|
// 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; |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
class FedoraRepositoryClosedNameSpaceTestCase extends DrupalWebTestCase { |
||||||
|
|
||||||
|
public static function getInfo() { |
||||||
|
return array( |
||||||
|
'name' => 'Fedora Repository with closed name space', |
||||||
|
'description' => t('Fails if allow_open_namespace has been set to TRUE in settings.php.'), |
||||||
|
'group' => t('fedora repository'), |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
function setUp() { |
||||||
|
parent::setUp('fedora_repository'); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
function testRestrictedNamePage() { |
||||||
|
$admin_tester = $this->drupalCreateUser(array('administer site configuration', 'view fedora collection')); |
||||||
|
$this->drupalLogin($admin_tester); |
||||||
|
$this->drupalGet('admin/settings/fedora_repository'); |
||||||
|
$this->assertNoText('Enforce namespace restrictions:'); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue