'Code coverage', 'page callback' => 'code_coverage_report_view', 'page arguments' => array(1), 'access arguments' => array('view code_coverage reports'), 'file' => 'code_coverage.report.inc', 'type' => MENU_CALLBACK, ); $items['coverage/%/%'] = array( 'title' => 'Code coverage', 'page callback' => 'code_coverage_report_view_file', 'page arguments' => array(1, 2), 'access arguments' => array('view code_coverage reports'), 'file' => 'code_coverage.report.inc', 'type' => MENU_CALLBACK, ); $items['admin/config/development/code_coverage'] = array( 'title' => 'Code coverage', 'page callback' => 'drupal_get_form', 'page arguments' => array('code_coverage_settings_form'), 'access arguments' => array('administer site configuration'), ); return $items; } /** * Implementation of hook_permission(). */ function code_coverage_permission() { return array( 'view code_coverage reports' => array( 'title' => t('View code coverage reports'), 'description' => t('View the code coverage reports.'), ), ); } /** * Settings form. */ function code_coverage_settings_form($form, &$form_state) { $form['clear'] = array( '#type' => 'fieldset', '#title' => t('Clear'), '#description' => t('Clear all results stored in database.'), ); $form['clear']['op'] = array( '#type' => 'submit', '#value' => t('Clear results'), '#submit' => array('code_coverage_result_clear'), ); $form['filter'] = array( '#type' => 'fieldset', '#title' => t('Filter'), ); $form['filter']['code_coverage_modules'] = array( '#type' => 'checkboxes', '#title' => t('Modules'), '#description' => t('Modules to record code coverage for. Leave blank for all.'), '#options' => module_list(), '#default_value' => variable_get('code_coverage_modules', array()), ); unset($form['filter']['code_coverage_modules']['#options']['code_coverage']); $form['filter']['code_coverage_files'] = array( '#type' => 'textarea', '#title' => t('Files'), '#description' => t('Files to record code coverage for (use relative path and place each on separate line). Leave blank for all.'), '#default_value' => variable_get('code_coverage_files', ''), ); $form = system_settings_form($form); $form['#submit'][] = 'code_coverage_settings_form_process'; return $form; } /** * Pre-process settings so they are ready for use. */ function code_coverage_settings_form_process($form, &$form_state) { // Use the module path when comparing against the relative path. $modules = array_keys(array_filter($form_state['values']['code_coverage_modules'])); foreach ($modules as &$module) { $module = drupal_get_path('module', $module); } variable_set('code_coverage_filter_modules', $modules); // If the first entry is empty then the file filter was not set. $files = explode("\n", $form_state['values']['code_coverage_files']); if (!$files[0]) { $files = array(); } variable_set('code_coverage_filter_files', $files); } /** * Clear all results stored in database. */ function code_coverage_result_clear() { $total = 0; foreach (array('code_coverage_file', 'code_coverage_line', 'code_coverage_log') as $table) { $total += db_delete($table)->execute(); } // Display message containing total number of records cleared. drupal_set_message(t('Cleared @count record(s).', array('@count' => number_format($total)))); }