You are here

public function RulesTriggerTestCase::testReactiveRuleCreation in Rules 7.2

Same name and namespace in other branches
  1. 8.3 d7-tests/rules_test_trigger_case.test \RulesTriggerTestCase::testReactiveRuleCreation()

Tests CRUD for reaction rules - making sure the events are stored properly.

File

tests/rules.test, line 1149
Rules tests.

Class

RulesTriggerTestCase
Test triggering rules.

Code

public function testReactiveRuleCreation() {
  $rule = $this
    ->createTestRule();
  $rule
    ->save();
  $result = db_query("SELECT event FROM {rules_trigger} WHERE id = :id", array(
    ':id' => $rule->id,
  ));
  $this
    ->assertEqual($result
    ->fetchField(), 'node_presave', 'Associated event has been saved.');

  // Try updating.
  $rule
    ->removeEvent('node_presave');
  $rule
    ->event('node_insert');
  $rule
    ->event('node_update');
  $rule->active = FALSE;
  $rule
    ->integrityCheck()
    ->save();
  $result = db_query("SELECT event FROM {rules_trigger} WHERE id = :id", array(
    ':id' => $rule->id,
  ));
  $this
    ->assertEqual($result
    ->fetchCol(), array_values($rule
    ->events()), 'Updated associated events.');

  // Try deleting.
  $rule
    ->delete();
  $result = db_query("SELECT event FROM {rules_trigger} WHERE id = :id", array(
    ':id' => $rule->id,
  ));
  $this
    ->assertEqual($result
    ->fetchField(), FALSE, 'Deleted associated events.');
}