It'd be nice if it was simpler to import accessibility tests on install, either via features integration or just cleaner API functions
What I ended up doing:
/**
* Implements hook_install()
*/
function mymodule_install() {
module_load_include('admin.inc', 'accessibility');
$tests = module_invoke_all('accessibility_tests', TRUE);
$enabled = _accessibility_admin_get_enabled_tests();
$add_test = array_unique(array_merge(
_mymodule_get_test_from_guildelines('508'),
_mymodule_get_test_from_guildelines('wcag2aa')
));
foreach ($add_test as $test) {
if (!isset($enabled[$test]) && !empty($tests[$test])) {
_mymodule_accessibility_create_test_from_quail($test, $tests[$test]);
}
}
}
/**
* Creates a test entity from a quail test.
*/
function _mymodule_accessibility_create_test_from_quail($quail_name, $test) {
$language = language_default();
$new_test = new stdClass();
$new_test->language = $language->language;
$new_test->quail_name = $quail_name;
$new_test->name = $test['title'];
$new_test->severity = (isset($test['severity'])) ? $test['severity'] : 'suggestion';
$wrapper = entity_metadata_wrapper('accessibility_test', $new_test);
$wrapper->error_description->set(array('value' => $test['description'],
'format' => filter_default_format()
));
$wrapper->save(TRUE);
accessibility_test_save($new_test);
}
/**
* Fetches what tests are associated with a guideline.
*/
function _mymodule_get_test_from_guildelines($guildeline) {
$filename = libraries_get_path('quail') . '/src/resources/guidelines/' . $guildeline . '.json';
$contents = file_get_contents($filename);
return drupal_json_decode($contents);
}
Comments
Comment #1
Anonymous (not verified) commentedMost of the entity stuff is based on the model project, so it does need cleaner APIs. Features integration would be great, I think that accessibility tests are in a definite grey area between configuration and content, and might be doable via UUID features.
Another use case for this would be to have "test packs" which had predefined tests with messages for different editing environments (i.e. the alt text test message talked about fixing it for a specific editor.)
Comment #2
Anonymous (not verified) commentedKnee-jerk subject entry into tag field.
Comment #3
Anonymous (not verified) commentedHere's the beginnings of a patch, it exports and imports tests so far but needs some more testing. The one issue is that it's leaving features as 'rebuilding' even tho the semaphore is removed.
Comment #4
Anonymous (not verified) commentedMissed the new features file.
Comment #5
Anonymous (not verified) commentedFixed the problem where features would miss default states.
Comment #6
Anonymous (not verified) commentedComment #7
btopro commentedI tested this feature against the -console branch and noticed the following issues. Things export and appear to import correctly. The issue is that when you uninstall a feature it doesn't get rid of it and this causes PDO errors when you go to enable it again. It also seems to have this problem when trying to enable if there's a match in the database for the exact same record that was exported. On uninstall / install, field_revision_error_description and field_error_description need to be cleared or at least validated that they aren't going to overlap and cause a conflict.
also unrelated but noticed during install/uninstall:
Notice: Use of undefined constant ACCESSIBILITY_QUAIL_VERSION - assumed 'ACCESSIBILITY_QUAIL_VERSION' in accessibility_requirements() (line 51 of /Applications/MAMP/htdocs/dev/maketest/sites/all/modules/contrib/accessibility/accessibility.install).Comment #8
btopro commentedFeature revert was able to rebuild the records and import them again but generated the following --
Notice: Undefined variable: delete in accessibility_test_features_rebuild() (line 70 of /Applications/MAMP/htdocs/dev/maketest/sites/all/modules/contrib/accessibility/accessibility.features.inc).I'm thinking if a delete function is added for these that it'll resolve this notice and the errors reported above.
Comment #9
Anonymous (not verified) commentedFixed the delete issue, committed to 7.x.