updated rules

This commit is contained in:
2021-07-12 09:49:00 +02:00
parent 7b1e954f7f
commit fd5d68d5e9
75 changed files with 5254 additions and 1335 deletions

View File

@@ -1,8 +1,8 @@
<?php
/**
* @file Rules Admin UI
* Implements rule management and configuration screens.
* @file
* Implements rule management and configuration screens.
*/
/**
@@ -26,11 +26,12 @@ function rules_admin_reaction_overview($form, &$form_state, $base_path) {
}
else {
$event = $_GET['event'];
$conditions['event'] = $event;
// Filter using a wildcard suffix so configured event names with suffixes
// are found also.
$conditions['event'] = $event . '%';
$collapsed = FALSE;
}
$form['help'] = array(
'#type' => 'markup',
'#markup' => t('Reaction rules, listed below, react on selected events on the site. Each reaction rule may fire any number of <em>actions</em>, and may have any number of <em>conditions</em> that must be met for the actions to be executed. You can also set up <a href="@url1">components</a> stand-alone sets of Rules configuration that can be used in Rules and other parts of your site. See <a href="@url2">the online documentation</a> for an introduction on how to use Rules.',
array('@url1' => url('admin/config/workflow/rules/components'),
'@url2' => rules_external_help('rules'))),
@@ -103,7 +104,6 @@ function rules_admin_components_overview($form, &$form_state, $base_path) {
$collapsed = FALSE;
}
$form['help'] = array(
'#type' => 'markup',
'#markup' => t('Components are stand-alone sets of Rules configuration that can be used by Rules and other modules on your site. Components are for example useful if you want to use the same conditions, actions or rules in multiple places, or call them from your custom module. You may also export each component separately. See <a href="@url">the online documentation</a> for more information about how to use components.',
array('@url' => rules_external_help('components'))),
);
@@ -160,7 +160,7 @@ function rules_admin_settings($form, &$form_state) {
$pathauto_help = t("Note that Pathauto's URL path cleaning method can be configured at <a href='!url'>admin/config/search/path/settings</a>.", array('!url' => url('admin/config/search/path/settings')));
}
else {
$pathauto_help = t('Install the <a href="http://drupal.org/project/pathauto">Pathauto module</a> in order to get a configurable URL path cleaning method.');
$pathauto_help = t('Install the <a href="https://www.drupal.org/project/pathauto">Pathauto module</a> in order to get a configurable URL path cleaning method.');
}
$form['path']['rules_path_cleaning_callback'] = array(
@@ -190,7 +190,7 @@ function rules_admin_settings($form, &$form_state) {
$form['debug']['rules_debug_log'] = array(
'#type' => 'checkbox',
'#title' => t('Log debug information to the system log'),
'#default_value' => variable_get('rules_debug_log', 0),
'#default_value' => variable_get('rules_debug_log', FALSE),
);
$form['debug']['rules_debug'] = array(
'#type' => 'radios',
@@ -209,7 +209,7 @@ function rules_admin_settings($form, &$form_state) {
'#states' => array(
// Hide the regions settings when the debug log is disabled.
'invisible' => array(
'input[name="rules_debug"]' => array('value' => '0'),
'input[name="rules_debug"]' => array('value' => 0),
),
),
);
@@ -279,7 +279,7 @@ function rules_admin_settings_integrity_check_submit($form, &$form_state) {
rules_config_update_dirty_flag($rules_config, TRUE, TRUE);
if ($rules_config->dirty) {
$count++;
$variables = array('%label' => $rules_config->label(), '%name' => $rules_config->name, '@plugin' => $rules_config->plugin(), '!uri'=> url(RulesPluginUI::path($rules_config->name)));
$variables = array('%label' => $rules_config->label(), '%name' => $rules_config->name, '@plugin' => $rules_config->plugin(), '!uri' => url(RulesPluginUI::path($rules_config->name)));
drupal_set_message(t('The @plugin <a href="!uri">%label (%name)</a> fails the integrity check and cannot be executed.', $variables), 'error');
}
@@ -312,7 +312,7 @@ function rules_admin_settings_cache_rebuild_submit($form, &$form_state) {
function rules_admin_add_reaction_rule($form, &$form_state, $base_path) {
RulesPluginUI::formDefaults($form, $form_state);
$rules_config = rules_reaction_rule();
$rules_config = isset($form_state['rules_config']) ? $form_state['rules_config'] : rules_reaction_rule();
$rules_config->form($form, $form_state, array('show settings' => TRUE, 'button' => TRUE));
$form['settings']['#collapsible'] = FALSE;
@@ -329,18 +329,34 @@ function rules_admin_add_reaction_rule($form, &$form_state, $base_path) {
// Incorporate the form to add the first event.
$form['settings'] += rules_ui_add_event(array(), $form_state, $rules_config, $base_path);
$form['settings']['event']['#tree'] = FALSE;
$form['settings']['event_settings']['#tree'] = FALSE;
unset($form['settings']['help']);
unset($form['settings']['submit']);
$form['submit']['#value'] = t('Save');
$form_state += array('rules_config' => $rules_config);
$form['#validate'][] = 'rules_ui_add_reaction_rule_validate';
$form['#validate'][] = 'rules_ui_edit_element_validate';
$form['#submit'][] = 'rules_ui_add_event_apply';
$form['#submit'][] = 'rules_ui_edit_element_submit';
$form['#submit'][] = 'rules_ui_add_reaction_rule_submit';
return $form;
}
/**
* Form validation callback.
*/
function rules_ui_add_reaction_rule_validate(&$form, &$form_state) {
rules_ui_add_event_validate($form['settings'], $form_state);
}
/**
* Form submit callback.
*/
function rules_ui_add_reaction_rule_submit(&$form, &$form_state) {
rules_ui_add_event_apply($form['settings'], $form_state);
rules_ui_edit_element_submit($form, $form_state);
}
/**
* Add component form.
*/

View File

@@ -2,13 +2,14 @@ name = Rules UI
description = Administrative interface for managing rules.
package = Rules
core = 7.x
files[] = rules_admin.module
files[] = rules_admin.inc
dependencies[] = rules
configure = admin/config/workflow/rules
; Information added by drupal.org packaging script on 2013-03-27
version = "7.x-2.3"
; Test cases
files[] = tests/rules_admin.test
; Information added by Drupal.org packaging script on 2019-01-24
version = "7.x-2.12"
core = "7.x"
project = "rules"
datestamp = "1364401818"
datestamp = "1548305586"

View File

@@ -1,7 +1,8 @@
<?php
/**
* @file Rules Admin UI
* @file
* Rules Admin User Interface.
*/
/**

View File

@@ -0,0 +1,126 @@
<?php
/**
* @file
* Rules UI tests.
*/
/**
* Tests for creating rules through the UI.
*/
class RulesUiTestCase extends DrupalWebTestCase {
/**
* Declares test metadata.
*/
public static function getInfo() {
return array(
'name' => 'Rules UI Tests ',
'description' => 'Tests Rules UI.',
'group' => 'Rules',
);
}
/**
* Overrides DrupalWebTestCase::setUp().
*/
protected function setUp() {
parent::setUp('rules', 'rules_admin', 'rules_test');
RulesLog::logger()->clear();
variable_set('rules_debug_log', TRUE);
}
/**
* Tests that NOT condition labels are not HTML-encoded in the UI.
*
* @see https://www.drupal.org/project/rules/issues/1945006
*/
public function testConditionLabel() {
// Create a simple user account with permission to create a rule.
$user = $this->drupalCreateUser(array('access administration pages', 'administer rules'));
$this->drupalLogin($user);
// First we need an event.
$this->drupalGet('admin/config/workflow/rules/reaction/add');
$edit = array(
'settings[label]' => 'Test node event',
'settings[name]' => 'test_node_event',
'event' => 'node_insert',
);
$this->drupalPost(NULL, $edit, 'Save');
$this->assertText('Editing reaction rule', 'Rule edit page is shown.');
// Now add a condition with a special character in the label.
$this->clickLink('Add condition');
$this->assertText('Add a new condition', 'Condition edit page is shown.');
$edit = array(
'element_name' => 'rules_test_condition_apostrophe',
);
$this->drupalPost(NULL, $edit, 'Continue');
// Negate the condition, as this is how it gets improperly HTML encoded.
$edit = array(
'negate' => TRUE,
);
$this->drupalPost(NULL, $edit, 'Save');
$this->assertNoRaw("&amp;#039;", 'Apostrophe is not HTML-encoded.');
}
}
/**
* UI test cases for the minimal profile.
*
* The minimal profile is useful for testing because it has fewer dependencies
* so the tests run faster. Also, removing the profile-specific configuration
* reveals assumptions in the code. For example, the minimal profile doesn't
* define any content types, so when Rules expects to have content types to
* operate on that assumpation may cause errors.
*/
class RulesMinimalProfileTestCase extends DrupalWebTestCase {
protected $profile = 'minimal';
/**
* Declares test metadata.
*/
public static function getInfo() {
return array(
'name' => 'Rules UI Minimal Profile Tests ',
'description' => 'Tests UI support for minimal profile.',
'group' => 'Rules',
);
}
/**
* Overrides DrupalWebTestCase::setUp().
*/
protected function setUp() {
parent::setUp('rules', 'rules_admin');
RulesLog::logger()->clear();
variable_set('rules_debug_log', TRUE);
}
/**
* Tests node event UI without content types.
*
* @see https://www.drupal.org/project/rules/issues/2267341
*/
public function testNodeEventUi() {
// Create a simple user account with permission to create a rule.
$user = $this->drupalCreateUser(array('access administration pages', 'administer rules'));
$this->drupalLogin($user);
$this->drupalGet('admin/config/workflow/rules/reaction/add');
$edit = array(
'settings[label]' => 'Test node event',
'settings[name]' => 'test_node_event',
'event' => 'node_insert',
);
$this->drupalPostAJAX(NULL, $edit, 'event');
$this->assertText('Restrict by type', 'Restrict by type selection is visible.');
$this->drupalPost(NULL, $edit, 'Save');
$this->assertText('Editing reaction rule', 'Rule edit page is shown.');
}
}