Browse Source

Merge pull request #549 from qadan/7.x-filter_drupal_is_writeable

7.x filter-drupal.xml is writable
pull/560/head
Jordan Dukart 10 years ago
parent
commit
08e7da89bc
  1. 26
      islandora.module
  2. 87
      tests/includes/islandora_web_test_case.inc

26
islandora.module

@ -1814,10 +1814,29 @@ function islandora_islandora_datastream_modified(AbstractObject $object, Abstrac
*/
function islandora_form_simpletest_test_form_alter(array &$form) {
module_load_include('inc', 'simpletest', 'simpletest.pages');
module_load_include('inc', 'islandora', 'tests/includes/test_utility_abstraction');
$configuration = IslandoraTestUtilityClass::getTestConfiguration();
$filter_path = $configuration['drupal_filter_file'];
$filter_status = is_writable($filter_path);
if ($filter_status) {
$filter_status_message = theme_image(array('path' => 'misc/watchdog-ok.png', 'attributes' => array())) . " ";
$filter_status_message .= t("Drupal filter at <b>!filter_path</b> is writable by the server.", array(
'!filter_path' => $filter_path,
));
}
else {
$filter_status_message = theme_image(array('path' => 'misc/watchdog-error.png', 'attributes' => array())) . " ";
$filter_status_message .= t("Drupal filter at <b>!filter_path</b> is not writable by the server. Please make sure your webserver has permission to write to the Drupal filter. If the path given is incorrect, you will need to change it in your server's test config file, located in the Islandora module's 'tests' folder as test_config.ini or default.test_config.ini.", array(
'!filter_path' => $filter_path,
));
}
$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.'),
'#description' => t("Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.<p>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.</p><p><em>Drupal Filter Write Status:</em> !filter_status_message</p>", array(
'!filter_status_message' => $filter_status_message,
)),
);
$form['tests']['table'] = array(
@ -1837,6 +1856,9 @@ function islandora_form_simpletest_test_form_alter(array &$form) {
'#title' => filter_xss($info['name']),
'#description' => filter_xss($info['description']),
);
if (is_subclass_of($class, 'IslandoraWebTestCase', TRUE) && !$filter_status) {
$form['tests']['table'][$group][$class]['#disabled'] = TRUE;
}
}
}
@ -1861,7 +1883,7 @@ function islandora_form_simpletest_test_form_alter(array &$form) {
}
/**
* Submit handler for islandora_form_simpletest_test_form_alter().
* Removes simpletest entries from the Drupal filter.
*/
function islandora_repair_drupal_filter() {

87
tests/includes/islandora_web_test_case.inc

@ -21,6 +21,17 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
*/
protected $deleteObjectsOnTeardown = TRUE;
/**
* Instantiates an IslandoraWebTestCase with a configuration.
*
* @throws Exception
* If the required test config file is not found.
*/
public function __construct($test_id = NULL) {
$this->configuration = IslandoraTestUtilityClass::getTestConfiguration();
parent::__construct($test_id);
}
/**
* Defers to IslandoraTestUtilities for missing methods.
*
@ -28,6 +39,9 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* The method being called.
* @param array $args
* The arguments for that method.
*
* @return bool
* TRUE if the result was a pass, or FALSE otherwise.
*/
public function __call($method, $args) {
module_load_include('inc', 'islandora', 'tests/includes/utilities');
@ -57,6 +71,74 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
}
}
/**
* Run all tests in this class.
*
* Attempts to figure out if the Drupal filter is writable before running any
* tests.
*
* @see DrupalWebTestCase::run()
*/
public function run(array $methods = array()) {
// Determine if the Drupal filter is writable so we know if we can proceed.
if (is_writable($this->configuration['drupal_filter_file'])) {
// Set up the SimpleTest environment.
simpletest_verbose(NULL, variable_get('file_public_path', conf_path() . '/files'), get_class($this));
$this->httpauth_method = variable_get('simpletest_httpauth_method', CURLAUTH_BASIC);
$username = variable_get('simpletest_httpauth_username', NULL);
$password = variable_get('simpletest_httpauth_password', NULL);
if ($username && $password) {
$this->httpauth_credentials = $username . ':' . $password;
}
set_error_handler(array($this, 'errorHandler'));
$class = get_class($this);
// Iterate through all the methods in this class, unless a specific list
// of methods to run was passed.
$class_methods = get_class_methods($class);
if ($methods) {
$class_methods = array_intersect($class_methods, $methods);
}
foreach ($class_methods as $method) {
// If the current method starts with "test", run it - it's a test.
if (strtolower(substr($method, 0, 4)) == 'test') {
// Insert a fail record. This will be deleted on completion to ensure
// that testing completed.
$method_info = new ReflectionMethod($class, $method);
$caller = array(
'file' => $method_info->getFileName(),
'line' => $method_info->getStartLine(),
'function' => $class . '->' . $method . '()',
);
$completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
try {
$this->setUp();
$this->$method();
}
catch (Exception $e) {
$this->exceptionHandler($e);
}
$this->tearDown();
// Remove the completion check record.
DrupalTestCase::deleteAssert($completion_check_id);
}
}
}
// If the Drupal filter is not writable, skip testing and error out.
else {
$method_info = new ReflectionMethod($this, 'run');
$class = get_class($this);
set_error_handler(array($this, 'errorHandler'));
$caller = array(
'file' => $method_info->getFileName(),
'line' => $method_info->getStartLine(),
'function' => $class . '->run()',
);
$this->assert(FALSE, "Unable to proceed; the Drupal filter is not writable by the server.", "Completion check", $caller);
}
drupal_get_messages();
restore_error_handler();
}
/**
* Sets up the web test case.
*
@ -74,7 +156,6 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
module_load_include('inc', 'islandora', 'includes/tuque_wrapper');
module_load_include('inc', 'islandora', 'tests/includes/utilities');
$this->configuration = IslandoraTestUtilityClass::getTestConfiguration();
if ($this->configuration['use_drupal_filter']) {
$this->setUpDrupalFilter();
}
@ -142,7 +223,6 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
islandora_repair_drupal_filter();
}
unset($this->admin);
unset($this->configuration);
parent::tearDown();
}
@ -178,6 +258,9 @@ class IslandoraWebTestCase extends DrupalWebTestCase {
* The label of the first 'Delete' button
* @param bool $safety
* If TRUE, this will only delete objects owned by users in $this->users.
*
* @return bool
* If the deletion fails, return FALSE.
*/
public function deleteObject($pid, $button = NULL, $safety = TRUE) {
$object = islandora_object_load($pid);

Loading…
Cancel
Save