From eb566f30097b52410a27abf79f41ecf681f3e5b6 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 2 Mar 2011 13:34:56 -0400 Subject: [PATCH] Added simple tests --- tests/fedora_repository.test | 96 +++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 22 deletions(-) diff --git a/tests/fedora_repository.test b/tests/fedora_repository.test index f5cec203..e5653d90 100644 --- a/tests/fedora_repository.test +++ b/tests/fedora_repository.test @@ -98,27 +98,6 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { $this->cleanUpRepository($pid_list); } - public function testPidSpaceRestriction() { - - // give user full permissions - $admin_tester = $this->drupalCreateUser(array('administer site configuration', 'view fedora collection')); - $this->drupalLogin($admin_tester); - //$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'); - $this->assertPattern('/The configuration options have been saved./', 'The configuration options have been saved.'); - - $this->drupalGet('fedora/repository/demo:SmileyStuff/'); - $this->assertPattern('/Access denied/', 'No access to SmileyStuff Collection'); - $inVal['fedora_namespace_restriction_enforced'] = 0; - $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); - $this->drupalGet('fedora/repository/demo:SmileyStuff/'); - $this->assertPattern('/Collection of Smiley Stuff/', 'Access to SmileyStuff Collection'); - } - private function cleanUpRepository($pid_list = array()) { $this->pass("This is the PID list to purge: " . implode(", ", $pid_list)); foreach ($pid_list as $pid) { @@ -185,7 +164,6 @@ class FedoraRepositoryClosedNameSpaceTestCase extends DrupalWebTestCase { function setUp() { parent::setUp('fedora_repository'); - } function testRestrictedNamePage() { @@ -195,4 +173,78 @@ class FedoraRepositoryClosedNameSpaceTestCase extends DrupalWebTestCase { $this->assertNoText('Enforce namespace restrictions:'); } +} + +class FedoraRepositoryOpenNameSpaceTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Fedora Repository with open name space', + 'description' => t('Fails if allow_open_namespace has been set to FALSE in settings.php.'), + '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; + } + + public function testPidSpaceRestriction() { + + // give user full permissions + $admin_tester = $this->drupalCreateUser(array('administer site configuration', 'view fedora collection')); + $this->drupalLogin($admin_tester); + $inVal['fedora_namespace_restriction_enforced'] = TRUE; + $inVal['fedora_pids_allowed'] = 'simpletest:'; + $this->drupalPost('admin/settings/fedora_repository', $inVal, 'Save configuration'); + $this->assertPattern('/The configuration options have been saved./', 'The configuration options have been saved.'); + + $this->drupalGet('fedora/repository/demo:SmileyStuff/'); + $this->assertPattern('/Access denied/', 'No access to SmileyStuff Collection'); + $inVal['fedora_namespace_restriction_enforced'] = 0; + $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); + $this->drupalGet('fedora/repository/demo:SmileyStuff/'); + $this->assertPattern('/Collection of Smiley Stuff/', 'Access to SmileyStuff Collection'); + } + + 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; + } + } \ No newline at end of file