/** * Test node creation by editor. * * 1. Editor creates Draft node * 2. Editor set status from Draft to Final Draft * 3. The node appears in the users's overview screen. */ public function testModerateToBeApproved() { $this->loginAs('editor1'); $node = $this->drupalCreateNode(array('language' => 'en', 'title' => $this->nodeTitle1, 'type' => 'news', 'workbench_access' => 1007)); workbench_moderation_moderate($node, 'final_draft'); $this->loginAs('review_manager1'); // Set node status To Be Reviewed. $options = array('title_field[en][0][value]' => $this->nodeTitle1, 'workbench_moderation_state_new' => 'needs_review'); $this->drupalPost("node/{$node->nid}/edit", $options, t('Save')); entity_get_controller('node')->resetCache(array($node->nid)); $node = node_load($node->nid); $this->assertEquals('needs_review', $node->workbench_moderation['current']->state); // Set the reviewer to project_manager1 $pm1 = user_load_by_name('project_manager1'); $options = array('project_manager' => $pm1->uid); $this->drupalPost("node/{$node->nid}/review", $options, t('Change')); $this->drupalGet("node/{$node->nid}/review"); $this->assertText('project_manager1'); // Define the list of approvers. // Cannot use drupalPost here. $ap1 = user_load_by_name('approver1'); $ap2 = user_load_by_name('approver2 '); $form_state = array('node' => $node, 'values' => array('rows' => array($ap1->uid => array('weight' => -10), $ap2->uid => array('weight' => -11)))); module_load_include('inc', 'osha_workflow', 'osha_workflow.admin'); drupal_form_submit('osha_workflow_node_approval_form', $form_state, $node); $this->drupalGet("node/{$node->nid}/approve"); $this->assertText($ap1->name); $this->assertText($ap2->name); $this->loginAs('project_manager1'); $options = array('workbench_moderation_state_new' => 'to_be_approved'); $this->drupalPost("node/{$node->nid}/edit", $options, t('Save')); entity_get_controller('node')->resetCache(array($node->nid)); $node = node_load($node->nid); $this->assertEquals('to_be_approved', $node->workbench_moderation['current']->state); }
/** * Configure the apachesolr and search_api_solr modules with proper settings. */ function osha_configure_solr() { $config_file = sprintf('%s/../conf/config.json', dirname(__FILE__)); if (!is_readable($config_file)) { drupal_set_message("Cannot read configuration file!", 'warning'); return; } $cfg = json_decode(file_get_contents($config_file), TRUE); if (empty($cfg)) { drupal_set_message('Configuration file was empty, nothing to do here', 'warning'); return; } $cfg = array_merge(array('name' => 'Solr server', 'enabled' => 1, 'description' => 'Search server', 'scheme' => 'http', 'host' => 'localhost', 'port' => '8983', 'path' => '/solr', 'http_user' => '', 'http_password' => '', 'excerpt' => NULL, 'retrieve_data' => NULL, 'highlight_data' => NULL, 'skip_schema_check' => NULL, 'solr_version' => '', 'http_method' => 'AUTO'), $cfg['solr_server']); if (module_exists('search_api_solr') && module_load_include('inc', 'search_api', 'search_api.admin')) { drupal_set_message('Configuring search_api_solr ...'); $form_state = array('values' => array('machine_name' => 'solr_server', 'class' => 'search_api_solr_service', 'name' => $cfg['name'], 'enabled' => $cfg['enabled'], 'description' => $cfg['description'], 'options' => array('form' => array('scheme' => $cfg['scheme'], 'host' => $cfg['host'], 'port' => $cfg['port'], 'path' => $cfg['path'], 'http' => array('http_user' => $cfg['http_user'], 'http_pass' => $cfg['http_pass']), 'advanced' => array('excerpt' => $cfg['excerpt'], 'retrieve_data' => $cfg['retrieve_data'], 'highlight_data' => $cfg['highlight_data'], 'skip_schema_check' => $cfg['skip_schema_check'], 'solr_version' => $cfg['solr_version'], 'http_method' => $cfg['http_method']))))); drupal_form_submit('search_api_admin_add_server', $form_state); } // Configure apachesolr: submit apachesolr_environment_edit_form if (module_exists('apachesolr') && module_load_include('inc', 'apachesolr', 'apachesolr.admin')) { drupal_set_message('Configuring apachesolr ...'); $url = sprintf('%s://%s:%s%s', $cfg['scheme'], $cfg['host'], $cfg['port'], $cfg['path']); $env_id = apachesolr_default_environment(); $environment = apachesolr_environment_load($env_id); $environment['url'] = $url; $environment['name'] = $cfg['name']; $environment['conf']['apachesolr_direct_commit'] = $cfg['apachesolr_direct_commit']; $environment['conf']['apachesolr_read_only'] = $cfg['apachesolr_read_only']; $environment['conf']['apachesolr_soft_commit'] = $cfg['apachesolr_soft_commit']; apachesolr_environment_save($environment); // @todo: See ticket #2527 - cannot make the form save new settings! // drupal_form_submit('apachesolr_environment_edit_form', $form_state, // $environment); } }
/** * Submit the system_config_form ensure the configuration has expected values. */ public function testConfigForm() { // Programmatically submit the given values. foreach ($this->values as $form_key => $data) { $values[$form_key] = $data['#value']; } $form_state = array('values' => $values); drupal_form_submit($this->form, $form_state); // Check that the form returns an error when expected, and vice versa. $errors = form_get_errors($form_state); $valid_form = empty($errors); $args = array('%values' => print_r($values, TRUE), '%errors' => $valid_form ? t('None') : implode(' ', $errors)); $this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args)); foreach ($this->values as $data) { $this->assertEqual($data['#value'], \Drupal::config($data['#config_name'])->get($data['#config_key'])); } }
/** * Run an individual installation task. * * @param $task * An array of information about the task to be run. * @param $install_state * An array of information about the current installation state. This is * passed in by reference so that it can be modified by the task. * @return * The output of the task function, if there is any. */ function install_run_task($task, &$install_state) { $function = $task['function']; if ($task['type'] == 'form') { require_once DRUPAL_ROOT . '/includes/form.inc'; if ($install_state['interactive']) { // For interactive forms, build the form and ensure that it will not // redirect, since the installer handles its own redirection only after // marking the form submission task complete. $form_state = array('args' => array(&$install_state), 'no_redirect' => TRUE); $form = drupal_build_form($function, $form_state); // If a successful form submission did not occur, the form needs to be // rendered, which means the task is not complete yet. if (empty($form_state['executed'])) { $install_state['task_not_complete'] = TRUE; return drupal_render($form); } // Otherwise, return nothing so the next task will run in the same // request. return; } else { // For non-interactive forms, submit the form programmatically with the // values taken from the installation state. Throw an exception if any // errors were encountered. $form_state = array('values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array()); drupal_form_submit($function, $form_state, $install_state); $errors = form_get_errors(); if (!empty($errors)) { throw new Exception(implode("\n", $errors)); } } } elseif ($task['type'] == 'batch') { // Start a new batch based on the task function, if one is not running // already. $current_batch = variable_get('install_current_batch'); if (!$install_state['interactive'] || !$current_batch) { $batch = $function($install_state); if (empty($batch)) { // If the task did some processing and decided no batch was necessary, // there is nothing more to do here. return; } batch_set($batch); // For interactive batches, we need to store the fact that this batch // task is currently running. Otherwise, we need to make sure the batch // will complete in one page request. if ($install_state['interactive']) { variable_set('install_current_batch', $function); } else { $batch =& batch_get(); $batch['progressive'] = FALSE; } // Process the batch. For progressive batches, this will redirect. // Otherwise, the batch will complete. batch_process(install_redirect_url($install_state), install_full_redirect_url($install_state)); } elseif ($current_batch == $function) { include_once DRUPAL_ROOT . '/includes/batch.inc'; $output = _batch_page(); // The task is complete when we try to access the batch page and receive // FALSE in return, since this means we are at a URL where we are no // longer requesting a batch ID. if ($output === FALSE) { // Return nothing so the next task will run in the same request. variable_del('install_current_batch'); return; } else { // We need to force the page request to end if the task is not // complete, since the batch API sometimes prints JSON output // rather than returning a themed page. $install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE; return $output; } } } else { // For normal tasks, just return the function result, whatever it is. return $function($install_state); } }
/** * Drupal get login example */ public function postPasswordReset() { //var_dump($_POST); $drupal = new \erdiko\drupal\Model(); // Load required include files for requesting user's password \module_load_include('inc', 'user', 'user.pages'); // Fill form_state. $form_state['values']['name'] = $_POST['name']; $form_state['values']['op'] = 'E-mail new password'; // Execute the register form. \drupal_form_submit('user_pass', $form_state); if ($errors = form_get_errors()) { // The supplied name is neither a username nor an email address. return service_error(implode(" ", $errors), 406, array('form_errors' => $errors)); } else { // Requesting new password has been successful. $this->setContent('Email sent'); } }
/** * Add press releases rss feed. */ function osha_add_agregator_rss_feeds() { if (module_exists('aggregator') && module_load_include('inc', 'aggregator', 'aggregator.admin')) { drupal_set_message('Add press releases rss feed ...'); $form_state = array('values' => array('title' => 'EU-OSHA in the media', 'url' => 'http://portal.kantarmedia.de/rss/index/1002043/100000063/1024803/9a7b629357e748080ff47e4d0db7ec57cffff3fe', 'refresh' => 900, 'block' => 2, 'op' => 'Save')); drupal_form_submit('aggregator_form_feed', $form_state); drupal_cron_run(); cache_clear_all(); } }
public function postRegister() { $user = new \erdiko\drupal\models\User(); if (\user_load_by_name($_POST['name'])) { echo "User exists!!"; } else { $account = user_save('', $_POST); } // Fill form_state. $form_state['values']['name'] = $_POST['name']; $form_state['values']['op'] = 'E-mail new password'; // Execute the register form. \drupal_form_submit('user_pass', $form_state); $content .= "<pre>" . print_r($_POST, true) . "</pre>"; $this->setContent($content); }
/** * Responsible for handling insert/update of question-specific data. * This is typically called from within the Node API, so there is no need * to save the node. * * The $is_new flag is set to TRUE whenever the node is being initially * created. * * A save function is required to handle the following three situations: * - A new node is created ($is_new is TRUE) * - A new node *revision* is created ($is_new is NOT set, because the * node itself is not new). * - An existing node revision is modified. * * @see hook_update and hook_insert in quiz_question.module * * @param $is_new * TRUE when the node is initially created. */ public function save($is_new = FALSE) { // We call the abstract function saveNodeProperties to save type specific data $this->saveNodeProperties($is_new); db_merge('quiz_question_properties')->key(array('nid' => $this->node->nid, 'vid' => $this->node->vid))->fields(array('nid' => $this->node->nid, 'vid' => $this->node->vid, 'max_score' => $this->getMaximumScore()))->execute(); // Save what quizzes this question belongs to. $quizzes_kept = $this->saveRelationships(); if ($quizzes_kept && $this->node->revision) { if (user_access('manual quiz revisioning') && !variable_get('quiz_auto_revisioning', 1)) { unset($_GET['destination']); unset($_REQUEST['edit']['destination']); drupal_goto('quiz_question/' . $this->node->nid . '/' . $this->node->vid . '/revision_actions'); } else { $form_state = array(); $form_state['values']['op'] = t('Submit'); require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'quiz_question') . '/quiz_question.pages.inc'; drupal_form_submit('quiz_question_revision_actions', $form_state, $this->node->nid, $this->node->vid); } } }