You are here

public function RulesInvocationEnabledTestCase::testInvocationOnNodeMenuLoading in Rules 7.2

Tests that a Rules event is triggered on node menu item loading.

See also

rules_test_invocation_node_load()

File

tests/rules.test, line 2244
Rules tests.

Class

RulesInvocationEnabledTestCase
Test early bootstrap Rules invocation.

Code

public function testInvocationOnNodeMenuLoading() {

  // Create a test node.
  $node = $this
    ->drupalCreateNode(array(
    'title' => 'Test',
  ));

  // Enable Rules logging on the INFO level so that entries are written to
  // dblog.
  variable_set('rules_log_errors', RulesLog::INFO);

  // Create an empty rule that will fire in our node load hook.
  $rule = rules_reaction_rule();
  $rule
    ->event('rules_test_event');
  $rule
    ->save('test_rule');

  // Visit the node page which should trigger the load hook.
  $this
    ->drupalGet('node/' . $node->nid);
  $result = db_query("SELECT * FROM {watchdog} WHERE type = 'rules' AND message = 'Reacting on event %label.'")
    ->fetch();
  $this
    ->assertFalse(empty($result), 'Rules event was triggered and logged.');
}