Projet

Général

Profil

Paste
Télécharger (3,73 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / tests / rules_test.rules_defaults.inc @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Includes any Rules integration provided by the module.
6
 */
7

    
8
/**
9
 * Implements hook_default_rules_configuration().
10
 */
11
function rules_test_default_rules_configuration() {
12
  $rule = rules_reaction_rule();
13
  $rule->label = 'example default rule';
14
  // Add rules tags.
15
  $rule->tags = array('Admin', 'Tag2');
16
  $rule->active = FALSE;
17
  $rule->event('node_update')
18
       ->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate())
19
       ->condition('data_is', array('data:select' => 'node:type', 'value' => 'page'))
20
       ->action('drupal_message', array('message' => 'A node has been updated.'));
21

    
22
  $configs['rules_test_default_1'] = $rule;
23

    
24
  $action_set = rules_action_set(array('node' => array('type' => 'node', 'label' => 'Content')));
25
  $action_set->action('node_publish');
26
  $configs['rules_test_action_set'] = $action_set;
27

    
28
  // Test providing a rule using an export.
29
  $configs['rules_export_test'] = rules_import(_rules_export_get_test_export());
30

    
31
  // An action set used to test merging term parents.
32
  $configs['rules_retrieve_term_parents'] = rules_import('{ "rules_retrieve_term_parents" : {
33
    "LABEL" : "Retrieve term parents",
34
    "PLUGIN" : "action set",
35
    "REQUIRES" : [ "rules" ],
36
    "USES VARIABLES" : {
37
      "terms" : { "label" : "Terms", "type" : "list\u003ctaxonomy_term\u003e" },
38
      "term_parents" : {
39
        "label" : "Term parents",
40
        "type" : "list\u003ctaxonomy_term\u003e",
41
        "parameter" : false
42
      }
43
    },
44
    "ACTION SET" : [
45
      { "LOOP" : {
46
          "USING" : { "list" : [ "terms" ] },
47
          "ITEM" : { "current_term" : "Current term" },
48
          "DO" : [
49
            { "LOOP" : {
50
                "USING" : { "list" : [ "current-term:parent" ] },
51
                "ITEM" : { "current_parent" : "Current parent" },
52
                "DO" : [
53
                  { "list_add" : {
54
                      "list" : [ "term-parents" ],
55
                      "item" : [ "current-parent" ],
56
                      "unique" : 1
57
                    }
58
                  }
59
                ]
60
              }
61
            }
62
          ]
63
        }
64
      }
65
    ],
66
    "PROVIDES VARIABLES" : [ "term_parents" ]
67
  }
68
}');
69

    
70
  return $configs;
71
}
72

    
73
/**
74
 * Defines the export of rule for testing import/export.
75
 */
76
function _rules_export_get_test_export() {
77
  return '{ "rules_export_test" : {
78
    "LABEL" : "Test import rule2",
79
    "PLUGIN" : "reaction rule",
80
    "WEIGHT" : "-1",
81
    "ACTIVE" : false,
82
    "OWNER" : "rules",
83
    "TAGS" : [ "bar", "baz", "foo" ],
84
    "REQUIRES" : [ "rules", "comment" ],
85
    "ON" : { "comment_insert" : [] },
86
    "IF" : [
87
      { "OR" : [
88
          { "NOT node_is_sticky" : { "node" : [ "comment:node" ] } },
89
          { "node_is_of_type" : {
90
              "node" : [ "comment:node" ],
91
              "type" : { "value" : { "page" : "page" } }
92
            }
93
          },
94
          { "NOT AND" : [ { "OR" : [] } ] }
95
        ]
96
      }
97
    ],
98
    "DO" : [
99
      { "data_set" : {
100
          "data" : [ "comment:node:created" ],
101
          "value" : { "select" : "site:current-date", "date_offset" : { "value" : -604800 } }
102
        }
103
      },
104
      { "node_make_sticky" : { "node" : [ "comment:node" ] } },
105
      { "variable_add" : {
106
          "USING" : { "type" : "token", "value" : "error" },
107
          "PROVIDE" : { "variable_added" : { "level" : "Error level" } }
108
        }
109
      },
110
      { "drupal_message" : {
111
          "message" : "fein, [comment:node:title] has been made sticky!",
112
          "type" : [ "level" ]
113
        }
114
      },
115
      { "LOOP" : {
116
          "USING" : { "list" : [ "site:current-user:roles" ] },
117
          "ITEM" : { "current_role" : "Current role" },
118
          "DO" : [ { "drupal_message" : { "message" : [ "current-role" ] } } ]
119
        }
120
      }
121
    ]
122
  }
123
}';
124
}