Browse Source

tests can no longer destroy filter_drupal.xml; filter can be repaired

pull/406/head
qadan 11 years ago
parent
commit
093a134b22
  1. 94
      islandora.module
  2. 2
      tests/datastream_validators.inc
  3. 21
      tests/islandora_web_test_case.inc

94
islandora.module

@ -1602,3 +1602,97 @@ function islandora_islandora_datastream_modified(AbstractObject $object, Abstrac
)); ));
islandora_derivative_logging($logging_results); islandora_derivative_logging($logging_results);
} }
/**
* Implements hook_form_simpletest_test_form_alter().
*/
function islandora_form_simpletest_test_form_alter(array &$form) {
module_load_include('inc', 'simpletest', 'simpletest.pages');
$form['tests'] = array(
'#type' => 'fieldset',
'#title' => t('Tests'),
'#description' => t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.<br/><br/>NOTE: Tests in groups prefixed with <em>Islandora</em> generally require a configuration file, found in the Islandora module "tests" folder, as well as the use of the Islandora Drupal filter. Before any tests are run, please ensure that your web server has the appropriate permissions to alter the drupal_filter.xml file in your Fedora config folder. Your original Islandora Drupal filter configuration will NOT be overwritten by tests; HOWEVER, if PHP exits abnormally before the filter is reset, please use the "Repair Drupal Filter" button below.'),
);
$form['tests']['table'] = array(
'#theme' => 'simpletest_test_table',
);
// Generate the list of tests arranged by group.
$groups = simpletest_test_get_all();
foreach ($groups as $group => $tests) {
$form['tests']['table'][$group] = array(
'#collapsed' => TRUE,
);
foreach ($tests as $class => $info) {
$form['tests']['table'][$group][$class] = array(
'#type' => 'checkbox',
'#title' => filter_xss($info['name']),
'#description' => filter_xss($info['description']),
);
}
}
// Operation buttons.
$form['tests']['op'] = array(
'#type' => 'submit',
'#value' => t('Run tests'),
);
$form['reset'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#title' => t('Repair Islandora Drupal Filter'),
'#description' => t('Attempts to repair the Islandora Drupal filter if a test that alters the Drupal filter has crashed. This is also intended for developers when creating tests built using the IslandoraWebTestCase class.'),
);
$form['reset']['op'] = array(
'#type' => 'submit',
'#value' => t('Repair Drupal Filter'),
'#submit' => array('islandora_repair_drupal_filter'),
);
}
/**
* Submit handler for islandora_form_simpletest_test_form_alter().
*/
function islandora_repair_drupal_filter() {
// Grab the config.
$path = drupal_get_path('module', 'islandora');
if (file_exists("$path/tests/test_config.ini")) {
$configuration = parse_ini_file("$path/tests/test_config.ini");
}
elseif (file_exists("$path/tests/default.test_config.ini")) {
$configuration = parse_ini_file("$path/tests/default.test_config.ini");
}
else {
drupal_set_message(t('Required default.test_config.ini/test_config.ini file not found'), 'error');
return FALSE;
}
// Xpath to the filter 'sql' elements.
$drupal_filter_dom = new DOMDocument();
$drupal_filter_dom->loadXML(file_get_contents($configuration['drupal_filter_file']));
$drupal_filter_xpath = new DOMXPath($drupal_filter_dom);
// Blow out the simpletest stuff.
$entries = 0;
foreach ($drupal_filter_xpath->query('//sql') as $sql) {
if (strpos($sql->nodeValue, 'simpletest') !== FALSE) {
$parent = $sql->parentNode;
$root = $parent->parentNode;
$parent->removeChild($sql);
$root->removeChild($parent);
$entries++;
}
}
file_put_contents($configuration['drupal_filter_file'], $drupal_filter_dom->saveXML());
if ($entries == 0) {
drupal_set_message(t("No simpletest entries were found in the Drupal filter."));
}
else {
drupal_set_message(format_plural($entries, "Removed 1 simpletest entry from the Drupal filter.", "Removed @count simpletest entries from the Drupal filter."));
}
}

2
tests/datastream_validators.inc

@ -38,7 +38,7 @@
* @return array * @return array
* A result that can be made useful in the validation functions below. * A result that can be made useful in the validation functions below.
*/ */
function assert_valid($assertion, $results, $pass, $fail = '') { function assert_valid($assertion, $results, $pass, $fail = NULL) {
if ($assertion) { if ($assertion) {
$result = array(TRUE, $pass); $result = array(TRUE, $pass);
} }

21
tests/islandora_web_test_case.inc

@ -74,15 +74,22 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
$connection_info = Database::getConnectionInfo('default'); $connection_info = Database::getConnectionInfo('default');
$drupal_filter_dom = new DomDocument(); $drupal_filter_dom = new DomDocument();
$drupal_filter_dom->loadXML($this->originalDrupalFilterContent); $drupal_filter_dom->loadXML($this->originalDrupalFilterContent);
$drupal_filter_xpath = new DOMXPath($drupal_filter_dom);
$server = $connection_info['default']['host']; $server = $connection_info['default']['host'];
$dbname = $connection_info['default']['database']; $dbname = $connection_info['default']['database'];
$user = $connection_info['default']['username']; $user = $connection_info['default']['username'];
$password = $connection_info['default']['password']; $password = $connection_info['default']['password'];
$port = $connection_info['default']['port'] ? $connection_info['default']['port'] : '3306'; $port = $connection_info['default']['port'] ? $connection_info['default']['port'] : '3306';
$prefix = $connection_info['default']['prefix']['default']; $prefix = $connection_info['default']['prefix']['default'];
$results = $drupal_filter_xpath->query("/FilterDrupal_Connection/connection[@server='$server' and @dbname='$dbname' and @user='$user' and @password='$password' and @port='$port']/sql"); $filter_drupal_connection_node = $drupal_filter_dom->getElementsByTagName('FilterDrupal_Connection')->item(0);
$results->item(0)->nodeValue = "SELECT DISTINCT u.uid AS userid, u.name AS Name, u.pass AS Pass, r.name AS Role FROM ({$prefix}users u LEFT JOIN {$prefix}users_roles ON u.uid={$prefix}users_roles.uid) LEFT JOIN {$prefix}role r ON r.rid={$prefix}users_roles.rid WHERE u.name=? AND u.pass=?;"; $first_connection_node = $drupal_filter_dom->getElementsByTagName('connection')->item(0);
$connection_node = $filter_drupal_connection_node->insertBefore($drupal_filter_dom->createElement('connection'), $first_connection_node);
$connection_node->setAttributeNode(new DOMAttr('server', $server));
$connection_node->setAttributeNode(new DOMAttr('dbname', $dbname));
$connection_node->setAttributeNode(new DOMAttr('user', $user));
$connection_node->setAttributeNode(new DOMAttr('password', $password));
$connection_node->setAttributeNode(new DOMAttr('port', $port));
$sql_node = $connection_node->appendChild(new DOMElement('sql'));
$sql_node->appendChild($drupal_filter_dom->createTextNode("SELECT DISTINCT u.uid AS userid, u.name AS Name, u.pass AS Pass, r.name AS Role FROM ({$prefix}users u LEFT JOIN {$prefix}users_roles ON u.uid={$prefix}users_roles.uid) LEFT JOIN {$prefix}role r ON r.rid={$prefix}users_roles.rid WHERE u.name=? AND u.pass=?;"));
file_put_contents($this->configuration['drupal_filter_file'], $drupal_filter_dom->saveXML()); file_put_contents($this->configuration['drupal_filter_file'], $drupal_filter_dom->saveXML());
} }
@ -248,10 +255,16 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* @param string $button * @param string $button
* The label of the first 'Delete' button * The label of the first 'Delete' button
*/ */
public function deleteObject($pid, $button = 'Delete') { public function deleteObject($pid, $button = NULL) {
$path = 'islandora/object/' . $pid . '/manage/properties'; $path = 'islandora/object/' . $pid . '/manage/properties';
$edit = array(); $edit = array();
if (isset($button)) {
$this->drupalPost($path, $edit, $button); $this->drupalPost($path, $edit, $button);
}
else {
$object = islandora_object_load($pid);
$this->drupalPost($path, $edit, "Permanently remove '{$object->label}' from repository");
}
$this->drupalPost($this->url, $edit, t('Delete')); $this->drupalPost($this->url, $edit, t('Delete'));
$object = islandora_object_load($pid); $object = islandora_object_load($pid);

Loading…
Cancel
Save