diff --git a/tests/web_test_case.inc b/tests/web_test_case.inc old mode 100644 new mode 100755 index 8a5b9a00..0206d962 --- a/tests/web_test_case.inc +++ b/tests/web_test_case.inc @@ -99,6 +99,78 @@ class IslandoraWebTestCase extends DrupalWebTestCase { $this->admin->repository = $connection->repository; return $this->admin; } + + /** + * Creates a temporary Drupal user with administrative privileges. This is much simpler than the probably-unnecessary process of determining the correct permissions for most tests. + * + * @param $permissions + * An array of permissions which the temporary admin user will adopt; should be left blank, as this will just pull all the permissions currently assigned to the Administrator role. + * + */ + public function createDrupalAdminUser(array $permissions = array()) { + $roles = user_roles(); + $index = array_search('administrator', $roles); + $user = $this->drupalCreateUser($permissions); + $user->roles[$index] = 'administrator'; + return user_save($user); + } + + /** + * Creates a randomly generated child collection in the top-level collection through the testing interface. This should be used in lieu of throwing test objects into a standard collection, in case that collection has been deleted. + * + * @param $label + * The label that should be assigned to the collection + * @param $model + * The content model the collection should use + * @param $pid + * The PID that should be assigned to the collection (left blank by default, using a sequentially assigned number) + * @see IslandoraWebTestCase::deleteRootTestCollection() + */ + public function createRootTestCollection($label, $model, $pid = '') { + $this->drupalGet('islandora'); + $root = $this->url; + $path = $root . '/manage/collection'; + $this->clickLink(t('Manage')); + $this->clickLink(t('Collection')); + $edit = array('label' => $label, 'pid' => $pid, 'inherit_policy' => FALSE, 'content_models[' . $model . ']' => TRUE); + $this->drupalPost($path, $edit, t('Create collection'), $options = array(), $headers = array(), $form_html_id = 'islandora-basic-collection-create-child-collection-form'); + $this->assertText($label, t('Created collection %label using the content model %model', array('%label' => $label, '%model' => $model)), 'Islandora'); + } + + /** + * Deletes a child collection from the root collection by searching for a particular label. + * + * @param $label + * The label of the collection to be deleted + * @see IslandoraWebTestCase::createRootTestCollection() + */ + public function deleteRootTestCollectionByLabel($label) { + $collection = $this->openRootTestCollectionByLabel($label); + if ($collection != FALSE) { + $this->clickLink('Manage'); + $this->clickLink('Properties'); + $path = $this->url; + + $edit = array(); + $this->drupalPost($path, $edit, t('Delete Collection')); + $path = $this->url; + $this->drupalPost($path, $edit, t('Delete')); + $this->pass(t('Deleted collection %label by searching the root collection', array('%label' => $label)), t('Islandora')); + } + } + + /** + * Deletes a child collection from the root collection directly via PID + */ + public function deleteRootTestCollectionByPid($label, $pid) { + $path = 'islandora/object/' . $pid . '/manage/properties'; + $edit = array(); + $this->drupalPost($path, $edit, t('Delete Collection')); + $path = $this->url; + $this->drupalPost($path, $edit, t('Delete')); + $this->assertText('children from', t('Deleted collection %label directly via PID %pid', array('%label' => $label, '%pid' => $pid)), t('Islandora')); + } + /** * Stores the content of the Drupal Filter for later restoration. */ @@ -113,6 +185,44 @@ class IslandoraWebTestCase extends DrupalWebTestCase { } } + /** + * Searches through the pages inside the root collection and opens the one specified by its label. This is much slower than doing it directly by PID; use this in tests where the PID is unknown. + * @param $label + * The label of the collection + * + */ + public function openRootTestCollectionByLabel($label, $index = 0) { + $nexturls = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => 'next >')); + if (isset($nexturls[$index])) { + while (isset($nexturls[$index])) { + $urls = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label)); + + if (isset($urls[$index])) { + $url_target = $this->getAbsoluteUrl($urls[$index]['href']); + } + + if (isset($url_target)) { + $this->assertTrue(isset($urls[$index]), t('Found collection %label in root collection', array('%label' => $label)), t('Islandora')); + return $this->drupalGet($url_target); + } + } + return FALSE; + } + else { + $urls = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label)); + + if (isset($urls[$index])) { + $url_target = $this->getAbsoluteUrl($urls[$index]['href']); + } + + if (isset($url_target)) { + $this->assertTrue(isset($urls[$index]), t('Found collection %label in root collection', array('%label' => $label)), t('Islandora')); + return $this->drupalGet($url_target); + } + } + return FALSE; + } + /** * Restores the original Drupal filter, frees any allocated resources. *