You are here

public function RulesTriggerTestCase::testEventSettings in Rules 7.2

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

Tests creating and triggering a reaction rule with event settings.

File

tests/rules.test, line 1344
Rules tests.

Class

RulesTriggerTestCase
Test triggering rules.

Code

public function testEventSettings() {
  $rule = rules_reaction_rule();
  $rule
    ->event('node_presave', array(
    'bundle' => 'article',
  ))
    ->condition('data_is_empty', array(
    'data:select' => 'node:field-tags',
  ))
    ->action('node_publish', array(
    'node:select' => 'node',
  ));
  $rule
    ->integrityCheck()
    ->save();
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'status' => 0,
  ));
  $this
    ->assertEqual($node->status, 0, 'Rule has not been triggered.');
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'status' => 0,
  ));
  $this
    ->assertEqual($node->status, 1, 'Rule has been triggered.');
  RulesLog::logger()
    ->checkLog();

  // Make sure an invalid bundle raises integrity problems.
  $rule
    ->event('node_presave', array(
    'bundle' => 'invalid',
  ));
  try {
    $rule
      ->integrityCheck();
    $this
      ->fail('Integrity check failed.');
  } catch (RulesIntegrityException $e) {
    $this
      ->pass('Integrity check failed: ' . $e);
  }
}