| 21 |
while ($test = db_fetch_object($tests)) { |
while ($test = db_fetch_object($tests)) { |
| 22 |
$rows[] = array( |
$rows[] = array( |
| 23 |
check_plain($test->name) .'<div class="description">' . check_plain($test->description) . '</div>', |
check_plain($test->name) .'<div class="description">' . check_plain($test->description) . '</div>', |
| 24 |
l('Edit', 'admin/build/simpletest_automator/' . $test->said), |
l(t('Edit'), 'admin/build/simpletest_automator/' . $test->said), |
| 25 |
l('Delete', 'admin/build/simpletest_automator/' . $test->said . '/delete'), |
l(t('Modules'), 'admin/build/simpletest_automator/' . $test->said . '/modules'), |
| 26 |
|
l(t('Permissions'), 'admin/build/simpletest_automator/' . $test->said . '/permissions'), |
| 27 |
|
l(t('Actions'), 'admin/build/simpletest_automator/' . $test->said . '/actions'), |
| 28 |
|
l(t('Export'), 'admin/build/simpletest_automator/' . $test->said . '/export'), |
| 29 |
|
l(t('Delete'), 'admin/build/simpletest_automator/' . $test->said . '/delete'), |
| 30 |
); |
); |
| 31 |
} |
} |
| 32 |
if (empty($rows)) { |
if (empty($rows)) { |
| 33 |
$rows = array(array(array('data' => t('No tests found. You can <a href="!url">add a new one</a>.', array('!url' => url('admin/build/simpletest_automator/add'))), 'colspan' => 3))); |
$rows = array(array(array('data' => t('No tests found. You can <a href="!url">add a new one</a>.', array('!url' => url('admin/build/simpletest_automator/add'))), 'colspan' => 3))); |
| 34 |
} |
} |
| 35 |
return theme('table', array('Name', array('data' => 'Operations', 'colspan' => 2)), $rows); |
return theme('table', array('Name', array('data' => t('Operations'), 'colspan' => 6)), $rows); |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
|
|
| 39 |
function simpletest_automator_admin_import(&$form_state) { |
function simpletest_automator_admin_import(&$form_state) { |
| 40 |
$form = array(); |
$form = array(); |
| 41 |
$form['upload'] = array( |
$form['import'] = array( |
| 42 |
'#type' => 'file', |
'#type' => 'textarea', |
| 43 |
'#title' => t('Test'), |
'#title' => t('Test'), |
| 44 |
'#description' => t('Upload a test that was exported by SimpleTest Automator. This will not work with any test.'), |
'#description' => t('Enter a previously exported ("For import") SimpleTest automator test, as the serialized output given.'), |
| 45 |
'#size' => 40, |
'#size' => 40, |
| 46 |
); |
); |
| 47 |
$form['submit'] = array( |
$form['submit'] = array( |
| 48 |
'#type' => 'submit', |
'#type' => 'submit', |
| 49 |
'#value' => t('Import'), |
'#value' => t('Import'), |
| 50 |
); |
); |
|
$form['#attributes']['enctype'] = 'multipart/form-data'; |
|
| 51 |
return $form; |
return $form; |
| 52 |
} |
} |
| 53 |
|
|
| 54 |
function simpletest_automator_admin_import_submit($form, &$form_state) { |
function simpletest_automator_admin_import_validate($form, &$form_state) { |
| 55 |
$file = file_save_upload('upload'); |
@$simpletest_automator = unserialize(trim($form_state['values']['import'])); |
| 56 |
if (!is_object($file) || !isset($file->filepath)) { |
if (!$simpletest_automator) { |
| 57 |
die('a horrible death'); |
form_set_error('import', t('Could not parse import format. Are you sure you copied the entire export?')); |
|
} |
|
|
$handle = fopen($file->filepath, "r"); |
|
|
if (isset($handle) && $handle) { |
|
|
while (!feof($handle)) { |
|
|
$buffer = fgets($handle); |
|
|
if (preg_match('/^ \* SimpleTest Automator: (.*)$/', $buffer, $matches)) { |
|
|
$test = $matches[1]; |
|
|
break; |
|
|
} |
|
|
} |
|
|
fclose($handle); |
|
|
} |
|
|
if (isset($test)) { |
|
|
$said = simpletest_automator_save($test); |
|
|
foreach ($test->actions as $action) { |
|
|
$action->said = $said; |
|
|
simpletest_automator_action_save($action); |
|
|
} |
|
|
$form_state['redirect'] = 'admin/build/simpletest_automator/'. $said; |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Couldn\'t parse file. Are you sure you uploaded the correct file?'), 'warning'); |
|
| 58 |
} |
} |
| 59 |
} |
} |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
function simpletest_automator_admin_import_submit($form, &$form_state) { |
| 63 |
|
$simpletest_automator = unserialize(trim($form_state['values']['import'])); |
| 64 |
|
simpletest_automator_save($simpletest_automator); |
| 65 |
|
drupal_set_message(t('Import successful.')); |
| 66 |
|
$form_state['redirect'] = 'admin/build/simpletest_automator'; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
/** |
/** |
| 70 |
* Menu callback: simpletest editing page. |
* Menu callback: simpletest editing page. |
| 71 |
*/ |
*/ |
| 452 |
$form['actions'] = array('#tree' => TRUE); |
$form['actions'] = array('#tree' => TRUE); |
| 453 |
foreach ($simpletest_automator->actions as $action) { |
foreach ($simpletest_automator->actions as $action) { |
| 454 |
$form['actions'][$action->aid] = array(); |
$form['actions'][$action->aid] = array(); |
| 455 |
$info = simpletest_automator_action_info($action); |
$info = _simpletest_automator_action_info($action); |
| 456 |
$form['actions'][$action->aid]['label']['#markup'] = $info['label']; |
$form['actions'][$action->aid]['label']['#markup'] = $info['label']; |
| 457 |
$form['actions'][$action->aid]['description']['#markup'] = $info['description']; |
$form['actions'][$action->aid]['description']['#markup'] = $info['description']; |
| 458 |
$form['actions'][$action->aid]['edit']['#markup'] = l(t('Edit'), "admin/build/simpletest_automator/$simpletest_automator->said/actions/$action->aid/edit"); |
$form['actions'][$action->aid]['edit']['#markup'] = l(t('Edit'), "admin/build/simpletest_automator/$simpletest_automator->said/actions/$action->aid/edit"); |
| 580 |
if (!isset($simpletest_automator->actions[$aid])) { |
if (!isset($simpletest_automator->actions[$aid])) { |
| 581 |
return drupal_not_found(); |
return drupal_not_found(); |
| 582 |
} |
} |
| 583 |
$info = simpletest_automator_action_info($simpletest_automator->actions[$aid]); |
$info = _simpletest_automator_action_info($simpletest_automator->actions[$aid]); |
| 584 |
$form = array(); |
$form = array(); |
| 585 |
$form['aid'] = array( |
$form['aid'] = array( |
| 586 |
'#type' => 'value', |
'#type' => 'value', |
| 593 |
return confirm_form($form, t('Are you sure you want to delete %action', array('%action' => $info['label'])), 'admin/build/simpletest_automator/'. $simpletest_automator->said .'/actions'); |
return confirm_form($form, t('Are you sure you want to delete %action', array('%action' => $info['label'])), 'admin/build/simpletest_automator/'. $simpletest_automator->said .'/actions'); |
| 594 |
} |
} |
| 595 |
|
|
| 596 |
function simpletest_automator_admin_export(&$form_state, $simpletest_automator) { |
function simpletest_automator_admin_export($simpletest_automator, $type = NULL) { |
| 597 |
$form = array(); |
if (empty($type)) { |
| 598 |
drupal_function_exists('simpletest_automator_export_test'); |
$items = array( |
| 599 |
|
l(t('File'), 'admin/build/simpletest_automator/' . $simpletest_automator->said . '/export/file') . '<div class="description">' . t('Select this option to export your test to a .test file.') . '</div>', |
| 600 |
|
l(t('For import'), 'admin/build/simpletest_automator/' . $simpletest_automator->said . '/export/import') . '<div class="description">' . t('Select this option to export your test in a format that can be re-imported in the "import" tab.') . '</div>', |
| 601 |
|
); |
| 602 |
|
return theme('item_list', $items); |
| 603 |
|
} |
| 604 |
|
else { |
| 605 |
|
switch ($type) { |
| 606 |
|
case 'file': |
| 607 |
|
return '<iframe src="'. url('simpletest_automator/export/' . $simpletest_automator->said) . '" width="1" height="1" style="border:0"></iframe>'. t('Your download should begin immediately. If it doesn\'t, click <a href="!url">here</a>.', array('!url' => url('simpletest_automator/export/' . $simpletest_automator->said))); |
| 608 |
|
|
| 609 |
|
case 'import': |
| 610 |
|
drupal_function_exists('_simpletest_automator_export_php'); |
| 611 |
|
drupal_add_css(drupal_get_path('module', 'simpletest_automator') . '/simpletest_automator.css'); |
| 612 |
|
return '<div class="simpletest-automator-export">' . check_plain(_simpletest_automator_export_php($simpletest_automator)) . '</div>'; |
| 613 |
|
|
| 614 |
|
default: |
| 615 |
|
return drupal_not_found(); |
| 616 |
|
|
| 617 |
|
} |
| 618 |
|
} |
| 619 |
// Provide it as a file download. |
// Provide it as a file download. |
|
$form['iframe']['#markup'] = '<iframe src="'. url('simpletest_automator/export/'. $simpletest_automator->said) .'" width="1" height="1" style="border:0"></iframe>'. t('Your download should begin immediately. If it doesn\'t, click <a href="!url">here</a>.', array('!url' => url('simpletest_automator/export/'. $simpletest_automator->said))); |
|
| 620 |
|
|
| 621 |
return $form; |
return $form; |
| 622 |
} |
} |
| 732 |
$output .= theme('table', $header, $rows, array('id' => 'permissions')); |
$output .= theme('table', $header, $rows, array('id' => 'permissions')); |
| 733 |
$output .= drupal_render($submit); |
$output .= drupal_render($submit); |
| 734 |
return $output; |
return $output; |
|
} |
|
|
drupal_function_exists('db_add_field'); |
|
| 735 |
|
} |