first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
name = "Rules Tests"
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 2012-10-23
version = "7.x-2.2+5-dev"
core = "7.x"
project = "rules"
datestamp = "1350998486"

View File

@@ -0,0 +1,54 @@
<?php
/**
* @file Rules test module.
*/
/**
* Implements hook_entity_property_info_alter() to add a property without
* access.
*/
function rules_test_entity_property_info_alter(&$info) {
$properties =& $info['site']['properties'];
$properties['no_access_user'] = array(
'label' => t("Logged in user"),
'description' => t("The currently logged in user."),
'getter callback' => 'entity_metadata_system_get_properties',
'access callback' => 'rules_test_no_access',
'type' => 'user',
);
$properties =& $info['node']['properties'];
$properties['reference'] = array(
'label' => t("Referenced entity"),
'getter callback' => 'rules_test_get_referenced_entity',
'type' => 'entity',
);
$properties['ref_nodes'] = array(
'label' => t("Referenced nodes"),
'getter callback' => 'rules_test_get_referenced_node',
'type' => 'list<node>',
);
}
/**
* Getter callback to get the referenced-entity property.
*/
function rules_test_get_referenced_entity($node) {
// For testing purposes we just return the node itself as property value.
return entity_metadata_wrapper('node', $node);
}
/**
* Getter callback to get the referenced-node list-property.
*/
function rules_test_get_referenced_node($node) {
// For testing purposes we just return the node itself as property value.
return array($node->nid);
}
function rules_test_no_access($op) {
return $op == 'edit' ? FALSE : TRUE;
}

View File

@@ -0,0 +1,244 @@
<?php
/**
* @file Includes any rules integration provided by the module.
*/
/**
* Implements hook_rules_file_info().
*/
function rules_test_rules_file_info() {
return array('rules_test.test');
}
/**
* Implements hook_rules_condition_info().
*/
function rules_test_rules_condition_info() {
$items = array();
$defaults = array(
'parameter' => array(
'node' => array('type' => 'node', 'label' => t('Content')),
),
'group' => t('Node'),
);
$items['rules_condition_content_is_type'] = array(
'label' => t('Content has type'),
'parameter' => array(
'node' => array('type' => 'node', 'label' => t('Content')),
'type' => array('type' => 'list<text>', 'label' => t('Content types')),
),
'help' => t('Evaluates to TRUE, if the given content has one of the selected content types.'),
) + $defaults;
$items['rules_condition_content_is_published'] = $defaults + array(
'label' => t('Content is published'),
);
$items['rules_test_condition_true'] = array(
'label' => t('Test condition returning true'),
'group' => t('Rules test'),
);
$items['rules_test_condition_false'] = array(
'label' => t('Test condition returning false'),
'group' => t('Rules test'),
);
// A condition for testing passing entities wrapped.
$items['rules_test_condition_node_wrapped'] = array(
'label' => t('Content is published'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Content'),
'wrapped' => TRUE,
),
),
'group' => t('Node'),
);
return $items;
}
/**
* Condition implementation returning true.
*/
function rules_test_condition_true($settings, $state, $element) {
if (!$element instanceof RulesCondition) {
throw new Exception('Rules element has not been passed to condition.');
}
rules_log('condition true called');
return TRUE;
}
/**
* Condition implementation returning false.
*/
function rules_test_condition_false() {
rules_log('condition false called');
return FALSE;
}
/**
* Condition implementation receiving the node wrapped.
*/
function rules_test_condition_node_wrapped($wrapper) {
return $wrapper instanceof EntityMetadataWrapper;
}
/**
* Implements hook_rules_action_info().
*/
function rules_test_rules_action_info() {
$items['rules_test_action'] = array(
'label' => t('Test action'),
'group' => t('Rules test'),
);
return $items + array(
'rules_node_publish_action' => array(
'label' => t('Publish content, but do not save'),
'parameter' => array(
'node' => array('type' => 'node', 'label' => t('Content')),
),
'callbacks' => array(
'help' => 'rules_test_custom_help',
),
'base' => 'node_publish_action',
),
'rules_node_publish_action_save' => array(
'label' => t('Publish content'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Content'),
'save' => TRUE,
),
),
'base' => 'node_publish_action',
),
'rules_node_make_sticky_action' => array(
'label' => t('Make content sticky'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Content'),
'save' => TRUE,
),
),
'base' => 'node_make_sticky_action',
),
// The same action again requiring a 'page' node.
'rules_node_page_make_sticky_action' => array(
'label' => t('Mage page content sticky'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Content'),
'save' => TRUE,
'bundles' => array('page'),
),
),
'base' => 'node_make_sticky_action',
),
'rules_action_test_reference' => array(
'label' => t('Change argument passed by reference'),
'parameter' => array(
// For references working right, we need a data type with a wrapper.
'arg' => array('type' => 'test'),
),
),
'rules_action_load_node' => array(
'label' => t('Fetch content by id'),
'parameter' => array(
'nid' => array('type' => 'integer', 'label' => t('Content ID')),
'vid' => array(
'type' => 'integer',
'label' => t('Content Revision ID'),
'description' => t("If you want to fetch a specific revision, specify it's revision id. Else leave it empty to fetch the currently active revision."),
'optional' => TRUE,
),
),
'provides' => array(
'node_loaded' => array(
'type' => 'node',
'label' => t('Loaded content'),
'label callback' => 'rules_action_load_node_variable_label',
),
),
'group' => t('Node'),
'access callback' => 'rules_node_integration_access',
),
'rules_action_delete_node' => array(
'label' => t('Delete content'),
'parameter' => array(
'node' => array('type' => 'node', 'label' => t('Content')),
),
'group' => t('Node'),
'access callback' => 'rules_node_integration_access',
),
// An action for testing named parameters.
'rules_action_node_set_title' => array(
'label' => t('Content'),
'parameter' => array(
'node' => array('type' => 'node', 'label' => t('Content')),
'title' => array('type' => 'text', 'label' => t('Text')),
),
'named parameter' => TRUE,
'group' => t('Node'),
'access callback' => 'rules_node_integration_access',
),
// Tests automatic saving with a non-entity data type.
'test_type_save' => array(
'base' => 'rules_test_type_save',
'label' => t('Save test type'),
'parameter' => array(
'node' => array('type' => 'rules_test_type', 'label' => t('Test content'), 'save' => TRUE),
),
'group' => t('Node'),
),
);
}
/**
* Test action doing nothing exception logging it has been called.
*/
function rules_test_action() {
rules_log('action called');
}
/**
* Implements hook_rules_data_info().
*/
function rules_test_rules_data_info() {
return array(
'rules_test_type' => array(
'label' => t('test type'),
'wrap' => TRUE,
'wrapper class' => 'RulesTestTypeWrapper',
),
);
}
/**
* Implements hook_rules_data_info_alter().
*/
function rules_test_rules_data_info_alter(&$data_info) {
$data_info['log_entry']['creation callback'] = 'rules_action_data_create_array';
}
/**
* The custom wrapper class for the rules test type.
*
* For testing we internally just make use of nodes.
*/
class RulesTestTypeWrapper extends RulesIdentifiableDataWrapper implements RulesDataWrapperSavableInterface {
protected function extractIdentifier($data) {
return $data->nid;
}
protected function load($id) {
return node_load($id);
}
public function save() {
node_save($this->value());
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* @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';
$rule->active = FALSE;
$rule->event('node_update')
->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate())
->condition('data_is', array('data:select' => 'node:type', 'value' => 'page'))
->action('drupal_message', array('message' => 'A node has been updated.'));
$configs['rules_test_default_1'] = $rule;
$action_set = rules_action_set(array('node' => array('type' => 'node', 'label' => 'Content')));
$action_set->action('node_publish');
$configs['rules_test_action_set'] = $action_set;
// Test providing a rule using an export.
$configs['rules_export_test'] = rules_import(_rules_export_get_test_export());
// An action set used to test merging term parents.
$configs['rules_retrieve_term_parents'] = rules_import('{ "rules_retrieve_term_parents" : {
"LABEL" : "Retrieve term parents",
"PLUGIN" : "action set",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
"terms" : { "label" : "Terms", "type" : "list\u003ctaxonomy_term\u003e" },
"term_parents" : {
"label" : "Term parents",
"type" : "list\u003ctaxonomy_term\u003e",
"parameter" : false
}
},
"ACTION SET" : [
{ "LOOP" : {
"USING" : { "list" : [ "terms" ] },
"ITEM" : { "current_term" : "Current term" },
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "current-term:parent" ] },
"ITEM" : { "current_parent" : "Current parent" },
"DO" : [
{ "list_add" : {
"list" : [ "term-parents" ],
"item" : [ "current-parent" ],
"unique" : 1
}
}
]
}
}
]
}
}
],
"PROVIDES VARIABLES" : [ "term_parents" ]
}
}');
return $configs;
}
/**
* Defines the export of rule for testing import/export.
*/
function _rules_export_get_test_export() {
return '{ "rules_export_test" : {
"LABEL" : "Test import rule2",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-1",
"ACTIVE" : false,
"TAGS" : [ "bar", "baz", "foo" ],
"REQUIRES" : [ "rules", "comment" ],
"ON" : [ "comment_insert" ],
"IF" : [
{ "OR" : [
{ "NOT node_is_sticky" : { "node" : [ "comment:node" ] } },
{ "node_is_of_type" : {
"node" : [ "comment:node" ],
"type" : { "value" : { "page" : "page" } }
}
},
{ "NOT AND" : [ { "OR" : [] } ] }
]
}
],
"DO" : [
{ "data_set" : {
"data" : [ "comment:node:created" ],
"value" : { "select" : "site:current-date", "date_offset" : { "value" : -604800 } }
}
},
{ "node_make_sticky" : { "node" : [ "comment:node" ] } },
{ "variable_add" : {
"USING" : { "type" : "token", "value" : "error" },
"PROVIDE" : { "variable_added" : { "level" : "Error level" } }
}
},
{ "drupal_message" : {
"message" : "fein, [comment:node:title] has been made sticky!",
"type" : [ "level" ]
}
},
{ "LOOP" : {
"USING" : { "list" : [ "site:current-user:roles" ] },
"ITEM" : { "current_role" : "Current role" },
"DO" : [ { "drupal_message" : { "message" : [ "current-role" ] } } ]
}
}
]
}
}';
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* @file Include file for testing file inclusion.
*/
/**
* Extender for the node data type.
*/
function rules_test_custom_node_save($object) {
throw new RulesEvaluationException('Custom save method invoked.');
}
/**
* Custom help callback for the rules_node_publish_action
*/
function rules_test_custom_help() {
return 'custom';
}
/**
* Action callback
*/
function rules_action_test_reference($data) {
$data['changed'] = TRUE;
return array('arg' => $data);
}
/**
* 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
*/
function rules_condition_content_is_published($node, $settings) {
return $node->status == 1;
}
/**
* Loads a node
*/
function rules_action_load_node($nid, $vid = NULL) {
return array('node_loaded' => node_load($nid, $vid ? $vid : NULL));
}
/**
* Action "Delete a node".
*/
function rules_action_delete_node($node) {
node_delete($node->nid);
}
/**
* An action making use of named parameters.
*/
function rules_action_node_set_title($arguments) {
// Make sure the data is unwrapped.
if ($arguments['node'] instanceof EntityMetadataWrapper) {
throw new Exception('Argument has not been correctly unwrapped.');
}
$arguments['node']->title = $arguments['title'];
return $arguments;
}
/**
* Action: Test saving - nothing to do here.
*/
function rules_test_type_save($node) {
}