You are here

public function RulesEventDispatcherTestCase::testStartAndStopMultiple in Rules 7.2

Same name and namespace in other branches
  1. 8.3 d7-tests/rules_test_event_dispatcher_case.test \RulesEventDispatcherTestCase::testStartAndStopMultiple()

Tests start and stop functionality when used with multiple events.

File

tests/rules.test, line 2189
Rules tests.

Class

RulesEventDispatcherTestCase
Tests event dispatcher functionality.

Code

public function testStartAndStopMultiple() {
  $handler = rules_get_event_handler('rules_test_event');

  // Initially, the task handler should not be watching.
  $this
    ->assertFalse($handler
    ->isWatching());

  // Set up five rules that all use the same event.
  $rules = array();
  foreach (array(
    1,
    2,
    3,
    4,
    5,
  ) as $key) {
    $rules[$key] = rules_reaction_rule();
    $rules[$key]
      ->event('rules_test_event');
    $rules[$key]
      ->save();
  }

  // Once saved, the event cache rebuild should start the watcher.
  RulesEventSet::rebuildEventCache();
  $this
    ->assertTrue($handler
    ->isWatching());

  // It should continue watching until all events are deleted.
  foreach ($rules as $key => $rule) {
    $rule
      ->delete();
    $this
      ->assertEqual($key !== 5, $handler
      ->isWatching());
  }
}