Index: drupalorg_testing.profile =================================================================== RCS file: /cvs/drupal/contributions/profiles/drupalorg_testing/drupalorg_testing.profile,v retrieving revision 1.30 diff -u -r1.30 drupalorg_testing.profile --- drupalorg_testing.profile 8 Nov 2007 17:15:51 -0000 1.30 +++ drupalorg_testing.profile 3 Dec 2007 03:06:14 -0000 @@ -103,6 +103,7 @@ _drupalorg_testing_create_project_terms(); _drupalorg_testing_create_content(); _drupalorg_testing_configure_project_settings(); + _drupalorg_testing_create_issues(); _drupalorg_testing_create_menus(); _drupalorg_testing_configure_blocks(); _block_rehash(); @@ -785,6 +786,106 @@ } /** + * Generates sample issues; + */ +function _drupalorg_testing_create_issues($num_issues = 200) { + require_once(drupal_get_path('module', 'project_issue') . './issue.inc'); + require_once(drupal_get_path('module', 'devel') .'/devel_generate.inc'); + + // Get the nid and components of each project + $projects = array(); + $result = db_query('SELECT nid, components FROM {project_issue_projects}'); + while ($project = db_fetch_object($result)) { + $projects[] = $project; + } + + // Get the possible project statuses + $statuses = array(); + $result = db_query('SELECT sid FROM {project_issue_state}'); + while ($status = db_fetch_object($result)) { + $statuses[] = $status->sid; + } + + // Get all usernames along with their uid + $users = array(); + $result = db_query('SELECT uid, name FROM {users}'); + while ($user = db_fetch_object($result)) { + $users[] = $user; + } + + $categories = array_values(project_issue_category()); + $priorities = project_issue_priority(); + + // Generate the random issues + for ($i = 0; $i < $num_issues; $i++) { + srand((double)microtime()*1000000); + + $issue = array(); + + $rand_element = array_rand($projects); + $components = unserialize($projects[$rand_element]->components); + $issue['component'] = $components[array_rand($components)]; + $issue['pid'] = $projects[$rand_element]->nid; + + $issue['category'] = $categories[array_rand($categories)]; + $issue['priority'] = array_rand($priorities); + $issue['assigned'] = $users[array_rand($users)]->uid; + $issue['sid'] = $statuses[array_rand($statuses)]; + $issue['name'] = $users[array_rand($users)]->name; + $issue['title'] = devel_create_greeking(rand(2, 15), true); + $issue['body'] = devel_create_content(); + + _drupalorg_testing_drupal_execute('project_issue_node_form', $issue, array('type' => 'project_issue')); + } +} + +function _drupalorg_testing_drupal_execute($form_id, $form_values) { + global $form_values; + $args = func_get_args(); + + $form_id = array_shift($args); + $form_values = array_shift($args); + array_unshift($args, $form_id); + + if (isset($form_values)) { + $form = call_user_func_array('drupal_retrieve_form', $args); + $form['#post'] = $form_values; + return _drupalorg_testing_drupal_process_form($form_id, $form); + } +} + +function _drupalorg_testing_drupal_process_form($form_id, &$form) { + global $form_values, $form_submitted, $user, $form_button_counter; + static $saved_globals = array(); + // In some scenarios, this function can be called recursively. Pushing any pre-existing + // $form_values and form submission data lets us start fresh without clobbering work done + // in earlier recursive calls. + array_push($saved_globals, array($form_values, $form_submitted, $form_button_counter)); + + $form_submitted = FALSE; + $form_button_counter = array(0, 0); + + drupal_prepare_form($form_id, $form); + if (($form['#programmed']) || (!empty($_POST) && (($_POST['form_id'] == $form_id)))) { + drupal_validate_form($form_id, $form); + // IE does not send a button value when there is only one submit button (and no non-submit buttons) + // and you submit by pressing enter. + // In that case we accept a submission without button values. + if ((($form['#programmed']) || $form_submitted || (!$form_button_counter[0] && $form_button_counter[1])) && !form_get_errors()) { + $redirect = drupal_submit_form($form_id, $form); + if (!$form['#programmed']) { + drupal_redirect_form($form, $redirect); + } + } + } + + // We've finished calling functions that alter the global values, so we can + // restore the ones that were there before this function was called. + list($form_values, $form_submitted, $form_button_counter) = array_pop($saved_globals); + return $redirect; +} + +/** * Setup menus to match drupal.org. */ function _drupalorg_testing_create_menus() {