You are here

public function RulesConditionalFrameworkTestCase::testPredicateElement in Conditional Rules 7

Same name and namespace in other branches
  1. 8 tests/rules_conditional.test \RulesConditionalFrameworkTestCase::testPredicateElement()

Tests the base predicate element.

File

tests/rules_conditional.test, line 258
SimpleTest testing suites.

Class

RulesConditionalFrameworkTestCase
Framework tests.

Code

public function testPredicateElement() {
  $predicateElement = new RulesConditionalTestStubPredicateElement();

  // Test integrity check.
  $message = 'Predicate element does not validate without predicate.';
  try {
    $predicateElement
      ->integrityCheck();
    $this
      ->fail($message);
  } catch (RulesIntegrityException $ex) {
    $expectedExceptionMessage = t('The conditional "%plugin" does not have a valid predicate.', array(
      '%plugin' => $predicateElement
        ->plugin(),
    ));
    $this
      ->assertEqual($expectedExceptionMessage, $ex
      ->getMessage(), $message);
  }

  // Test variable assertion using a field in a content type.
  field_create_field(array(
    'field_name' => 'field_test',
    'type' => 'text',
  ));
  field_create_instance(array(
    'field_name' => 'field_test',
    'entity_type' => 'node',
    'bundle' => 'page',
  ));
  $settings = array(
    'type' => 'page',
    'field_test' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'test value',
        ),
      ),
    ),
  );
  $node = $this
    ->drupalCreateNode($settings);
  $predicateElement = new RulesConditionalTestStubPredicateElement('data_is', array(
    'data:select' => 'node:type',
    'op' => '==',
    'value' => 'page',
  ));
  $actionSet = rules_action_set(array(
    'node' => array(
      'type' => 'node',
      'label' => 'Node',
    ),
  ))
    ->action($predicateElement
    ->action('rules_conditional_test_throw', array(
    'message:select' => 'node:field_test',
  )));
  $this
    ->assertExecution('test value', $actionSet
    ->integrityCheck(), array(
    $node,
  ), 'Predicate element correctly adds predicate assertions to state.');
}