$this->loggedInUser, 'db_access' => TRUE, ); $utilities = new IslandoraTestUtilities($this->configuration, $params); if (!method_exists($utilities, $method)) { $caller = $this->getAssertionCall(); throw new BadMethodCallException("Exception: undefined method $method in {$caller['file']}, line {$caller['line']}."); } $result = call_user_func_array(array(&$utilities, $method), $args); $this->parseUtilityResults($utilities); return $result; } /** * Parses utility results and passes them to the test results as an assertion. * * @param IslandoraTestUtilities $utility * An instance of IslandoraTestUtilities with populated results. */ public function parseUtilityResults($utility) { foreach ($utility->getResults() as $result) { $this->assert($result->getType(), $result->getMessage(), 'Islandora', $result->getCaller()); } } /** * Sets up the web test case. * * @see DrupalWebTestCase::setUp() */ public function setUp() { $args = func_get_args(); $args = (isset($args[0]) && is_array($args[0])) ? $args[0] : $args; // Always enable islandora. $args[] = 'islandora'; parent::setUp($args); // It's possible test are running before class autoloading. module_load_include('inc', 'islandora', 'includes/tuque'); module_load_include('inc', 'islandora', 'includes/tuque_wrapper'); module_load_include('inc', 'islandora', 'tests/includes/utilities'); $this->configuration = islandora_get_test_configuration(); if ($this->configuration['use_drupal_filter']) { $this->setUpDrupalFilter(); } $this->admin = $this->createAdminUser(); } /** * Creates the a full fedora admin user with a repository connection. */ protected function createAdminUser() { $roles = user_roles(); $index = array_search('administrator', $roles); $user = $this->drupalCreateUser(); $user->roles[$index] = 'administrator'; $user->name = $this->configuration['admin_user']; $user->pass = $this->configuration['admin_pass']; $user = user_save($user); $url = variable_get('islandora_base_url', $this->configuration['fedora_url']); $connection = islandora_get_tuque_connection($user, $url); $user->repository = $connection->repository; return $user; } /** * Logs in the given user, handles the special case where the user is admin. * * @see DrupalWebTestCase::drupalLogin() */ protected function drupalLogin(stdClass $account) { if ($account->uid == $this->admin->uid) { // Create password for Drupal. $edit = array('pass' => user_password()); $account = user_save($account, $edit); // Raw password is used to login. $account->pass_raw = $edit['pass']; // We must login before changing the password for fedora. parent::drupalLogin($account); $account->name = $this->configuration['admin_user']; $account->pass = $this->configuration['admin_pass']; // Save the fedora admin credentials for later GET/POST requests. $account = user_save($account); } else { parent::drupalLogin($account); $this->users[] = $account->name; } } /** * Restores the original Drupal filter, frees any allocated resources. * * To safeguard against leaving test objects in the repository, tearDown() * calls deleteUserCreatedObjects() every time by default. This feature can be * toggled by setting $this->deleteObjectsOnTeardown to TRUE or FALSE. * * @see DrupalWebTestCase::tearDown() */ public function tearDown() { if ($this->deleteObjectsOnTeardown) { foreach ($this->users as $user) { $this->deleteUserCreatedObjects($user); } } if ($this->configuration['use_drupal_filter']) { islandora_repair_drupal_filter(); } unset($this->admin); unset($this->configuration); parent::tearDown(); } /** * Gets a tuque object from a path. * * @param string $path * A full or partial path to an islandora object. * * @return AbstractObject * The pid of the object or FALSE if a PID is not found. */ public function getObjectFromPath($path) { $path_parts = explode('/', $path); $array_length = count($path_parts); for ($i = 0; $i < $array_length; $i++) { if ($path_parts[$i] == 'islandora' && isset($path_parts[$i + 1]) && $path_parts[$i + 1] == 'object') { if (isset($path_parts[$i + 2])) { return islandora_object_load(urldecode($path_parts[$i + 2])); } } } $this->fail("Failed to parse path: $path."); return FALSE; } /** * Deletes an object using the PID. This does the deletion using the UI. * * @param string $pid * The PID of the collection to be deleted * @param string $button * The label of the first 'Delete' button * @param bool $safety * If TRUE, this will only delete objects owned by users in $this->users. */ public function deleteObject($pid, $button = NULL, $safety = TRUE) { $object = islandora_object_load($pid); if (!$safety || in_array($object->owner, $this->users)) { $path = "islandora/object/$pid/manage/properties"; if (isset($button)) { $this->drupalPost($path, array(), $button); } else { $object = islandora_object_load($pid); $this->drupalPost($path, array(), "Permanently remove '{$object->label}' from repository"); } $this->drupalPost($this->url, array(), t('Delete')); $this->drupalGet("islandora/object/$pid"); $this->assertResponse(404, "Object $pid successfully deleted."); } else { $this->fail("Cannot delete object {$pid}; it is owned by non-test user {$object->owner}, and this function was called with the safety on."); return FALSE; } } /** * These are a few quick helper functions to fill in a gap in the standard * DrupalWebTestCase where no function exists to test for the simple existence * or non-existence of an error. */ /** * Asserts that an error is found in $this->content. * * @param string $message * The message to pass on to the results. * @param string $group * The group to place the result in. * * @return bool * TRUE on success, FALSE on failure. */ public function assertError($message = '', $group = 'Other') { if (!$message) { $message = "Error found on current page when error was expected."; } return $this->assertRaw("