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

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +3,10 @@ description = "Support module for the Rules tests."
package = Testing
core = 7.x
files[] = rules_test.rules.inc
files[] = rules_test.rules_defaults.inc
hidden = TRUE
; Information added by drupal.org packaging script on 2013-03-27
version = "7.x-2.3"
; 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 test module.
* @file
* Rules test module.
*/
/**
@@ -49,6 +50,9 @@ function rules_test_get_referenced_node($node) {
return array($node->nid);
}
/**
* Access callback. Returns TRUE except when $op == 'edit'.
*/
function rules_test_no_access($op) {
return $op == 'edit' ? FALSE : TRUE;
}

View File

@@ -1,9 +1,21 @@
<?php
/**
* @file Includes any rules integration provided by the module.
* @file
* Includes any rules integration provided by the module.
*/
/**
* Implements hook_rules_event_info().
*/
function rules_test_rules_event_info() {
return array(
'rules_test_event' => array(
'label' => t('Test event'),
'class' => 'RulesTestEventHandler',
),
);
}
/**
* Implements hook_rules_file_info().
@@ -42,6 +54,10 @@ function rules_test_rules_condition_info() {
'label' => t('Test condition returning false'),
'group' => t('Rules test'),
);
$items['rules_test_condition_apostrophe'] = array(
'label' => t("Test use of an apostrophe (') in a condition label"),
'group' => t('Rules test'),
);
// A condition for testing passing entities wrapped.
$items['rules_test_condition_node_wrapped'] = array(
'label' => t('Content is published'),
@@ -76,6 +92,20 @@ function rules_test_condition_false() {
return FALSE;
}
/**
* Condition testing use of an apostrophe in a condition label.
*
* Specifically, we want to ensure that special characters do not show up as
* HTML-encoded in the user interface.
*/
function rules_test_condition_apostrophe($settings, $state, $element) {
if (!$element instanceof RulesCondition) {
throw new Exception('Rules element has not been passed to condition.');
}
rules_log('condition apostrophe called');
return TRUE;
}
/**
* Condition implementation receiving the node wrapped.
*/
@@ -189,7 +219,11 @@ function rules_test_rules_action_info() {
'base' => 'rules_test_type_save',
'label' => t('Save test type'),
'parameter' => array(
'node' => array('type' => 'rules_test_type', 'label' => t('Test content'), 'save' => TRUE),
'node' => array(
'type' => 'rules_test_type',
'label' => t('Test content'),
'save' => TRUE,
),
),
'group' => t('Node'),
),
@@ -203,6 +237,37 @@ function rules_test_action() {
rules_log('action called');
}
/**
* Action for testing writing class-based actions.
*/
class RulesTestClassAction extends RulesActionHandlerBase {
/**
* Defines the action.
*/
public static function getInfo() {
return array(
'name' => 'rules_test_class_action',
'label' => t('Test class based action'),
'group' => t('Node'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Node'),
),
),
);
}
/**
* Executes the action.
*/
public function execute($node) {
rules_log('Action called with node ' . $node->nid);
}
}
/**
* Implements hook_rules_data_info().
*/
@@ -230,15 +295,88 @@ function rules_test_rules_data_info_alter(&$data_info) {
*/
class RulesTestTypeWrapper extends RulesIdentifiableDataWrapper implements RulesDataWrapperSavableInterface {
/**
* Overrides RulesIdentifiableDataWrapper::extractIdentifier().
*/
protected function extractIdentifier($data) {
return $data->nid;
}
/**
* Overrides RulesIdentifiableDataWrapper::load().
*/
protected function load($id) {
return node_load($id);
}
/**
* Implements RulesDataWrapperSavableInterface::save().
*/
public function save() {
node_save($this->value());
}
}
/**
* Implements hook_rules_plugin_info().
*/
function rules_test_rules_plugin_info() {
return array(
'rules test container' => array(
'label' => t('Test container'),
'class' => 'RulesTestContainer',
'embeddable' => 'RulesActionContainer',
),
);
}
/**
* Test container plugin.
*/
class RulesTestContainer extends RulesContainerPlugin {
protected $itemName = 'rules test container';
/**
* Evaluate the element on a given rules evaluation state.
*/
public function evaluate(RulesState $state) {
// Do nothing.
}
}
/**
* Test event handler class.
*/
class RulesTestEventHandler extends RulesEventDefaultHandler implements RulesEventDispatcherInterface {
/**
* Name of the variable in which to store the state of the event handler.
*
* @var string
*/
protected $variableName = 'rules_test_event_handler_watch';
/**
* Implements RulesEventDispatcherInterface::startWatching().
*/
public function startWatching() {
variable_set($this->variableName, TRUE);
}
/**
* Implements RulesEventDispatcherInterface::stopWatching().
*/
public function stopWatching() {
variable_set($this->variableName, FALSE);
}
/**
* Implements RulesEventDispatcherInterface::isWatching().
*/
public function isWatching() {
return (bool) variable_get($this->variableName);
}
}

View File

@@ -1,16 +1,18 @@
<?php
/**
* @file Includes any rules integration provided by the module.
* @file
* Includes any Rules integration provided by the module.
*/
/**
* Implements hook_default_rules_configuration().
*/
function rules_test_default_rules_configuration() {
$rule = rules_reaction_rule();
$rule->label = 'example default rule';
// Add rules tags.
$rule->tags = array('Admin', 'Tag2');
$rule->active = FALSE;
$rule->event('node_update')
->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate())
@@ -77,9 +79,10 @@ function _rules_export_get_test_export() {
"PLUGIN" : "reaction rule",
"WEIGHT" : "-1",
"ACTIVE" : false,
"OWNER" : "rules",
"TAGS" : [ "bar", "baz", "foo" ],
"REQUIRES" : [ "rules", "comment" ],
"ON" : [ "comment_insert" ],
"ON" : { "comment_insert" : [] },
"IF" : [
{ "OR" : [
{ "NOT node_is_sticky" : { "node" : [ "comment:node" ] } },

View File

@@ -1,7 +1,8 @@
<?php
/**
* @file Include file for testing file inclusion.
* @file
* Include file for testing file inclusion.
*/
/**
@@ -11,16 +12,15 @@ function rules_test_custom_node_save($object) {
throw new RulesEvaluationException('Custom save method invoked.');
}
/**
* Custom help callback for the rules_node_publish_action
* Custom help callback for the rules_node_publish_action().
*/
function rules_test_custom_help() {
return 'custom';
}
/**
* Action callback
* Action callback.
*/
function rules_action_test_reference($data) {
$data['changed'] = TRUE;
@@ -28,21 +28,21 @@ function rules_action_test_reference($data) {
}
/**
* Condition: Check for selected content types
* Condition: Check for selected content types.
*/
function rules_condition_content_is_type($node, $type) {
return in_array($node->type, $type);
}
/**
* Condition: Check if the node is published
* Condition: Check if the node is published.
*/
function rules_condition_content_is_published($node, $settings) {
return $node->status == 1;
}
/**
* Loads a node
* Loads a node.
*/
function rules_action_load_node($nid, $vid = NULL) {
return array('node_loaded' => node_load($nid, $vid ? $vid : NULL));

View File

@@ -0,0 +1,11 @@
name = "Rules Test invocation"
description = "Helper module to test Rules invocations."
package = Testing
core = 7.x
hidden = TRUE
; Information added by Drupal.org packaging script on 2019-01-24
version = "7.x-2.12"
core = "7.x"
project = "rules"
datestamp = "1548305586"

View File

@@ -0,0 +1,13 @@
<?php
/**
* @file
* Helper module for Rules invocation testing.
*/
/**
* Implements hook_node_load().
*/
function rules_test_invocation_node_load($nodes, $types) {
rules_invoke_event('rules_test_event');
}